1
$\begingroup$

I have an Armature ("Armature1") with a few bones in it ("Bone","Bone.001","Bone.002", "Bone.003"). I'm in pose mode and I have selected two bones. ("Bone.001", "Bone.002")

How do I create a variable that contains the two currently selected bones? (using python) So that I can reselect those bones again later in my script?

Hope this makes sense.

$\endgroup$

1 Answer 1

0
$\begingroup$

Store the names of the bones somewhere:

"""
    Save
"""
import bpy
from bpy import context as C

bone_names = [b.name for b in C.selected_pose_bones]
bpy.types.Armature.saved_pose_selection = bone_names

And then you can load the data from there:

"""
    Load
"""
import bpy
from bpy import context as C

for previously_selected in C.selected_pose_bones[:]:
    previously_selected.bone.select = False

for name in bpy.types.Armature.saved_pose_selection:
    C.object.pose.bones[name].bone.select = True
$\endgroup$
1
  • $\begingroup$ Apologies for the very late reply. I was out of office and away from my computer last week. @Markus- Thanks so much for this reply! $\endgroup$
    – MattL
    Sep 26, 2022 at 11:58

You must log in to answer this question.

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