I want to create a grid of spheres for that I wrote a script and got user values for no. of spheres, radius of sphere and distance between spheres. but when i run the script the spheres are being created over one another. I also get an error warning saying those 3 variables are not defined in global scope, and undefined variables.
‘’’
import maya.cmds as mc
global sField,rField,dField
def showUi():
global sField,rField,dField
if mc.window('Win',exists=True):
mc.deleteUI('Win')
mywin = mc.window('Win',title='My Window',widthHeight=(300,200))
mc.columnLayout()
sField = mc.intField(minValue=1)
rField = mc.floatField(minValue=0.1)
dField = mc.intField(minValue=2)
mc.button(label="Make Spheres",command=makeSphere)
mc.showWindow(mywin)
return sField,rField,dField
def makeSphere(*args):
global sField,rField,dField
spField = mc.intField(sField,q=True,value=True)
raField = mc.floatField(rField,q=True,value=True)
diField = mc.intField(dField,q=True,value=True)
for i in range(spField):
mc.polySphere(radius=raField)
mc.move((i*raField*diField),0,0)
for i in range(spField):
mc.polySphere(radius=raField)
mc.move(0,(i*raField*diField),0)
showUi()
‘’’