2
$\begingroup$

I'm trying to get a length of a single bone but having no luck to do it when it's last bone in chain. Need that value for custom property (which I need for drivers).

enter image description here

So far, I've figured out how to find a length of any bone that has parent and child by using Driver Variable Type: Distance and select that bone and it's child.

enter image description here

My question is how to find a length between 'last' bone's head and tail?

I'm sure there must be something easy and obvious way but for last couple of hours had no luck to find solution.

$\endgroup$
4
  • $\begingroup$ why don't you just add another bone to your last bone and that you got your length with the same method? ;) $\endgroup$
    – Chris
    May 15, 2022 at 8:35
  • $\begingroup$ @Chris I'm actually using that approach at the moment but need to know how to find length of any bone with no tricks ;) I'm sure there's some property we can read to get that info or at least calculate it somehow. $\endgroup$
    – Wh1T3h4Ck5
    May 15, 2022 at 8:53
  • $\begingroup$ you can do it via python... ;) $\endgroup$
    – Chris
    May 15, 2022 at 8:54
  • $\begingroup$ Is there a way to connect python script with drivers? Haven't done anything like that before but if there's a way, it's worth of getting into it. $\endgroup$
    – Wh1T3h4Ck5
    May 15, 2022 at 8:55

1 Answer 1

1
$\begingroup$

Yes, you can connect python script to drivers like this:

enter image description here

Choose type "scripted expression".

In text editor load "templates" - python - driver functions, so you can see how to make functions accessible in drivers.

Then you can use any function you wrote in the driver.

You can use simple python commands in drivers directly as well (check documentation for that).

So if you create function like this:

def bonelength(bone):
    return bone.length

and use that in your driver, it should work.

So to try out fast you could use e.g. this code:

def bonelength():
    return bpy.data.objects["Armature"].pose.bones["Bone.003"].length

Of course you have to replace "Armature" with the name of your armature, and "Bone.003" with the name of your bone.

$\endgroup$
2
  • $\begingroup$ Actually this worked well. Thanx. $\endgroup$
    – Wh1T3h4Ck5
    May 15, 2022 at 15:10
  • $\begingroup$ you are welcome! $\endgroup$
    – Chris
    May 15, 2022 at 15:10

You must log in to answer this question.

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