I am creating a script to help me speed up my rigging workflow. I am trying to create an automatic size adjustment for helpers that I am assigning to bones. That way longer bones will have larger helpers and smaller bones smaler helpers.
I decided to do this by calculating length of the bone as you can see below.
xyz1 = point3 $.pos.x $.pos.y $.pos.z --takes position from first bone
actionMan.executeAction 0 "40194" --moves to the next bone in chain
xyz2 = point3 $.pos.x $.pos.y $.pos.z --takes position from second bone
intensity = distance xyz2 xyz1 --calculate vector length
actionMan.executeAction 0 "40193" --moves to the previous bone in chain
loc = point()
loc.size = intensity*0.5 --defines the size of the helper
loc.position = $.position
Is there any easier way to do this? Because I have to use this in a "for" loop, when I select multiple bones, using actionMan to select other elements is not possible since it creates problems with selection.
Apart from the length
property of the bones (is there any reason not to use that?), you can get the first child which is a bone and get its distance. That is, if you have the top parent bone of the chain selected:
for b in #()+$ where isKindOf b BoneObj collect b.length
This will include also the last bone. Or by testing the parent-child distance:
for b in #()+$ where isKindOf b BoneObj and b.children.count > 0 collect distance b b.children[1]