PDA

View Full Version : getting selected object type


doppelganger
10-31-2003, 12:39 AM
I have been checking the online docs to no avail. I cannot seem to figure out how to get `ls` to show me if the user has selected a nurbsCurve or not.
ls -type geometryShape -showType;
shows me what is in the scene but I just want to test the selected object when I user runs a mel script to be sure it is a nurbsCurve. Am I on the right track here with using ls?
I couldn't find a more appropriate command.


Thanks in advance,

Scott

Doogie
10-31-2003, 01:55 AM
Well, this might help... What you have selected is the transform node (the shape node is under the transform node), so you have to get the shape node first (`ls -dagObjects -selection`), then decide what kind it is.

to see what kind of node is selected, you can use `ls -selection -showType`.

I dunno the easiest way to determine the type of node from the selection... I'm curious to hear the responses.

Buexe
10-31-2003, 08:17 AM
Doogie is right, if the selected object is a transform node it might have a shape node under it, so you have to check that first, than you can also use the nodeType command to check the type:

nodeType curve1;
// Result: transform //
nodeType curveShape1;
// Result: nurbsCurve //

b

doppelganger
10-31-2003, 03:31 PM
thanks for the replies!
I am still not quite clear on how I would navigate down from the transform node to the shapenode in MEL to retrive the nodeType. If the user has selected a curve named say curve1 and I issue the following commands I get this
ls -dagObjects -selection;
// Result: curve1 curveShape1 //
ls -selection -showType;
// Result: curve1 transform //
nodeType curve1;
// Result: transform //
nodeType curveShape1;
// Result: nurbsCurve //

What I am mixed up on is how to navigate down from the transform node (which seems to be what is selexted when a user click drags or just clicks on a curve) to the shape node which will allow me to capture the nodeType. Looking at the above output I could capture the output and do some string manipulation but I cant help but think there is an easier way.

I am still new to MEL so I really do appriciate all the help.

Thanks

Scott

Buexe
10-31-2003, 03:39 PM
use:
listRelatives -f -s;
to get the shape node than you can use the "strcmp" command to check if the Result is what you like. could put a better example of this together, but IM sort of in a hurry, maybe I can help you better later
sorry
buexe

Doogie
10-31-2003, 03:55 PM
global proc string objType(string $selection)
{
string $objType[];

$objType = `listRelatives -s $selection`;
return `nodeType $objType[0]`;
}


That should work, just drop that in your script and call it like objType curve1;

doppelganger
10-31-2003, 04:23 PM
Doogie,

That works great! Thanks so much for the help!

Scott

Doogie
11-17-2003, 12:56 AM
I can't believe I had forgotten about this command.

// Get the shape node
$shape = getShape( $node );


I came across it again browsing through http://www.ewertb.com/maya/mel/index.html

Just thought Id update this thread... This should make it a lot easier in the future.

doppelganger
11-17-2003, 01:59 AM
thanks!!!

That just simplified my code so much!!!

Sincerely,

Scott

Buexe
11-18-2003, 07:33 AM
Bryan did it again!
Thanx pointing that one out, Doogie
cheers
buexe

dwalden74
11-18-2003, 08:41 AM
I can't believe I had forgotten about this command.
$shape = getShape( $node );



Uh, this is just calling his own getShape procedure, and is certainly not a standard MEL command...

Doogie
11-18-2003, 12:04 PM
Sorry, I had pointed it out to keep him(or her) from having to include his own procedure to do this in each script that used it (I certianly didn't suggest it for speed improvements). Is there any occasions that this procedure call would not work? Or were you just pointing out the fact I improperly called it a command and not a procedure?

-Paul

dwalden74
11-18-2003, 12:35 PM
I just thought it was a little wierd that, out of the middle of nowhere, you suggested that he call `getShape( $node )`, without explaining at all what it was doing...as if just putting this into your script would return the shape node. And yes, saying it's a "command" makes it sound like it's some internal Maya thing, when it obviously isn't. I think there was just a misunderstanding of the wording in this thread.

CGTalk Moderation
01-16-2006, 01:00 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.