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
) to do something like this??
Thank you a lot!
Daniel
PS: here is the script, it is in python
CODE
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