def execute(self, context):
stl_path = bpy.path.abspath(bpy.context.scene.stl_path)
bpy.ops.import_mesh.stl(filepath=stl_path)
try:
ob_new = bpy.context.selected_objects[0]
for f in ob_new.data.polygons:
f.use_smooth = True
for b in ob_new.data.polygons:
bpy.context.space_data.show_textured_solid = True
bpy.context.object.show_transparent = True
bpy.context.scene.render.engine = 'CYCLES'
bpy.ops.object.editmode_toggle()
bpy.ops.mesh.select_all(action='TOGGLE')
bpy.ops.mesh.select_mode(use_extend=False, use_expand=False, type='FACE')
bpy.ops.mesh.select_all(action='TOGGLE')
bpy.ops.mesh.tris_convert_to_quads()
bpy.ops.view3d.snap_cursor_to_selected()
bpy.ops.object.origin_set(type = 'ORIGIN_CURSOR')
Everything is working well, until I use origin_set
. Maybe I should go to object mode, after converting mesh to quads.
But when I'm adding bpy.ops.object.editmode_toggle()
after tris_convert_to_quads
Blender is freezing. Without this last command, everything is working, also snapping cursor to selected.
Ok, I changed script.
def execute(self, context):
stl_path = bpy.path.abspath(bpy.context.scene.stl_path)
bpy.ops.import_mesh.stl(filepath=stl_path)
try:
ob_new = bpy.context.selected_objects[0]
for f in ob_new.data.polygons:
f.use_smooth = True
bpy.context.object.show_transparent = True
bpy.context.scene.render.engine = 'CYCLES'
bpy.ops.object.editmode_toggle()
bpy.ops.mesh.select_all(action='TOGGLE')
bpy.ops.mesh.select_mode(use_extend=False, use_expand=False, type='FACE')
bpy.ops.mesh.select_all(action='TOGGLE')
bpy.ops.mesh.tris_convert_to_quads()
bpy.ops.mesh.faces_shade_smooth()
bpy.ops.object.mode_set(mode='EDIT')
bpy.ops.mesh.select_all(action='TOGGLE')
to this line everything is ok, and script is ends in object mode. but If I add this line bpy.ops.object.origin_set(type='ORIGIN_CENTER_OF_MASS')
I have msg in console, that I must be in object mode. If i add this command bpy.ops.object.mode_set(mode='OBJECT') Blender is switching off.