I have a chunk of code I'm trying to execute based on if a scale-based animation has completed. The base concept is that a city block (plane) is created with a keyframed scale value of zero, and then 6 frames later, it should have a new keyframe scale value of one. Once it's gone from a scale of 0 to full size, I want buildings (cubes) to generate on top of the block; the locations of the new buildings are based on the vertex locations of the full size of the block.
The problem is I don't know how to query if the size of the plane has changed, and then use that as a trigger.
I have two sets of code right now, one to generate planes/blocks:
def planes(planesNum):
#help with this code from user https://stackoverflow.com/users/51685/akx
for i, pos in enumerate(positions[:planesNum]):
cmds.polyPlane(w=10,h=10,sw=5,sh=5,n=f'plane_{i}')
cmds.move(pos[0],pos[1],pos[2])
scaleNum = 0
if i > 1:
cmds.setKeyframe(f'plane_{i}', at='scaleX', v=scaleNum, t=[6*(i)])
cmds.setKeyframe(f'plane_{i}', at='scaleZ', v=scaleNum, t=[6*(i)])
#changing the value of the scale in a variable...
#...to hopefully use as a trigger later
#scaleNum= scaleNum+1
cmds.setKeyframe(f'plane_{i}', at='scaleX', v=scaleNum+1, t=[(6*i)+6])
cmds.setKeyframe(f'plane_{i}', at='scaleZ', v=scaleNum+1, t=[(6*i)+6])
#here 'v' is being set to a now-higher-valued scaleNum
#cmds.setKeyframe(f'plane_{i}', at='scaleX', v=scaleNum, t=[6])
#cmds.setKeyframe(f'plane_{i}', at='scaleZ', v=scaleNum, t=[6])
vertCount = cmds.polyEvaluate(f'plane_{i}', v=True)
And one to generate new cubes/buildings:
for j in range(vertCount):
v = cmds.xform(f'plane_{i}.vtx[{j}]', q=True, ws=True, t=True)
ranVert = r.randint(0,99)
cY= r.randint(3,10)
cmds.polyCube(h=cY, n=f'building_{j}')
cmds.move(v[0],.5*cY,v[2],f'building_{j}')
I want to tie these two events together so that when the plane reaches its full size, it then generates the cubes from the vertex locations of the plane. I've tried using while loops with closures/nested code, but I always run into the issue of the variables not being declared before they're used.