3
$\begingroup$

I've already figured out the code for finding bones by their name. I just need to know if there's more than one bone that meets this criteria (for example the words: "hand", "ik", and "l").

ar = bpy.data.objects["Armature"]

for bone in ar.data.bones:
    if all(words in bone.name for words in ("hand", "ik", "l")):
        Bone.name = "NewName"
$\endgroup$

2 Answers 2

4
$\begingroup$
for bone in bpy.data.objects["Armature"].data.bones:
    bn = bone.name
    if "hand" in bn:
        #do something
    elif "|" in bn:
        # do something else
    if "ik" in bn and "foot" in bn:
        # it's a foot ik

The 1. if always triggers as long as "hand" is in the name The 2. if only triggers when "hand" is not, but "|" is The 3. is true only when ik and foot are in the name. There might be a one-liner for this, but this approach should be more flexible and readable Please note, these are case-sensitive, if you want to ik to be treated the same way as IK, use:

bn = bone.name.lower()
$\endgroup$
2
$\begingroup$
import bpy
ar = bpy.data.objects["Armature"]  # consider bpy.data.armatures

words = ("hand", "ik", "l")
check = lambda b: all(word in b.name for word in words)
# check = lambda b: all(word in b.name.lower() for word in words)
found = [b for b in ar.data.bones if check(b)]
print(f"Found {len(found)} bones with {words=}\n{found}")
$\endgroup$

You must log in to answer this question.

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