Curve thru locators

Hello guys,
The idea of this script is to create a curve thru 2 locators specified by user and update curve position by changing locators’ positions. But when I tried to do opposite, update locators’ positions by changing curve position – it did not work. Does anyone know, what is wrong here and is it possible to simplify or do it in a different way?

Just create 2 locators, select them and run the script:

string $locators[2]=ls -sl;
// 1st point
float $point_0x=getAttr ($locators[0]+".translateX");
float $point_0y=getAttr ($locators[0]+".translateY");
float $point_0z=getAttr ($locators[0]+".translateZ");

// 2nd point
float $point_1x=getAttr ($locators[1]+".translateX");
float $point_1y=getAttr ($locators[1]+".translateY");
float $point_1z=getAttr ($locators[1]+".translateZ");

curve -d 1 -p $point_0x $point_0y $point_0z
-p $point_1x $point_1y $point_1z;

connectAttr -f locator1.translate curve1.cv[0];
connectAttr -f locator2.translate curve1.cv[1];

connectAttr -f curve1.cv[0] locator1.translate;
connectAttr -f curve1.cv[1] locator2.translate;

1 Like

You can not loop things, or you can its just not meaningful, so if you execute both connects at the same time it would not work.

Other than that your code works out fine atleast in maya 2011. Of course if you try to run teh code 2 times then thast a different story. You really need to fetch the returned names!

PS: curve1.cv[0] does not really exist so you should use the slot in the shape instead in this case curveShape1.controlPoints[0] this would save you some headaches in the future.

The little script you wrote cannot work. What you create is a cyclic dependency, your locator drives your curves cv position and those try to control the locators… Maya gives you a hint if you try to do this.
But i think what you really mean is that you try to get your curves control vertices world position and feed them into your locators to have some reference object for further stuff, right?
First, the control vertices values come in object space, so if you change the transformation of your “curve” you change the transformation of your transform node only. The curve shapes are childs of that node and inherit the parents transform, but they do not reflect that change in their local transform values. Thus the locators do not react. So either you write a little script and multiply the local transform values with the transform matrix of the transform node (can become a little bit messy if you parent your curve to other tranforms) or you try the following:

  1. create your curve and your locators
  2. connect the curves shape vertices object space translate values to your locators translate values
  3. parent your locators under your curves transform node (now your locators transform nodes and your curves shape are in the same hirarchy)
  4. create some additional locators and move them each at the corresponding position of your parented locators
  5. select one parented loactor THEN add select the corresponding locator form world space
  6. create a parent constraint

Now you can move your curve and your control vertices, the locators in world space should stay attached to the control vertices.

Thanks for replies. So, as I understand, I was wrong, when I connected locator transform node with curve transform node:
connectAttr -f locator1.translate curve1.cv[0];
While I should connect locator transform node with curve shape node:
connectAttr -f locator1.translate curveShape1.cv[0];
(but how do you know, that it should be done exactly this way???)

And instead of connecting them in opposite way, I can simply parent my locators to the curve.

string $locators[2]=ls -sl;

// 1st point
float $point_0[]=getAttr ($locators[0]+".translate");

// 2nd point
float $point_1[]=getAttr ($locators[1]+".translate");

curve -d 1 -p $point_0[0] $point_0[1] $point_0[2]
-p $point_1[0] $point_1[1] $point_1[2];

connectAttr -f locator1.translate curveShape1.cv[0];
connectAttr -f locator2.translate curveShape1.cv[1];

parent $locators curve1;

Its a alias to data elsewhere.

While I should connect locator transform node with curve shape node:
>> connectAttr -f locator1.translate curveShape1.cv[0];

Well you got half the idea correct the name of the atribute also changes to controlPoints[0] or cp[0] so the acual name is:

connectAttr -f locator1.translate curveShape1.cp[0];

note the name change of the attribute too!

(but how do you know, that it should be done exactly this way???)

Well, you know it because thats what maya ultimately does. If you go look of it in the hypergraph or disconnect you wil see that thats indeed the connection maya made. However you can also deduce this fact form other clues:

curve1 is a transform, you know this by the fact that you have selected it on screen, you can ask maya to verify. The points on the curve do not actually reside in the trasofrm because the trasform is the same irrespectively of type. So when you select a polygon the trasform is the same as in the case of a line, nurbs surface, or locator. The actual geometry is located in the shape thets actually a child of trensform.

Now you can kindly ask maya if curve1 actually has a attribute called cv, you mynotice it does not. So you will notice that indeed things like this are illusions the real data is somewhere else.

And third you can read the relevant part of the manual, in other words the node reference, and come to the same conclusion

in short you will now form now on that the slots of data for the components you select in maya are not actually realy named the way they seem at first glance.

And instead of connecting them in opposite way, I can simply parent my locators to the curve.

Yes, or connect the parnet matrix in… etc. A bidirectional connection is also possible if you use a constraint but thet becomes harder to organize animation around.

Joojaa, thank you for detailed explanation.

Hello,

Is there a way i could adapt this script so that i could keen using it over and over again? i’ve tried with this and it does create the curve between locators but the curve does not parent when you use the script twice.

Thanks for any help.