0
$\begingroup$

I am using a lattice to displace an object and I would like the new location of the object after the lattice deform happens. I am trying to do this through the Blender API. ob is my sphere. ob.location is still giving me 0,0,0 and when I look at the 3D Viewport it also shows 0,0,0.

enter image description here enter image description here

$\endgroup$
2
  • $\begingroup$ Closed and re-opened, See. blender.stackexchange.com/questions/146559/… As can be seen in image above the origin is not moved, the mesh is modified wrt to the original origin. Link shows how to get the modified mesh & hence coordinates. The "new" origin can be calculated from these. For case of sphere above could look at half way between pole verts, But (big but) will depend on lattice deform (and other modifiers) ... Would consider using a constraint approach. Constrain an empty to copy location $\endgroup$
    – batFINGER
    Jun 8 '21 at 11:10
  • $\begingroup$ of vertex group. blender.stackexchange.com/questions/139640/… $\endgroup$
    – batFINGER
    Jun 8 '21 at 11:11
0
$\begingroup$

I had to select each object, apply the modifier to my object, reset my origin to the center of mass, finally deselect the object. Repeat for all objects with the modifier.

bpy.ops.object.select_all(action = 'DESELECT')

for ob in collection.objects:
    if ob.type == "MESH":
        for modifier in ob.modifiers:
            ob.select_set(True)
            bpy.context.view_layer.objects.active = ob
            bpy.ops.object.modifier_apply(modifier = modifier.name)
            bpy.ops.object.origin_set(type = 'ORIGIN_CENTER_OF_MASS')
            bpy.ops.object.select_all(action = 'DESELECT')
$\endgroup$

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.