STL batch export (each object as separate file)

Scripting in Blender with Python, and working on the API

Moderators: jesterKing, stiv

CoDEmanX
Posts: 894
Joined: Sun Apr 05, 2009 7:42 pm
Location: Germany

STL batch export (each object as separate file)

Postby CoDEmanX » Tue Jul 03, 2012 2:16 pm

i dunno where the original post has gone, where someone asked about batch stl export. He was having problems with the call

bpy.ops.export_mesh.stl(str)

----------------------


filepath is not a positional argument

you need to pass it like
bpy.ops.export_mesh.stl(filepath=str)

and if you want to export all selected object, each into a separate file, you gotta use different code...

e.g.

Code: Select all

import bpy

# Keep a copy of user selection
sel_obs = bpy.context.selected_objects[:]

for ob in sel_obs:
   
    # Skip non-mesh objects
    if ob.type != 'MESH':
        continue

    # Clear selection   
    bpy.ops.object.select_all(action="DESELECT")
   
    # Select single object
    ob.select = True
   
    # Export single object to STL
    bpy.ops.export_mesh.stl(filepath="D:\\temp\\batch_" + ob.name + ".stl")
   
# Restore user selection
for ob in sel_obs:
    ob.select = True
bpy.context.scene.objects.active = ob
I'm sitting, waiting, wishing, building Blender in superstition...

Return to “Python”

Who is online

Users browsing this forum: Yahoo [Bot] and 0 guests