I pretty new to this forum and I desperately need some help with a Python script that I came up with for a boolean operation.
Line 33 (highlighted in red) reports a runtime error: "Must have exactly 2 polygons selected."
Code:
import maya.cmds as mc import maya.mel as mel import random random.seed(5) ### Varibale defining which boolean operation will be used: ### 1 = union, 2 = difference, 3 = intersection booleanOp = 1 for i in range(20): name = "MyObject" + str(i) mc.polyCube(n=name, w=1, d=1, h=1) mc.move(random.uniform(-0.5,0.5), random.uniform(-0.5,0.5), random.uniform(-0.5,0.5)) mc.scale(random.uniform(2.5,3.5), random.uniform(2.5,3.5), random.uniform(2.5,3.5)) mc.polyBoolOp("MyObject0", "MyObject1", op=booleanOp, n="MyResult1") for next in range(2, 20): objNext = "MyObject" + str(next) previous = next - 1 objPrevious = "MyObject" + str(previous) result = "MyResult" + str(next) mc.polyBoolOp(objPrevious, objNext, op=booleanOp, n=result) mc.rename("MyResult19", "MyResult0") for j in range(20): mc.polyCylinder(n="MyCylinder"+str(j), h=random.randrange(8, 9), r=random.uniform(0.05, 0.1)) mc.move(random.randrange(-1, 1), random.randrange(-1, 1), random.randrange(-1, 1), ) mel.eval('mc.polyBoolOp(op=2, n="MyResult") + str(j+1) + "MyResult" + str(j) + "MyCylinder" + str(j)')
Thanks