I'm stuck at the part of my loop where the empty gets constrained to the bone. I don't know how to refer to the bones and empties I want to constrain since their names vary as the loop runs. Here's what I have so far:
##Loop that runs on every bone in rig for bone in metarig: ## print each bones name print (bone.name) ##create Cubeshaped Empty of radius 0.6 at origin makeEmpty = bpy.ops.object.empty_add(type='CUBE', location=(0, 0, 0), radius=(0.1)) ##rename newly created empty bpy.context.selected_objects.name = ("empty_A_" + (bone.name))
Up to here above code works, when I end the loop here I get all my empties named correctly.
The Next command errors out: I'm trying to define the Constraint owner and targets without using explicit names, since this is a loop? What's the correct way? I also tried calling it by its name (
"empty_A_" + (bone.name)) that doesn't work.
## Create reference for current empty emptyobj = bpy.context.selected_objects ## also tried referring to it by its name, the following also errors out emptyobj = bpy.context.("empty_A_" + (bone.name)) ## then I want to do this, not sure if this will work since I'm stuck at the above line, targetbone = bone myConstraint = emptyobj.constraints.new(type='CHILD_OF') myConstraint.target = targetbone
Any guidance would be greatly appreciated, been stuck on this for a while now :(.