In Maya, how to query the world space coordinates of the control points of a curve using MEL

shapeare picture shapeare · Feb 27, 2013 · Viewed 9.6k times · Source

I created a curve using the EP curve tool. Then I tried to query the world space coordinates of the control points of this curve by using the following MEL commands:

createNode curveInfo;
connectAttr curveShape1.worldSpace curveInfo1.inputCurve;
getAttr "curveInfo1.cp[*]";

but it just printed out the cv coordinates in the object space, say results like:

// Result: 0 0 0 1 0 0 2 0 0 3 0 0 //

Acoording to Maya documentation, the “curve” command can be used to query world space positions, here is a snippet from the documentation:

createNode curveInfo;

connectAttr curveShape1.worldSpace curveInfo1.inputCurve;

getAttr “curveInfo1.knots[*]”;

// This sequence creates a curve info node, connects the info node to the curve and queries the knot vector of the curve using the curve info node. You can use the curve info node to query other attributes such as world space CV values and arc length.

How to use the “curve” command to query world space positions?

I also tried using the “xform” command, but it seems that it does not work for my curve. The result is like:

xform -q -t -ws curve1;
// Result: 0 0 0 //

Answer

joojaa picture joojaa · Feb 27, 2013

Easiest way is to use the pointPosition command eg.:

pointPosition -w object.ep[1] 

Point position works with any of the point attributes ep, cv, uv, pt etc. But can only query one point at a time so you need to loop.

Nodes dont have any concept of world or local space coordinates (tough you could transform the space), just raw data coordinates. Knots is not what your looking for tough knots define how the curve is parametrized. In general Maya documentation is a bit hard to read for beginning users because Maya operates on a object accessor model. So command and operations don't necessarily do what you would think they do. Rather many commands are accessors to something, and they only operate on the object they are accessors of. Curve command has no conquerable attributes so it can not be queried.