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, thanks to a YT guide.
I figured this would be perfect project to break my teeth with, a Mel command/procedure that does this:
- Get the selected objects,
- If the selection consists of mixed objects, filter for curve objects only
- Move all of the curves shapes to the leading objects transform node
- 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.
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):
You rarely need to ever list everything selected and then find or filter for something specific inside that list, because you can just list things of a certain type, in the current selection.
For example, with any number of varied node types selected, you can just do something like this:
string $selCurves[] = `ls -selection -type nurbsCurve -dag`;
print "\nselected curves (shapes):\n";
print $selCurves;
string $selCrvTrans[] = `listRelatives -p $selCurves`;
print "\nselected curve Transforms:\n";
print $selCrvTrans;
so you ls
for type nurbsCurve
, which is more often than not what you want when you want to do stuff with selected curves, but if you do then want/need their transforms, just get them with listRelatives
.
The “trick” here to get the shapes when you have transforms selected is to add the -dag
flag.
In Maya, most “objects” you can select and manipulate in the scene consist of a transform
node (i.e. “curve1”) with a geometry shape child (i.e. “curveShape1”). It is possible, and normal, to parent transforms under each other to create hierarchies, but it’s also possible to reparent a shape node under a new transform. This is not something you are likely to come across or have to worry about very often though.
1 Like
Thank you for this solution and expalanation. Its just what I was hoping for.