PDA

View Full Version : rename is not working...


misterwolfy
10-14-2010, 04:47 AM
I am trying to create a grid of cubes and rename them. I have a script that works, but the rename is broken for some reason. Below is the code.

To explain the problem: the way I have this set up the last cube created should be named: "cube_1p0_1p0", but in fact it is named "cube_1p0_1p4". When I print the code that I use to rename it shows the last cube should be named "cube_1p0_1p0". Run the script and you will see what I mean.

Any ideas?


##Python

x = -2
count = 0
cubes = []
while x <= 2:
z = -2
while z <= 2:
newCube = mc.polyCube( name = ( 'newCube_' + str(count) ) )
cubeName=newCube[0]
cubes.append(cubeName)
mc.setAttr((cubeName + '.translateY'), .5);
mc.makeIdentity(apply=True, t =True, r=True, s=True, n= 0)
mc.ResetTransformations()
newPosX = ((x+2))
newPosZ = ((z+2))
mc.move( newPosX, 0, newPosZ )
nX = str( float(newPosX) / 4)
nXf = nX.replace('.', 'p')
nZ = str( float(newPosZ) / 4)
nZf = nZ.replace('.', 'p')
mc.rename(newCube[0], 'cube_' + nZf + '_' + nZf )
print ('nXf is ' + nXf + ' and nZf is ' + nZf + ' the cube has just been renamed: ' + ('cube_' + nZf + '_' + nZf) + '\n')
mc.move( x, 0, z )
count +=1
z += 1
x +=1



Thanks for reading!

mje11even
10-14-2010, 05:02 AM
The names need to be unique and there are a total of four cubes that you are trying to name cube_1p0_1p0. Perhaps you meant to use

mc.rename(newCube[0], 'cube_' + nXf + '_' + nZf )

instead of

mc.rename(newCube[0], 'cube_' + nZf + '_' + nZf )

misterwolfy
10-14-2010, 10:43 AM
Yes, duhhhh! That was it. Thanks for the help, and your fresh eyes!

Best,

Wolfy

CGTalk Moderation
10-14-2010, 10:43 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.