When I used this example, the function MQSystem.getDocument().deleteObject(x) didn't delete the cache of objects that every time I run the code, the number of objects are accumulated and make the window lagged.
Is it possible to fix this problem?
Is there a code similar to AllObject.Clear()?
------------------------------------------------
import random
doc = MQSystem.getDocument()
out = MQSystem.println
for x in range(0, MQSystem.getDocument().numObject):
MQSystem.getDocument().deleteObject(x)
def p(*args):
if len(args)==0:
MQSystem.println("")
return
for arg in args:
MQSystem.println(str(arg))
#drawCube_def_metal.py
続きを表示...
def unitcube(L=50,x=0,y=0,z=0):
obj = MQSystem.newObject()
num=doc.numObject
a=num
obj.name="cube_%d" % a
obj.addVertex(x-L/2.0,y-L/2.0,z+L/2.0) #0
obj.addVertex(x+L/2.0,y-L/2.0,z+L/2.0) #1
obj.addVertex(x+L/2.0,y+L/2.0,z+L/2.0) #2
obj.addVertex(x-L/2.0,y+L/2.0,z+L/2.0) #3
obj.addVertex(x-L/2.0,y-L/2.0,z-L/2.0) #4
obj.addVertex(x-L/2.0,y+L/2.0,z-L/2.0) #5
obj.addVertex(x+L/2.0,y+L/2.0,z-L/2.0) #6
obj.addVertex(x+L/2.0,y-L/2.0,z-L/2.0) #7
obj.addFace([0,3,2,1])
obj.addFace([1,2,6,7])
obj.addFace([4,7,6,5])
obj.addFace([0,4,5,3])
obj.addFace([3,5,6,2])
obj.addFace([0,1,7,4])
doc.addObject( obj )
mat1=MQSystem.newMaterial()
doc.addMaterial(mat1)
num0 = doc.numMaterial
numm=num0-1
doc.material[numm].color.red=num0*0.00346
doc.material[numm].color.green=0.1
doc.material[numm].color.blue=1-num0*0.00346
doc.material[numm].alpha=1.0
doc.material[numm].diffuse=1.0
doc.material[numm].ambient=0.0
doc.material[numm].emissive=0.0
doc.material[numm].specular=1.0
for face in obj.face:
face.material=numm
for dist in range(0,1400,60):
for dist2 in range(0,1400,60):
unitcube(40,dist-700,20+random.gauss(0,8),dist2-700)
num = doc.numObject
out("number of cubes %d" % num)