How to get the arclen between two curve points in Maya? -
in maya 2015, can arclen of curve using command:
cmds.arclen('bezier1')
but want arclen of 2 points in curve. there anyway this?
using maya's api surely best way @scottiedoo said, here function made when didn't know api , gives same results.
from maya import cmds def computecrvlength(crv, startparam = none, endparam = none): ''' compute length of curve between 2 given uparameters. if both uparameters arguments set none (default), compute length of whole curve. arguments: - crv = string; existing nurbcurve - startparam = 0 <= float <= 1 or none; default = none; point parameter value, if not none, compute points between startpt , endpt values. - endparam = 0 <= float <= 1 or none; default = none; point parameter value, if not none, compute points between startpt , endpt values. returns: - length of curve between given uparameters - length of curve start startparam - length of curve start endparam ''' ###### exceptions if cmds.objexists(crv) == false: cmds.error ('the curve "%s" does\'nt exists.' % crv) if cmds.filterexpand (crv, sm = 9) == none: cmds.error ('the object "%s" not nurbcurve.' % crv) if startparam != none: if (0 <= startparam <= 1) == false: cmds.error ('the start point parameter value must between 0 , 1.') if endparam != none: if (0 <= endparam <= 1) == false: cmds.error ('the end point parameter value must between 0 , 1.') if (startparam == none , endparam != none) or (startparam != none , endparam == none): cmds.error ('the start , end points parameters must both none or ' + 'both have values.') if startparam != none , endparam != none: if endparam < startparam: cmds.error ('the end point parameter value cannot less or ' + 'equal start point parameter value.') ###### function if startparam == none , endparam == none: crvlength = cmds.arclen (crv, ch = false) distcrvtostartparam = 0 distcrvtoendparam = crvlength else: tmparclendim = cmds.arclengthdimension (cmds.listrelatives(crv, s = true)[0] + '.u[0]') cmds.setattr (cmds.listrelatives(tmparclendim, p = true)[0] + '.uparamvalue', startparam) distcrvtostartparam = cmds.getattr (tmparclendim + '.al') cmds.setattr (cmds.listrelatives(tmparclendim, p = true)[0] + '.uparamvalue', endparam) distcrvtoendparam = cmds.getattr (tmparclendim + '.al') cmds.delete (tmparclendim) crvlength = (distcrvtoendparam - distcrvtostartparam) return crvlength, distcrvtostartparam, distcrvtoendparam
Comments
Post a Comment