Skip to content

Instantly share code, notes, and snippets.

@DAMO238
Created July 13, 2020 15:17
Show Gist options
  • Save DAMO238/4f0910f4f86d8a0fb814859b5336b327 to your computer and use it in GitHub Desktop.
Save DAMO238/4f0910f4f86d8a0fb814859b5336b327 to your computer and use it in GitHub Desktop.
Blender python file to convert an stl file into an obj file.
#!/bin/python
import bpy
import sys
argv = sys.argv
argv = argv[argv.index("--") + 1:] # get all args after "--"
candidate_list = [item.name for item in bpy.data.objects if item.type == "MESH"]
# select them only.
for object_name in candidate_list:
bpy.data.objects[object_name].select()
# remove all selected.
bpy.ops.object.delete()
stl_in = argv[0]
obj_out = argv[1]
bpy.ops.import_mesh.stl(filepath=stl_in, axis_forward='-Z', axis_up='Y')
bpy.ops.export_scene.obj(filepath=obj_out, axis_forward='-Z', axis_up='Y')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment