FORUMS: list search recent posts

Renamer script

COW Forums : Autodesk Maya

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
Otto Lindqvist
Renamer script
on Jul 11, 2012 at 8:23:28 am

Hello,

I started to study MEL to make my future life easier with scripting. I've studied C++ and C# in school and the logic is similar. Languages of course has their differences.

I got the basic script working, but I wanted to create window where to give the commands so no need to edit the code every time with new name.


This is the basic code which works just fine (I had the variables in finnish and changed those in english just in fly. Should work however)




//Valitse objektien nimi ja muista lainausmerkit!

string $NewName = "Jalusta_risti";

//--------Älä Koske!---------------------------------------

string $Named [] = `ls -sl`;

for ($myNode in $Named)
{
select $myNode;
rename $NewName;
};




Here is the code which should create a window where to type to textfield and no need to touch the code. However I get few errors and few are confusing me because before the window system those worked just fine. Here's the error messages:
// Error: string $Named[] = `ls -sl`; //
// Error: Syntax error //
// Error: for ($myNode in $Named) //
// Error: "$Named" is an undeclared variable. //
// Error: select $myNode; //
// Error: "$myNode" is an undeclared variable. //



window -title "Rename objects" -rtf true RenamerWindow;
columnLayout;

textField -label "New name" -field true "NewName";

button -label "Rename" -c "Renamer";



showWindow RenamerWindow;

proc Renamer ()
{

string $NewName = `textField -q -value "NewName"`
string $Named [] = `ls -sl`;

for ($myNode in $Named)
{
select $myNode;
rename $NewName;
}

}



Anyone who could help me? Thanks!

Btw, does anyone know any good script editor for mac which understands MEL?


Return to posts index

Steve Sayer
Re: Renamer script
on Jul 17, 2012 at 5:15:51 pm

A few things need to be corrected here. The first is the easiest: you forgot a semicolon after the string $NewName line. :)

Whenever you have a line that you know should work returning a syntax error, check the line before it for the semicolon.

Now, some of the flags on your interfaces commands are incorrect. Make sure you double-check flags in the help docs. textField controls don't have 'label' flags, but a textFieldGrp does. The flag for the actual text field is 'text,' not 'field' or 'value' (so when you query it, use '-q -text' not '-q -value').

Also, when you query that text field, you need to specify which text field you're referring to, which means you need to capture its name. This is a very common technique useful in all sorts of scripting tasks. When you create your text field, capture its name like this:

string $myFieldName = `textField -tx "New name"`;

Now the string $myFieldName will refer accurately to that particular text field.

Give those suggestions a try and post again if you have more questions. Good luck.


Return to posts index

Otto Lindqvist
Re: Renamer script
on Sep 19, 2012 at 10:01:37 am

Sorry, I've been busy away so I havent had any time to develop this script.

Now I finally tried to finish this script to make it easy to use everyday tool. However I still crashed weird problem. It opens window where is that requested textfield (for some reason there's number one there) and that button which says Rename.

When I type new name and press rename button it gives name like this: RenamerWindow_columnLayout27_textField10

Here's the updated code. I added also added that if statement to the beginning to prevent Objects name is not unique error:

//Clear old window away
if (`window -exists RenamerWindow`)

{

deleteUI -window RenamerWindow;

}

//Create window
window -title "Rename selected objects" -rtf true RenamerWindow;

columnLayout;

textFieldGrp -label "New name" -text true "TextField";



button -label "Rename" -c "Renamer";

showWindow RenamerWindow;

//Renaming procedure
proc Renamer ()
{

string $TextField = `textField -text "NewName"`;
string $Named [] = `ls -sl`;

for ($myNode in $Named)
{

select $myNode;
rename $TextField;

} };



Any suggestions?

If it's not moving, animate it


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2017 CreativeCOW.net All Rights Reserved
[TOP]