PDA

View Full Version : memory problems with duplicate


nier
02-09-2008, 11:52 PM
Hello!

In my script I need to duplicate a certain object more the 1000 times... maya naturally keeps crashing. I tried instancing instead, same problem...

Is there any technique better (or smarter :P) to do something like this??

Thank you a lot!
Daniel

PS: here is the script, it is in python
def duplicateOnNormal():
# gets an obj named "element" and duplicates it align to each face's normal of the selected polygon
# get the poly name:
sel = cmds.ls(sl=1)
if (len(sel) != 1):
mm.eval('warning "You need to select an object!";')
return
obj = sel[0]
print "Selected object: " + obj

#get number of face on obj
nFaces = cmds.polyEvaluate(obj, vertex=1)

#for each face, get its normal, duplicate "element" and position on it, and normalConstraint "element" to the normal
newGroup = cmds.group(empty=1, name="elements")
i=0
while i <= nFaces:
f = obj+".vtx["+str(i)+"]"
#find face position
fPos = cmds.xform(f, q=1, t=1, ws=1)
#duplicate "element" and position it on the face's coordinates
newObj = cmds.instance("element") #cmds.duplicate("element")
cmds.xform(newObj[0], t=(fPos[0], fPos[1], fPos[2]), ws=1)
#normalConstraint it
cmds.normalConstraint( f, newObj[0], aimVector = (0,0,1))
# and group it
cmds.parent(newObj ,newGroup)
#cmds.refresh(cv=1)

i+=1

greatPumpkin
02-11-2008, 07:43 AM
try ways of iterating less on the duplicate command. So, instead of looping every face initially, try duplicating or extruding all faces, and then separating them, then looping through that result and performing your normal constraint-

nier
02-11-2008, 09:11 AM
Well, duplicate was giving me too much trouble, to I went for creating another polygon on each place, with history turned of... goes smootlhy now...

Thanx!!

CGTalk Moderation
02-11-2008, 09:11 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.