Python FreeCad ActiveDocument with variable

  python, syntax, syntax-error

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 = 150n’))

If it’s possible to substitute with a variable, I will be gratefull if someone will show me the syntax.

Source: Python Questions