CadQuery / cadquery

A python parametric CAD scripting framework based on OCCT
https://cadquery.readthedocs.io
Other
3.14k stars 289 forks source link

Export a separate STL for each object in a STEP file #1136

Open 0xCoto opened 2 years ago

0xCoto commented 2 years ago

I'm new to CadQuery, trying to transition from FreeCAD to carry out some modelling automation/operations.

I've managed to load a STEP file, and export it as an STL:

result = cq.importers.importStep("data/" + step_file)
cq.exporters.export(result, "data/" + stl)

What I couldn't quite find on the documentation is whether it is also possible to export an STL for each shape/object individually? E.g. if the STEP consists of 3 cubes, I should get 3 separate STLs.

0xCoto commented 2 years ago

Figured it out:

shapes = model.objects[0]
for i, shape in enumerate(shapes):
    shape.exportStl("obj_"+str(i)+".stl")

Follow-up question: is it possible to maintain the name of each shape (like it's maintained when you open a STEP file with FreeCAD and see the name of each object)?