This script shows how to remove an Element from the document. This can be done by calling the document’s ‘removeObject()’ method. Please be aware that the Element still exists in memory, it just does not belong to the document anymore. You can reassign it by calling the ‘addObject()’ method. This can be useful for undo/redo operations.

import OpenLxApp as lx
import OpenLxUI as ui

app = lx.Application.getInstance()
doc = app.getActiveDocument()

#--------------------------------------
# First create the element.
#--------------------------------------
block = lx.Block.createIn(doc)
elem = lx.Element.createIn(doc)
elem.setGeometry(block)
doc.recompute()

# Do whatever you want with the element

#--------------------------- 
# Delete the element.
#---------------------------
doc.removeObject(elem)
doc.recompute()

Leave a Reply

Your email address will not be published. Required fields are marked *