Update a string with procedure - Issue

Update a string with procedure - Issue

t.pansiot
Explorer Explorer
611 Views
4 Replies
Message 1 of 5

Update a string with procedure - Issue

t.pansiot
Explorer
Explorer

Hi, 

Here is my issue, I want to create a tool to change a string Value:

Theoric Example:   Variable called  "Name One"

Click on the tool to update Variable in "Name Two"

 

MEL Script:

string $Target = "NAME_ONE";


string $window = `window -title "Long Name"
-iconName "Short Name"
-widthHeight 200 55`;
columnLayout -adjustableColumn true;
button -label "Change Name" -command "NewName($Target)";
button -label "Close" -command ("deleteUI -window " + $window);
setParent ..;
showWindow $window;

 

proc NewName(string $Target){
$Target = "NAME_TWO";
print $Target;
}

 

print $Target;

 

 

During the procedure, it seems to work, nut as soon as I print $Target again, it remains, "Object_One"

 

Anyone would know a trick?

 

0 Likes
Accepted solutions (1)
612 Views
4 Replies
Replies (4)
Message 2 of 5

mspeer
Consultant
Consultant

Hi!

 

Try something like this:

global proc string NewName(string $name){
$name = "NAME_TWO";
return $name;
}

NewName("whatever");
print `NewName("whatever")`;
print (NewName("whatever"));
0 Likes
Message 3 of 5

t.pansiot
Explorer
Explorer
Accepted solution

Here is the solutions: string should be "global string" and it should be called inside the proc like this:

global string $Target = "NAME_ONE";

string $window = `window -title "Long Name"
-iconName "Short Name"
-widthHeight 200 55`;
columnLayout -adjustableColumn true;
button -label "Change Name" -command "NewName()";
button -label "Close" -command ("deleteUI -window " + $window);
setParent ..;
showWindow $window;

global proc NewName(){
global string $Target ;
$Target = "NAME_TWO";
print $Target;
}

print $Target;

Message 4 of 5

t.pansiot
Explorer
Explorer
Thanks a lot Mspeer, I found a solution bellow
0 Likes
Message 5 of 5

mspeer
Consultant
Consultant

Hi!

Yes I tested this too and it did not work, but I guess this was, because I had already declared the variable based on your example code and would have needed to close and reopen Maya.

0 Likes