I have a scene with multiple objects and I want to export them individually as .stl meshes.

Right now, it is just a cube and a plane, for simplicity. The cube is resting on the plane.

I've tried the following script to loop through the objects in the scene and export them individually as .stls:

names = [ob.name for ob in bpy.context.selected_objects]

for name in names:
    obj = bpy.data.objects[name]
    bpy.context.scene.objects.active = obj
    stl_path = os.path.join('C://Users/deden/Desktop/', name + '.stl')

However, when I do this, both .stl files contain both the cube and the the plane. I am trying to have a separate .stl file for both the cube and the plane.

Can anybody help me with this?

I've seen a couple other stack posts but keep getting the same problem..


Set the use_selection property

enter image description here

To export only the selection, set the use_selection property to True. Also select object before and deselect after.

context = bpy.context
obs = context.selected_objects  # makes a "snapshot" copy of property
scene = context.scene
for ob in obs:
    scene.objects.active = ob
    ob.select = True
    stl_path = os.path.join('C://Users/deden/Desktop/', name + '.stl')
    ob.select = False
  • $\begingroup$ thank you..this worked for me, much appreciated $\endgroup$ – Derek Eden Feb 5 '19 at 15:51

The STL exporter doesn't have an option like "selected objects only". So, you have to deal with the exporter code to get this done.
Another idea is to hide other objects to a dedicated inactive scene while exporting.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.