I'm quite new to Python so the answer to my question might be simple or impossible.
In below shown example I would like to substitute the object name "myBox" with a variable boxName.
boxName = "myBox"
FreeCAD.ActiveDocument.addObject("Part::Box", boxName)*
This works:
FreeCAD.ActiveDocument.myBox.Length = 150
This doesn't:
FreeCAD.ActiveDocument. + boxName + .Length = 150
I get a syntax error:
'App.Document' object has no attribute 'boxName' or when I try other variations I get this error:
(1)<class 'SyntaxError'>: ('invalid syntax', ('###/AppData/Roaming/FreeCAD/Macro/nyMacro.FCMacro', 5, 24, 'FreeCAD.ActiveDocument.+(boxName)+.Length = 150\n'))
If it's possible to substitute with a variable, I will be gratefull if someone will show me the syntax.
You have to use meta programming. Do a little study about this concept. It's interesting. In Python you can execute dynamic code by eval function:
eval('FreeCAD.ActiveDocument. + boxName + .Length = 150')
Do seaech about eval and exec function if I'm not wrong.
Python FreeCad ActiveDocument with variable