Mel _ Rename error

Mel _ Rename error

jayantbhatt07
Advocate Advocate
1,661 Views
8 Replies
Message 1 of 9

Mel _ Rename error

jayantbhatt07
Advocate
Advocate

Hi, guys, I'm working on a script where it adds the suffix to an object. Suppose my object name is Sphere and I run this script the new name is Sphere_High but the problem I'm facing If I run this script again on an object the new object name is Sphere_High_High which I don't want, I know I can figure it out by adding conditions but that is also not working for me or I'm noob. Here is the command _ 


string $sel[] = `ls -sl`;
int $sSize = size($sel);
string $suffix = "_High";
for($eo in $sel)
rename $eo ($eo + $suffix); 
0 Likes
Accepted solutions (3)
1,662 Views
8 Replies
Replies (8)
Message 2 of 9

rajasekaransurjen
Collaborator
Collaborator

Hi,

To reuse the script make it as procedure.

global proc Test()
{

......

......

}

Your script is working good.

global proc high()
{
string $sel[] = `ls -sl`;
int $sSize = size($sel);
string $suffix = "_High";
for($eo in $sel)
rename $eo ($eo + $suffix);
}

 

0 Likes
Message 3 of 9

jayantbhatt07
Advocate
Advocate

thank for your reply. I know it is working fine but see the attachments. I hope you will get it.

see the attachment ( * )  In that outliner object name is  pCylinder1_High that is fine.

 

BUT

 

When I run this script on more time on the same objects the new name is pCylinder1_High_High. Which I don't want.

 

My main question is that if High suffix is already there it should not work or add that one more time.

0 Likes
Message 4 of 9

rajasekaransurjen
Collaborator
Collaborator
Accepted solution

Ok then try this...

global proc high()
{
    string $sel[] = `ls -sl`;
    int $sSize = size($sel);
    string $suffix = "_High";
    for($eo in $sel)
    if(endString($eo, 5)!="_High")
    {
    rename $eo ($eo + $suffix);
    }
}
0 Likes
Message 5 of 9

jayantbhatt07
Advocate
Advocate

Thank you so much for your help.

 

One more doubt Is it possible to take a screenshot in Maya?  ( I know we can use the snipping tool? )

0 Likes
Message 6 of 9

jayantbhatt07
Advocate
Advocate

Hi, same issue when I changed it from high to low it's not working. Like if I run this script multiple times on the same object it is continuously adding the suffix.

 

global proc Low()
{
string $sel[] = `ls -sl`;
int $sSize = size($sel);
string $suffix = "_Low";
for($eo in $sel)
if(endString($eo, 5)!="_Low")
{
rename $eo ($eo + $suffix);
}
}

0 Likes
Message 7 of 9

olarn
Advocate
Advocate
Accepted solution

How many characters do you think are there in "_Low"

0 Likes
Message 8 of 9

jayantbhatt07
Advocate
Advocate
Hi,Thank you so much got your point. It has 4 characters that mean I have to change that no. From 5 to 4.
0 Likes
Message 9 of 9

rajasekaransurjen
Collaborator
Collaborator
Accepted solution

yes you got it...

0 Likes