FreeCAD Tips 1 : Clear your workspace
/FreeCAD is a fantastic CAD program which provides access to all the drawing elements from Python. I use it a lot (I might be the only one). Perhaps I should write something all about it. For now though, here’s a tiny bit of code that’s very useful.
# Delete all existing objects in the document
for obj in doc.Objects:
doc.removeObject(obj.Name)
This allows you replace existing code generated objects with new ones so your workspace doesn’t fill up with stuff. This is useful if you are making objects with software:
frame = Part.makeBox(width, height, depth)
The statement above makes a frame as a 3D object with a particular size. This is a 3D object, but at the moment it isn’t part of a design document. So, let’s make a document:
doc = App.ActiveDocument or App.newDocument("Frame")
This statement makes a new document called doc. Better yet, it only makes a new document if we don’t already have one. Now we can add our frame to the document:
frame_obj = doc.addObject("Part::Feature", "Frame")
frame_obj.Shape = frame
The first statement above adds a feature to the document. the second sets the shape on this feature to the frame that we created. Great stuff. But if you re-run the program you get another feature. Which you don’t want. That’s why the statements at the top are so useful. They work through the document and clear away everything so that you can add new versions.