View Full Version : Strange mel pb
Nicool 01-01-2003, 08:00 PM // User interface
$result=`promptDialog
-title " Rename Selection"
-message "Enter the new name for the selection renaming."
-button "Ok"
-button "Cancel"
-defaultButton "Ok"
-dismissString "Cancel"`;
if ($result == "Ok") {
$newName = `promptDialog -q`;
$newName = ("\"" + $newName + "\"");
renameSel($newName);
}
// proc
global proc renameSel (string $newName) {
for ($sel in `ls -sl`) {
rename $sel ($newName + "#");
}
print "Selection renaming done.";
}
When I run my script, error : // Warning: Removing invalid characters from name. // is repeted for each object. But by proc works right alone, so I think it's the interface...
Help me
:bounce:
|
|
bigfatMELon
01-01-2003, 10:36 PM
Yes, you are adding quote characters to your string. Specifically, this line:
$newName = ("\"" + $newName + "\"");
Quote characters are illegal in Maya addresses. There is no need to add these characters since what you are adding them to is already a string. You only need to do something like this to force quotes into strings that will be evaluated or externally parsed, like with the sys command. Remove that line.
While we're looking at your code, I also don't quite see the point of wrapping the rename function in a global proc. You're only abstracting two lines of code. It seems rather wasteful.
My version looks like this:
$result=`promptDialog
-title " Rename Selection"
-message "Enter the new name for the selection renaming."
-button "Ok"
-button "Cancel"
-defaultButton "Ok"
-dismissString "Cancel"`;
if ($result == "Ok"){
$newName = `promptDialog -q`;
for ($sel in `ls -sl`)
rename $sel ($newName + "#");
}
print "Selection renaming done.";
-jl
Nicool
01-01-2003, 11:25 PM
Yes, you are true (and you are evidently a better coder than me)... But I want to keep my little (and my first one) function independent to the interface !:rolleyes:
So can't I keep my function??
(So I've seen later you've already create a script to rename a selection and the function has the same name "renameSel"... At first I was surprised :surprised because my script wasn't finished and I've sent a MEL on Highend.com :p So excuse me, be sure I've not copy you !)
Thanks
Nicool
01-01-2003, 11:29 PM
Sorry I've test my script without the line to add quotes... And it works well.
I've add too an error message to make sure the user have realy some objects selected :)
Thanks
bigfatMELon
01-02-2003, 07:01 PM
Originally posted by Nicool
Yes, you are true (and you are evidently a better coder than me)... But I want to keep my little (and my first one) function independent to the interface !:rolleyes:
So can't I keep my function??
(So I've seen later you've already create a script to rename a selection and the function has the same name "renameSel"... At first I was surprised :surprised because my script wasn't finished and I've sent a MEL on Highend.com :p So excuse me, be sure I've not copy you !)
Thanks
You can keep your function if you prefer. That was just a suggestion on code efficiency.
Also, it would be just fine if you copied what I wrote because it's an edited version of what you wrote and I gather that you copied portions of it from somewhere else as well. This is the nature of coding and for mel especially.
And to throw another log on the fire, here's a floating window version of this kind of script:
global proc renSel (string $field){
string $sel[] = `ls -sl`;
string $x;
for ($x in $sel)
rename $x (`textField -q -tx $field` + "#");
}
global proc renameItWin (){
string $field;
if (`window -ex "renWin"`)
deleteUI "renWin";
window -title "Rename" -w 220 -h 80 -s false "renWin";
columnLayout -w 200 "renCol";
text -l "" -h 10;
rowLayout -nc 1 -cw 1 180 -cat 1 "left" 20;
$field = `textField -w 180 "renField"`;
textField -e -cc ("renSel " + $field) "renField";
setParent..;
rowLayout -nc 1 -cw 1 200 -cat 1 "left" 120;
button -l "Rename" -w 80 -c ("renSel " + $field);
setParent..;
text -l "" -h 16;
showWindow "renWin";
}
-jl
Nicool
01-02-2003, 09:48 PM
Because I know your are realy stronger than me, I want you exaplein me why don't you use simply a dialog function for your interface??
bigfatMELon
01-03-2003, 12:36 AM
Well, I think there still remains some doubt as to who is stronger as we've yet to arm wrestle or challenge one another to a contest of lifting heavy stones.
Now, as to the lack of the dialog function, I looked at your original idea and got to thinking that it's useful, but also cumbersome in that the dialog is modal. That is, it comes up, you must type, then you hit enter and it goes away. That's a lot of stuff happening and you have to retype your entry every time.
It would be more useful to have a small floating window that stays open until dismissed. You can then apply your new names at will, and without necessarily retyping them. It also offers a great opportunity to see how something like this might be coded, where the rename function MUST be a global proc.
Also, there is the matter of software design rules of thumb. If the goal of your script is to provide a renaming UI and there is no reason to prevent the user from doing other things when asking them for the new name, then there is every reason to avoid doing that. Hense, a floating window instead of a modal dialog. If I was going to ask the user for a file name before writing a file, then I might want the user to focus on that one thing before moving on. It's the difference between performing a task and providing a tool. The floating window version is a tool.
Of course, every rule has a converse rule, like "this is quick and dirty scripting so get off your high horse and just get the damned thing done." In which case, the modal dialog function is perfect.
-jl
Nicool
01-03-2003, 09:17 PM
I've read what you've written
Thanks :)
CGTalk Moderation
01-14-2006, 02:00 AM
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.
vBulletin v3.0.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.