I'm not really sure why you're doing it the way you're doing it...
This is how I solved it quickly (There's better ways but I'm lazy and I 
didn't want to keep working on it.)  Just a simple recursive function.

def dist( objA, objB ):

   Ax, Ay, Az = objA.getTranslation(space="world")

   Bx, By, Bz = objB.getTranslation(space="world")

   return (  (Ax-Bx)**2 + (Ay-By)**2 + (Az-Bz)**2  )**0.5

def lenJointChain(obj,len=0):

       if obj.getChildren()==[]:

              return len

       else:

               child=obj.getChildren(type='transform')[0]

               return lenJointChain(child, len=len+dist(obj,child))

lenJointChain(pm.ls(sl=True)[0])



On Wednesday, May 28, 2014 3:18:13 PM UTC-4, flaye wrote:
>
>
>
> # Find the full length of the chain
> sel=[]
> sel=mc.ls(sl=True)
> length = 0
> for i in range(1, len(sel)):
>     length += abs(mc.getAttr(sel[i]+'.tx'))
>
> print length
>
>
> The above code will provide the correct answer, on the condition that the 
> primary axis of the joints (in this case, X) is known.
>
> I've also tried using the MVector function, but unfortunately the numbers 
> are off
>
> import maya.api.OpenMaya as om #for api 2.0
> sel=[]
> sel=mc.ls(sl=True)
>
> startjnt=sel[0]
> numjnts=len(sel)
> length=0
> for i in range(0,numjnts-1):
>         
>         currentjnt=sel[i]
>         
>         nextjnt=mc.listRelatives(currentjnt,children=1)[0]
>     
>         print currentjnt,nextjnt
>
>         t1=mc.xform(currentjnt,q=1,t=1) 
>         t2=mc.xform(nextjnt,q=1,t=1)
>        
>         v1=om.MVector(t1)
>         v2=om.MVector(t2)
>         
>         dist=om.MVector(v2-v1).length() #equivalent to MEL's mag?
>         length+=dist
> print length
>
>
> any ideas? Thanks.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/python_inside_maya/36c4b02b-61b7-4fb7-ab3d-e134bb0e5038%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to