Selecting bones

bpy.ops.object.mode_set(mode='EDIT') 
bl = (>>List of bone names<<)
for a in range(len(bl)):
    bpy.data.objects["Armature"].data.bones[bl[a]].select = True

That only seem to select the tails of the bones in that list. How to do this the right way?

oops, thought i posted this in the python forum, oh well…

This works for my armature with bones named A, B and C but it doesn’t look exactly elegant:

bpy.ops.object.mode_set(mode='EDIT') 
bl = ['A', 'B', 'C']

def select_bone(bone):
    bone.select = True
    bone.select_head = True
    bone.select_tail = True

for name in bl:
    bone = bpy.data.objects["Armature"].data.edit_bones[name]
    select_bone(bone)

I kinda question whether I really need to write a helper function to select a bone completely but I found no other way. :man_shrugging:

1 Like

Really weird. You would think that bone.select should be enough, specially when you have seperate commands for selecting head and tail. Looks like a bug to me. Anyways, that’ll work for me, thanks 3dioot

Yeah, your not alone in thinking that. :slight_smile:

I’ve been trying my hand at some scripting for Blender (it would be very useful in my rigging adventures) but I’ve come out of my attempts somewhat frustrated so far. I am well versed in Python, its just the API that feels like its throwing me curve balls with weird gotcha’s and counterintuitive methods or data structures.

Trying to not let it get to me, being frustrated is not a good mindset for learning, but so far I’ve been constantly wasting time instead of winning when I tried to script some simple actions. I’m not at all convinced at this point I should invest more time in learning Blenders Python API. :man_shrugging:

With that said I’m confident it will lure me in again… This would be so much faster to do if you could automate it… Are you sure you don’t want to open the python editor? Come on, how hard can it really be? :sweat_smile:

1 Like

All of your three paragraphs describes exactly what i experienced, hehe. Well except that i’m not that versatile in Python (which makes it even worse).

BUT…

never-give-up-meme

…even if you feel stupid, reaching out for help for simple things like selecting bones.
:flushed:

1 Like

That is a very funny picture. I can certainly relate. :sweat_smile:

You really have no reason to feel stupid. I would attribute a more positive attribute like bravery because learning to script can feel pretty daunting when your first starting out. :man_superhero:

Also, imagine knowing Python and still getting nothing workable (coughs). At least you have somewhat of an “excuse”.

Besides we all have our strengths and weaknesses. Since your comments stood out in regards to rigging I dove into your post history and found a treasure trove of tips and tricks in regards to rigging, most of which are completely new to me.

I also found some old rigging and animation demo reels on your Vimeo channel. Very inspirational stuff to me. So while I may have a bit of a headstart with python you certainly have the edge in actual rigging and animation knowledge.

Long story short; don’t feel ashamed about your supposedly “simple problems”. Coding always makes sense in hindsight and the few lines of working code you end up with seldom feel like they are a good representation of the time you spend to get them actually working. This feeling will always chase you; even as you get better at scripting.

In summary I’m certain it will start to click for you at some point. Navigating Blenders API might turn out to be the hardest part. :wink:

1 Like

Well thank you for your kind words. I’m just glad in knowing, i’m not the only one struggling with the Blender API. To tell you the truth, i’m not much of a rigger neither. Animating with a lot of bad and slow rigs in my job, it was more like making a virtue out of necessity. But i admit, seeing a idea working is kind of fun and rewarding.

And speaking of working ideas, i just finished my script just to find out that the idea didn’t worked.

My goal was to find a way to quickly create and pose BBone chains with a few clicks without worrying about the technical aspect of it. All you have to do is: create the chain by a click of a button then place and adjust the chain to the curved surface of your model (for example the brow area) then hit a another button to convert it to a BBone chain with Bezier Handles. The idea behind it was to snapshot the chain with ‘pose as rest pose’. So instead of going trough the process of adjusting the chain in edit mode, you could do it in pose mode and click another button and be done with it. Unfortunately, ‘pose as rest pose’ doesn’t alter the curveIn and curveOut values in edit mode, which means as soon i add the necessary driver for the bezier handles, the chain straightens out again and the ‘pose as rest pose’ information is gone. I dont know if that makes any sense to you.

So you end up with something like this, which is basically the kind of chain i use in my rigs. i applied a ‘pose to rest pose’ to it and if you change to edit mode, you see the parameters that should describe the curvature, are all ‘zero’ed out’, which is wrong.

BBone Bezier Chain1.blend (724.4 KB)

Oh well, just another venture gone wrong… :weary:

Necessity often makes people very creative! There is a saying that lazy programmers are the best programmers; why do something yourself when you can have the computer do it for you. Also, for better or worse, I found your stuff impressive. Sounds like you were wearing multiple hats. That can be frustrating but also fun!

What you describe is a great idea, in fact its so great that other people have already done it. How is that for validation of your idea? :wink: The below video includes the use of a script that adds control handles automatically -after- aligning the bendy bones to the curvature of the face (be it eyebrows or whatever):

Using scripting for rig generation like this is extremely common. I am certain you are aware of Rigify for example. Its very labor intensive (and prone to error) to recreate complex setups every time from scratch. You are talking about a smaller component here but the main idea is the same. Its exactly for stuff like this I intend to use scripting as well.

The script that is used creates a similar setup to yours but not entirely. I think it will provide a great base to work from.

Remember your adventure has only “gone wrong” if you decide this is where it ends (and you consider it a loss even though you undoubtedly learned a lot of stuff). But perhaps you could try reworking this script to fit your needs. Its how a lot of scripting is done; copy pasting snippets of code and altering existing code. I believe in you :nerd_face:

PS
I believe the link to the script under the YT video still works but in case it doesnt: control_bones_creator_1_1.py (8.9 KB)

Awesome find and thanks for that script link. There is a lot to learn from in terms of structure and error avoiding. I don’t have his fancy ‘if type==’ safety grid to avoid user errors in there (yet).

Not quite. You see, the idea behind it was to avoid that ‘curve adjusting’ in the properties window (like he did in the linked video). Instead i planned to do every adjustment in Pose Mode and then apply it as ‘Rest Pose’. Not possible as i’ve learned and i don’t think they gonna fix that anytime soon or if they even aware of that ‘pose to rest pose’ issue.

But, i learned a lot in the process, so thats good. Plus i can rest in the certainty that i came far enough to be able to produce something similar myself (well, not quite but theoretically :wink: ).

Again, thanks for your kind words and enouragement :slight_smile: