3
$\begingroup$

I have a biped armature. And I want Blender to ignore the Right and Left bones. I want to select the bones that their names don't end with either R or L (want to select in Edit mode).

$\endgroup$

4 Answers 4

3
$\begingroup$

The simplest way to do this is to select by pattern and use the pattern *[!LR]. Putting the exclamation point ! as the first character of a character selection list says to invert that list, that is select any character except those in the list, so this pattern will select any bone name that does not end in L or R.

You may want to enable case sensitive if you have center bones that end in lower case l or r.

No scripts or extra steps are required.

Select menu with select pattern highlighted

Selection dialog showing the pattern needed

Since you included the scripting tag

import bpy

bpy.ops.object.select_pattern(pattern='*[!LR]')
$\endgroup$
1
  • $\begingroup$ Genius! thanks a ton! $\endgroup$
    – Zack
    Sep 26, 2021 at 23:20
3
$\begingroup$

Blender doesn't treat bone suffixes as case sensitive, so I used a regex to match both cases. The thing you might have missed if you tried yourself is that there are 3 different bone definitions, there are bones, edit bones, and pose bones. You edit edit bones, pose pose bones and leave bones pretty much alone.

import bpy
import re # regular expression library

arm = bpy.context.active_object

if arm == None or arm.type != 'ARMATURE':
    raise ValueError('You must select an armature')

# Set edit mode    
if bpy.context.mode != 'EDIT':
    bpy.ops.object.mode_set(mode='EDIT')
    
for ebone in arm.data.edit_bones:
    # a regular expression that matches names ending in a period followed by l,L,r,R
    if re.match('.+\.[RrLl]$', ebone.name):
        ebone.select = False 
        print('{} selected'.format(ebone.name))
        
    else:
        ebone.select = True
        print('{} not selected'.format(ebone.name))
        
$\endgroup$
3
$\begingroup$

I see that you've added scripting tag, but this task is not too complicated to use Python!

Press menu SelectSelect Pattern...

In the window input * [LR]* if you have L and R separated by space and *.[LR]* if it separated by dot. Also if L and R is at the end of the name you can use *.[LR]

Then press Enter in the field to activate selection. (The is no Apply (Select) button, so this can be a little tricky)

enter image description here

Then you have all L and R bones selected, simply invert selection by pressing Ctrl + I

$\endgroup$
3
  • $\begingroup$ If you put ! between [ and L you don't have to invert. $\endgroup$ Sep 21, 2021 at 14:13
  • $\begingroup$ @MartyFouts it looks like you give good hint, but this will not work, because it still searches for separator (. or _ or space) $\endgroup$
    – Crantisz
    Sep 21, 2021 at 14:26
  • $\begingroup$ You need to remove the last * for my comment to work. You're searching for L or R anywhere in the string. $\endgroup$ Sep 21, 2021 at 14:38
2
$\begingroup$

Select centre bones.

To do this in any mode, can for all but edit mode set the select attribute of an Armature.bone

Select Pose Bones Per Script In Blender 2.8

For edit bones, can either toggle out of edit, do as above and back into edit mode, or set the select on an edit bone.

Either way selections are reflected in all modes.

Edit left and right to suit, for example if your bones end with "_Left"

left, right = "_Left", "_Right"

".L" and ".R" have been used here as default. `

import bpy

context = bpy.context

left, right = ".L", ".R"

ob = context.object
arm = ob.data

assert ob.type == 'ARMATURE', "Select an Armature"
col = "edit_bones" if context.mode == 'EDIT_ARMATURE' else "bones"
for b in getattr(arm, col):
    b.select = not (
        b.name.endswith(f"{left}") 
        or b.name.endswith(f"{right}")
        )

Note: can make this case insensitive, by converting both name and suffix to lower case, with

b.name.lower().endswith(f"{left}".lower())
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.