Announcements

Between mid-October and November, the content on AREA will be relocated to the Autodesk Community M&E Hub and the Autodesk Community Gallery. Learn more HERE.

curve param at Cvs

curve param at Cvs

egoldid1
Advocate Advocate
1,335 Views
2 Replies
Message 1 of 3

curve param at Cvs

egoldid1
Advocate
Advocate

hi

how i can to get the Curve Param value at one CV(curve CV)?

 

 

 

 

0 Likes
1,336 Views
2 Replies
Replies (2)
Message 2 of 3

robotProdigy
Advocate
Advocate

Normally, I would give a pointer on where to look, but I was bored while waiting on a render. I'm not sure if this works perfectly, or the exact way you need, but it may get you by if it's not. It gets the param value by getting the closest point on the curve from the passed in CV index. Then it gets the param from that using nice convenience methods in the Python API. In addition to returning the param value, it also returns the length, and closest point on the curve (in object space) to the passed in CV. If you want to update this function, you can see what other methods are available for MFnNurbsCurve in the developer docs

 

import maya.api.OpenMaya as om

def get_param_from_cv(curve_name, cv):
"""
Returns the parameter, length, and closest point to the specified CV.

Args:
curve_name (str): Name of the curve
cv (int): The index of the CV in which to return the parameter value of

Returns (list[float, float, MPoint]): parameter, length, closest point on
curve in object space.
"""
dgpa = om.MDagPath.getAPathTo(om.MSelectionList().add(curve_name).getDependNode(0))
curve = om.MFnNurbsCurve(dgpa)
cv_pos = curve.cvPosition(cv, om.MSpace.kObject)
closest_pnt, param = curve.closestPoint(cv_pos)
length = curve.findLengthFromParam(param)
return [param, length, closest_pnt]

# make a curve called curve1
param, length, pnt_on_curve = get_param_from_cv('curve1', 2)

print('param :%s' % param)
print('length :%s' % length)
print('pnt_on_curve:%s' % pnt_on_curve)

 -Paul

Message 3 of 3

aldo.aldrich
Observer
Observer

Thank you!!!