TransWikia.com

Move empty as parent so that children follow (python)

Blender Asked by Jirara on December 31, 2020

I have a scenario where I want to align objects based on a particular set of vertices. I thought the simplest way to do that would be to add empties at those vertex locations, parent the mesh to the empty, and then align them. However, when I did this, the empty moved, but not its child mesh! If I do it manually (parent and move with my mouse) the child follows the empty the way I expected.

Here is the code doing the movement. I’m setting the location, so I’m wondering if that somehow works differently from mesh translate – which I’m assuming but not sure is what is called when I move the mouse .

bpy.data.objects[hotObject.name].select_set(True) #child
bpy.data.objects[hotObjEmpty.name].select_set(True) #parent

bpy.context.view_layer.objects.active = bpy.data.objects[hotObjEmpty.name] #parent active
bpy.ops.object.parent_set()

#then move the empty to the target coords (the object will follow)
bpy.data.objects[hotObjEmpty.name].location = targetCoords

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP