0
$\begingroup$

So, I am writing a set of scripts to help me out with manual rigging in Blender. But I came across a problem when trying to assign constraints to 2 different groups of bones that I store in separate lists.

I store my deform and target bones in two separate lists using these lines of code:

def get_selected_pose_bones(self):
    """Get selected pose bones and store them in the list"""
    selection = bpy.context.selected_pose_bones
    self.pose_bones = []
    for bone in selection:
        self.pose_bones.append(bone)
    return self.pose_bones

#in rest of my functions I use:

def_bones = self.get_selected_pose_bones()
tgt_bones = self.get_selected_pose_bones()

and do all the necessary operations with those. But when it comes to assigning copy_transforms constraints I get stuck.

Basically, in pose mode I need to make the first bone in the list active and while it being active assign a copy_transform constraint, then I will need to assign a first bone from the second list as a target of the first bone's copy transform constraint. I have zero clue how to do that.

If someone dealt with something like this I would appreciate your help.

$\endgroup$

1 Answer 1

0
$\begingroup$

So, I have solved the problem I was facing.

To do that you will have to use the several operators in conjunction with some of your own logic. I used operators for selecting the object and then making it active. The use of following operators helped:

For selection and making objects active: bpy.ops.object.select_pattern()

if you use it in a for loop with bone's name list you can select every bone one by one.

Then to make a bone active you would use something like:

bpy.context.object.data.bones.active = bone_to_make_active
bone_to_make_active.select = True. 

The solution how to make bones active is available here on stackexchange, search for "how to make selected bone active".

Then you would use operators like:

bpy.ops.pose.constaint_add()

and then you would need to access constraints and edit it through context module:

bpy.context.object.pose.bones[bone.name].constraints["Copy Transforms"].target = bpy.data.objects['Armature']

And then you would need to access the subtarget value through context module again:

bpy.context.object.pose.bones[bone.name].constraints["Copy Transforms"].subtarget = bone_to_constraint[0].name

I know, it's not a copy and run kind of solution, but unfortunately I have my code split into separate classes and methods, it will be really time consuming to write one long method.

$\endgroup$

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.