python - Blender, convert .stl to .obj with prompt commande -
i want convert .stl file .obj, without using blender interface.
to that, want in 2 step :
1 stl blend
2 blend obj
actually blend obj work ok python code :
import bpy import sys argv = sys.argv argv = argv[argv.index("--") + 1:] # args after "--" obj_out = argv[0] bpy.ops.export_scene.obj(filepath=obj_out, axis_forward='-z', axis_up='y')
and batch :
@echo off rem put path of blender folder set path=c:\program files\blender foundation\blender set filename=guitar.blend set target=guitar.obj rem launch blender %filename% --background --python convert_blend_to_obj.py -- %target% pause
this work perfectly.
the problem stl blend, not working python code :
import bpy import sys argv = sys.argv argv = argv[argv.index("--") + 1:] # args after "--" blend_out = argv[0] bpy.ops.import_mesh.stl(filepath=blend_out, axis_forward='-z', axis_up='y')
and batch associated :
@echo off rem put path of blender folder set path=c:\program files\blender foundation\blender set filename=turbine.stl set target=turbine.blend rem launch blender %filename% --background --python convert_stl_to_blend.py -- %target% pause
i got error : file format not supported in file c:..\turbine.stl blender quit
i think problem in python code, don't know change.
i found first script here : https://wiki.blender.org/index.php/extensions:2.6/py/scripts/import-export/wavefront_obj
i thank in advance help, maybe there better way that. don't want have launch blender , manually. need prompt commande.
i got error : file format not supported in file c:..\turbine.stl blender quit
the error getting means blender trying read first command argument .blend file. put script's arguments after "--" (as says in script's comment), , should work.
made changes script import stl , export obj in 1 step, test if works:
import bpy import sys argv = sys.argv argv = argv[argv.index("--") + 1:] # args after "--" 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')
and launched follows:
blender --background --python convert_stl_to_blend.py -- test.stl test.obj
Comments
Post a Comment