0
$\begingroup$

in order to speed up the process of configuring a ragdoll humanoid with Blender, i use an addon that creates empties on the head of each bone aligned to the bone (Bonera), and other that creates meshes on the same location but with already configured rigid bodies and rigid body constraints (Rigid Body Gen). Then i manually copy the transforms from the empties to the meshes so they line up one by one. How could i do this for all selected meshes at once with a script? Like for the selected meshes, copy loc and rot from the empties using their name as reference (copy loc/rot from bone_[name] to joint_[name])

$\endgroup$

1 Answer 1

0
$\begingroup$

From the information you've given, only this simple script can be derived. Hope it helps. If it's not working, please provide more precise information about your scene setup.

import bpy

# get all selected objects
for selected_obj in bpy.context.selected_objects:
    
    # only consume meshes
    if selected_obj.type == 'MESH':    
    
        # get bone and joint object with mesh name
        bone_obj = bpy.data.objects['bone_' + selected_obj.name]
        joint_obj = bpy.data.objects['joint_' + selected_obj.name]

        # copy loc and rot
        joint_obj.location = bone_obj.location
        joint_obj.rotation_euler = bone_obj.rotation_euler
$\endgroup$
4
  • 1
    $\begingroup$ Thanks @taiyo, it was almost there, i just had to remove the "joint_" string from the obj name before assigning the bone, the way you did it become "bone_joint_name", the end script is even simpler, your answer helped me to figure it out: bone_obj = bpy.data.objects['bone_' + obj.name.replace("joint_", '')] $\endgroup$
    – Jh0nny
    Aug 8, 2023 at 3:10
  • $\begingroup$ I just noticed that if the empties are parented to something, the copy loc and rot does not work properly, is there any code for copying the transform data if the "bone_" object is a children of another obj? $\endgroup$
    – Jh0nny
    Aug 8, 2023 at 11:10
  • $\begingroup$ @Jh0nny loc and rot are local values (relative to the parent), if you have a hierarchy its gets more complicated. You can get the global values with decomposing the obj.matrix_world attribute, see this answer blender.stackexchange.com/questions/209398/…. $\endgroup$
    – taiyo
    Aug 8, 2023 at 11:39
  • $\begingroup$ Thanks, it works now! $\endgroup$
    – Jh0nny
    Aug 8, 2023 at 16:24

You must log in to answer this question.

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