Thursday, August 6, 2009

Assignment01B

I managed to make the part with the rotation and the scale of the square but when i tried to make it recursive i could not manage to select all the time the last square created. I tried to make a list where to store all of them and always refer to it from the list but it doesn't work as well.


###########################
###assignment01B
###student Andreea Nica


import maya.cmds as cmds


def squares (it,i):

##select the needed sides of the square
t=i-1
cmds.select('nurbsSquare%d'%t)
isSides = cmds.filterExpand(sm=9)

line1 = isSides[0]
line2 = isSides[1]

##get the point on the side of the square at the specific proportion
poc1 = cmds.pointOnCurve( line1, pr=perc1, top=True, p=True ) #rightnurbsSquare
poc2 = cmds.pointOnCurve( line2, pr=perc2, top=True, p=True )

##find the corner of the square in order to find the exact position where the second square will be moved
perc3 =1
corner = cmds.pointOnCurve( line2, pr=perc3, top=True, p=True )

##create the second square

cmds.duplicate('nurbsSquare%d'%t)
if t <> 1:
SquaresList.append('nurbsSquare%d'%t)

##find the position where the last square will be placed
x = corner[0]-poc1[0]
xx=float(x/3)
y= corner[0]
yy=float(y/3)

##move the square
cmds.move (xx,yy,0, 'nurbsSquare%d'%i)
cmds.select('nurbsSquare%d'%i)

##find the pivot for scale and rotation
x1=float(poc2[0])
y1=float(poc2[1])

##scale and rotate
cmds.scale( .8, .8, .8, 'nurbsSquare%d'%i, pivot=(x1, y1, 0), absolute=True )
cmds.rotate(0,0,'20deg',pivot=(x1, y1, 0),absolute=True)

##select only the last square created
cmds.select( clear=True )
cmds.select('nurbsSquare%d'%i)

cmds.hide('nurbsSquare%d'%t)

##check if the last iteration was reached or not
if it == 0 :
#stop
cmds.showHidden( all=True )
print 'gataaaaaaaaaaaaaaaa'
return "Done."
else:
#did not finish yet
#remove one unit (count down)
it -= 1
i += 1

squares(it,i)

##create the initial square
initialSquare = cmds.nurbsSquare( sl1=10, sl2=10 )
isSides = cmds.filterExpand(sm=9)
print isSides
perc1 = 1./3
perc2 = 2./3

SquaresList = []
SquaresList.append('nurbsSquare1')
print SquaresList
##call the recursive function

squares(4,2)

print 'Final List'
print SquaresList

No comments:

Post a Comment