# 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/2606977d-8837-430d-88d5-6527440e33d9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.