1
$\begingroup$

I'm fairly new to blender scripting and I'm having some trouble figuring out the context in which every command must be to work. My code looks like this:

bpy.ops.object.origin_set(type='ORIGIN_GEOMETRY', center='MEDIAN')
bpy.context.area.type = 'VIEW_3D'
bpy.ops.view3d.snap_selected_to_cursor(use_offset=False)
bpy.ops.object.editmode_toggle()
bpy.ops.transform.translate(value=(0, 20.6551, 0), orient_type='GLOBAL', orient_matrix=((1, 0, 0), (0, 1, 0), (0, 0, 1)), orient_matrix_type='GLOBAL', constraint_axis=(False, True, False), mirror=True, use_proportional_edit=False, proportional_edit_falloff='SMOOTH', proportional_size=1, use_proportional_connected=False, use_proportional_projected=False)

I've figured out view3d for the snap, but as soon as I want to move it in edit mode it closes blender

I assume I need to set the context for every line but I have no idea where to start looking for what command needs what context.

$\endgroup$
1
  • $\begingroup$ IMO, for what you are attempting to do above, would go straight to linear algebra and using matrices. eg blender.stackexchange.com/a/186009/15543 shows a low level way to set origin to geometry (instead of op above) after which (for rest above) set object matrix world to cursor matrix, then transform the mesh again. This removes any need for switching mode or being in a certain space. $\endgroup$ – batFINGER Jan 5 at 12:22

Your Answer

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

Browse other questions tagged or ask your own question.