--
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 python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/c2037bbe-0d8c-41df-bdad-5d870ed2be09%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
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 python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/7834a76c-3cda-4aad-a394-15a729daed3d%40googlegroups.com.
import maya.OpenMaya as om
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CABBPk37HiCpsvzgCi8QDFnRn-Pgyg%3Dpupj%2BxC6X7cW5G54Lbiw%40mail.gmail.com.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/7834a76c-3cda-4aad-a394-15a729daed3d%40googlegroups.com.
--
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 python_inside_maya+unsub...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CABBPk37HiCpsvzgCi8QDFnRn-Pgyg%3Dpupj%2BxC6X7cW5G54Lbiw%40mail.gmail.com.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/4df5702a-0697-403f-9ea2-76e6fffd4316%40googlegroups.com.
# 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 lengthI'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 lengthdef 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])
from math import *
def dist (objA, objB):
Ax,Ay,Az=mc.xform(objA,q=1,t=1)
Bx,By,Bz=mc.xform(objB,q=1,t=1)
return sqrt(pow((Ax-Bx),2)+pow((Ay-By),2)+pow((Az-Bz),2))
def lenJointChain(obj,len=0):
print obj
if mc.listRelatives(obj,children=1)==[]:
return len
else:
child=mc.listRelatives(obj,children=1,type='transform')[0]
return lenJointChain (child, len=len+dist(obj,child))
lenJointChain(mc.ls(sl=True)[0])