mayamel

Stuck on script/procedure to combine two curves into one


I have been learning Mel, just finished MEL Scripting for Maya Animator and also read through the official Mel guide. Apparently in Maya there is no native way, at least through the UI, to combine two curves into a single object. After some searching I eventually figured out how to do it through the UI.

I figured this would be perfect project to break my teeth with, a Mel command/procedure that does this:

  1. Get the selected objects,
    • If the selection consists of mixed objects, filter for curve objects only
  2. Move all of the curves shapes to the leading objects transform node
  3. Delete all of the transform nodes that are now empty

I would essentially be reproducing the steps shown in this video, Combine Curves. Merge curves into one curve.

Things is I am just staring at the blinking cursor, and not getting anywhere. I have figured out how to get the selected objects with:

string $selection[] = `ls -selection`;
print($selection);   // prints 'curve1' and 'curve2' 

I am stuck on determining if curve1 and curve1 are transform nodes or shapes? I have a pretty decent background in shell environments and currently use PowerShell (core) heavily. So not everything is perplexing me here. In the case of Mel, curve1 and curve2 are just strings, not objects that can be queried.

I know shape nodes have Shape appended to them, so I can kind of tell but how does one go about identifying these things anyways.

Any examples or a suggestion would be amazing to have.

Edit1:

I also tried the -shape flag for parent, parent -s;, it results in the hierarchy shown in the first example of the image below. But I am expecting to get a hierarchy that is similar to the second example (curve3, the name is incidental):


Solution

  • You cold try to parent like this:

    parent -s -r curveShape newTransformNode;
    

    This only works correctly if the transform node of the curveShape is not transformed in space. If so, it will jump relative to the new transform. So if you have any transformation you have to freeze transforms first.