Jump to content
  • Advertisement
Sign in to follow this  
oneshotflinch

Renaming Objects using MEL Scripts

This topic is 4627 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I am quite new to MEL scripting but not new to programming. I would like to make a MEL script that works on both a single selected object as well as multiple selected objects. I would like it to be able to have the user rename the selected object(s). Then I'd like to check to see if a given object has already been appended (renamed) with the user-input string before it attempts to rename it. I'd like to know what command I use to get the object name so I can parse it into a string. Any help is greatly appreciated. Thanks.

Share this post


Link to post
Share on other sites
Advertisement
Hello,

To get the names of the current selected nodes, you would do something like:

// Get selection into string array
string $select[] = `ls -sl`;

// Process the elements
for($node in $select)
{
print ( $node );
}

The result of the print would be the names of currently selected nodes, pCube1, pCube2 etc.

And to check if the names match:

string $select[] = `ls -sl`;
string $test = "pCube1";
for($node in $select)
{
print ( $node );

if($node == $test)
print ("Names match!");
}


Maya has a built in rename command

rename newName oldName


There's also a built in renameSelectionList command, which can be used to rename selected objects

renameSelectionList("Cube");


Hope that helps :)

A nice site with a big list of how-tos:
http://www.ewertb.com/maya/

In particular #80 might be helpful to you:
http://www.ewertb.com/maya/mel/mel.php?howto=80

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!