Finding a Bone's Length (pardon the expression!) to use in a Driver

Simple question:

I, and another user here, want to use a bone’s length in a Driver Scripted Expression. I have looked at various options and found out that there is a function called BonesDict in Python, which has a length option. I can use things like “pose.bones[“Bone.001”].location[0]” to return the X location of the bone, which is 0 unless you move the bone in Pose Mode, so is NFU to me! So the question is:

“How do I get to the length of a bone, through BonesDict or any other method, to use it in a Driver?”

Over to the experts! :smiley:

Thanks, Clock.

Hey clockmender…

Try typing this into blender’s python console:

bpy.data.armatures['Armature'].edit_bones['Bone'].length

and you should get the length of the bone. Of course, the words enclosed in [ ] must be changed to reflect the name of the armature and the bone you want the length of.

Best wishes,
Randy

1 Like

Hmmmm - bpy.data.armatures[‘Armature’].edit_bones[‘Bone’].length - did not work…

but, bpy.data.armatures[‘Armature’].bones[‘Bone’].length - did! This gives me the bone length that I can poke into a custom variable.

However, any combination of these expressions in the Driver Variable did not - D’Oh! I tried setting the Driver Prop to Armature type - then select the armature, then tried all sorts of expressions like bones[‘Bone’].length, edit_bones[‘Bone’].length, pose.bones[‘Bone’].length - nothing stopped the box being red in colour grrrrrrr.

Oh well I shall just have to use the console window to get the bone length.

Thanks Randy - best wishes, Clock.

Ps did you get my PM ref CAD question?

Sorry that didn’t work, here’s the deal on that…

It worked for me in blender 2.73, it doesn’t work for me in blender 2.74. So there has been a change in the python api between 2.73 and 2.74. This I find to be odd because that part of the api has been stable for some time and isn’t really subject to change, but it has changed. I dunno why.

The python api was constantly changing as the 2.5x series were released. Understandable at that time, as blender was in a re-write stage. It was rough for scripters, as the api changed so much from version to version. During the 2.6x versions, the python api didn’t change as much, it was pretty stable, but small changes here and there. And by this time, I would think python api dealing with armatures wouldn’t be changing so much, in the current version. You know what they say when you ‘assume’ something…

As to what you are doing with this, I just noticed the other thread, just find the length and hard code it in. I’ll comment there too.

Yes on the CAD, just haven’t had time to pm back, been away for a day…

Randy

edit: Just commented in the other thread, got to thinking, normally in the application of this, the bone doesn’t scale. It only rotates from the tip or the root, depending upon what way it rotates, so you hard code in the value. But if you wanted to scale the bone as well, that could be done with python as well. But it’s really not needed here, so I’ll skip that…

Thanks a lot, and it works until this day :slight_smile: