Let us examine the example a bit closer.
# Import Lexocad libraries import OpenLxApp as lx
The import statement loads existing Python code from another file – a module. The Python binding to Lexocad is defined by modules. By importing a module you gain access to Lexocad’s functions through the API (Application Programming Interface).
# Get the active document doc = lx.Application.getInstance().getActiveDocument()
To actually display something in the 3D scene we need to store the “active document” in a variable: everything that we create later will be assigned to the document.
# Create a geometry in the document block = lx.Block.createIn(doc) block.setXLength(3) block.setYLength(4) block.setZLength(5)
3D elements have an underlying geometry. Here we create geometry of type “Block” and we assign it to the above document.
# Create an element in the document and assign the geometry to it elem = lx.Element.createIn(doc) elem.setGeometry(block)
Here we create the 3D element and we assign it to the above document. The above geometry is then assigned to the element itself.
# Recompute the document doc.recompute()
Once we are done adding a new element, we have to tell Lexocad to rebuild the 3D scene: the method “recompute()” applied to the document will do that.