Community
Maya Forum
Welcome to Autodesk’s Maya Forums. Share your knowledge, ask questions, and explore popular Maya topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Update a string with procedure - Issue

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
t.pansiot
358 Views, 4 Replies

Update a string with procedure - Issue

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?

 

Labels (7)
4 REPLIES 4
Message 2 of 5
mspeer
in reply to: t.pansiot

Hi!

 

Try something like this:

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

NewName("whatever");
print `NewName("whatever")`;
print (NewName("whatever"));
Message 3 of 5
t.pansiot
in reply to: mspeer

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
in reply to: mspeer

Thanks a lot Mspeer, I found a solution bellow
Message 5 of 5
mspeer
in reply to: t.pansiot

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.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Technology Administrators


Autodesk Design & Make Report