pythonfreecad

Python: How do I programmatically clear the viewer in FreeCAD?


I can use a Python script to create and show a part in FreeCAD like this:

Part.show(myPart)

But if I run the script again, it overlays a second copy of myPart on top of the original. How can the Python script clear the viewer before it starts drawing? I can manually use the FreeCAD menu to "Select All" and then "Delete", but how can I automate that to speed up my workflow?


Solution

  • This is the solution I came up with:

    def clearAll():
        doc = FreeCAD.ActiveDocument
        for obj in doc.Objects:
            doc.removeObject(obj.Label)