1
$\begingroup$

I tried to create a script that allows for a selection of meshes, to make the selected vertex the origin of the mesh.

import bpy

bpy.ops.object.editmode_toggle()
bpy.ops.view3d.snap_cursor_to_selected()

bpy.ops.object.editmode_toggle()
bpy.ops.object.origin_set(type='ORIGIN_CURSOR', center='MEDIAN')

this is what I did, but it's for a single instance and it doesn't work.

To better understand what I am trying to do, here is a visual representation.

meshes with the origin of the splited mesh

selected vertex of the meshes

origin to the selected vertex

I have a mesh that I split into several meshes and these meshes have the same origin as the original mesh. I want to make the vertex I select for each mesh the new origin of the mesh.

What I can do manually is:

  • Select a mesh
  • Switch to edit mode
  • Cursor to selected
  • Switch back to object mode
  • Origin to 3D cursor

but it can be very long if I have a lot of meshes. So I would like to create a script to do this, unfortunately I don't know enough about programming on blender.

$\endgroup$

1 Answer 1

2
$\begingroup$

you should apply the new origin to each of the selected objects. Get a list of the selected objects and apply the origin with a for loop.

This is a sample code:

C = bpy.context
O = bpy.ops

# get list of selected objects
objs = C.selected_objects

for obj in objs:
    # make current object as active
    C.view_layer.objects.active = obj
    # apply origin
    O.object.origin_set(type='ORIGIN_CURSOR', center='MEDIAN')
$\endgroup$
1
  • $\begingroup$ The loop works but the cursor doesn't snap to the selected vertex location. Thanks a lot for the help $\endgroup$ Dec 2, 2021 at 15:50

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .