Get Curve length
import maya.cmds as cmds
import maya.mel as mel
def lengthOfCurve(dagPathToCurve):
"""
Assume that the Shape path is given, error checking is for upstream
"""
import maya
numSpans = cmds.getAttr("%s.spans" % dagPathToCurve)
arcLengthTemp= cmds.arcLengthDimension("%s.u[%s]" % (dagPathToCurve,numSpans))
nodeParent = cmds.listRelatives(arcLengthTemp,parent=True)
curveLength = cmds.getAttr ("%s.al" % arcLengthTemp)
cmds.delete(nodeParent)
return curveLength
for i in cmds.ls(selection=True):
shapeNodes = cmds.listRelatives(i,shapes=True)
for shape in shapeNodes:
if cmds.nodeType(shape) == "nurbsCurve":
print "Curve: %s is %s units long" % (shape, lengthOfCurve(shape))
else:
print "Wrong: %s is a %s" % (shape, cmds.nodeType(shape))