FreeCAD adventure

Computer Aided Engineering, never thought I would be dealing with it. Yet, here I am messing with stuffs for the first time. At work FreeCAD is what we use to make 3D models. Technically speaking I do not directly work on FreeCAD but rather come in help if things go wrong or new stuffs are needed. Luckily, FreeCAD understands Python, and that chemistry makes it easier for me to provide additional stuffs not-yet-bundled in the core application.

Like today, my fellow colleague needed a way to generate the list of parts that were assembled to form a final object. See the example below, the object is made up of a series of separately designed parts which are then assembled to make up the final object.


More complex designs can involve dozens or even hundreds of smaller parts assembled together. Usually an engineer will later need the part names while building up a report. At the moment there is no option in FreeCAD that allows to export a list of parts. With some handy Python however, this could be made possible. See code below:

import os,pwd
user = pwd.getpwuid(os.getuid())[0]
save_path = "/home/"+user+"/freecad_parts_list.txt"
for obj in App.ActiveDocument.Objects:
    name = obj.Label + "\n"
    f = open(save_path, 'a')

Just shoot the Python console within FreeCAD and run the above code. It generates the file freecadpartslist.txt in your home directory listing all the parts that are assembled together. As of now, it's something pure text, basic stuff. Some more digging into the FreeCAD documentation and we shall find a way to make the output much more useful.

The FreeCAD file example used here is available from:

Share this post