/* */

Tuesday, 21 August 2012

Rename Script

Little renaming script for iterating over a list of objects and renaming each item:

## place selection into variable 'sel':

sel = cmds.ls(selection= True)

## create a for loop and iteratate over the list:
 for i in range(0,24):

##Use the rename command to rename the objects

 cmds.rename(sel[i], sel[i][:3] + '%s'  %(i))

 
print sel

Quick not on this one - the for loop uses 'range(0,24)' - this was me being a bit lazy, to make the script more dynamic I could have used the 'len()' function to set the for loop parameters, so it would have read:

for i in range (0,len(sel)):
               blah blah etc

I then used string formatting to place the value of i at the end of the name

In the process I got nice and stuck on pretty noob style, schoolboy errors:
I first set up the for loop wrong:

for i in sel:
               cmds.rename()

This set the value of i to the content of sel[] rather than its integer position - got errors like 'expecting type int got unicode'.

I also toyed with setting up an extra counter - declaring variable x as 0 outside the scope of the loop and then iterating inside the loop, but that meant x had a value of 1 and....you get the jist - bad idea and the wrong way of going about it




<< 01 02 03 04 05 06 07 08 09 10 >>

No comments:

Post a Comment