Reputation: 1
i'm trying to create a UI for Maya but when i try to run this code it works fine but when i click on create sphere it says error on line 77 about "width" but i didn't write nothing on line 77 about Width.. someone can help me please? (i'm a beginner)
import maya.cmds as cmds
class MR_Window(object):
#constructor
def __init__(self):
self.window = "MR_Window"
self.title = "Polygon Creator"
self.size = (400, 400)
# close old window is open
if cmds.window(self.window, exists = True):
cmds.deleteUI(self.window, window=True)
#create new window
self.window = cmds.window(self.window, title=self.title, widthHeight=self.size)
cmds.columnLayout(adjustableColumn = True)
cmds.text(self.title)
cmds.separator(height=20)
self.cubename = cmds.textFieldGrp( label='Cube Name:' )
self.cubeSize = cmds.floatFieldGrp(numberOfFields=3, label='size:',
value1=1, value2=1, value3=1)
self.cubeSubdivs = cmds.intSliderGrp(field=True, label='Subdivs',
minValue=1, value=1)
self.cubeCreateBtn = cmds.button(label='Create Cube', command=self.createCube)
self.spherename = cmds.textFieldGrp( label='Sphere Name:' )
self.sphereSize = cmds.floatFieldGrp(numberOfFields=3, label='size:',
value1=1, value2=1, value3=1)
self.sphereSubdivs = cmds.intSliderGrp(field=True, label='Subdivs',
minValue=1, value=1)
self.sphereCreateBtn = cmds.button(label='Create Sphere', command=self.createSphere)
#display new window
cmds.showWindow()
def createCube(self, *args):
name = cmds.textFieldGrp(self.cubename, query=True, text=True)
width = cmds.floatFieldGrp(self.cubeSize, query=True, value1=True)
height = cmds.floatFieldGrp(self.cubeSize, query=True, value2=True)
depth = cmds.floatFieldGrp(self.cubeSize, query=True, value3=True)
subdivs = cmds.intSliderGrp(self.cubeSubdivs, query=True, value=True)
cmds.polyCube(name=name, width=width, height=height, depth=depth,
subdivisionsWidth = subdivs, subdivisionsHeight = subdivs,
subdivisionsDepth = subdivs)
def createSphere(self, *args):
name = cmds.textFieldGrp(self.spherename, query=True, text=True)
width = cmds.floatFieldGrp(self.sphereSize, query=True, value1=True)
height = cmds.floatFieldGrp(self.sphereSize, query=True, value2=True)
depth = cmds.floatFieldGrp(self.sphereSize, query=True, value3=True)
subdivs = cmds.intSliderGrp(self.sphereSubdivs, query=True, value=True)
cmds.polySphere(name=name, width=width, height=height, depth=depth,
subdivisionsWidth = subdivs, subdivisionsHeight = subdivs,
subdivisionsDepth = subdivs)
myWindow = MR_Window()
Upvotes: 0
Views: 518
Reputation: 136
Your issue seems to be you're trying to create your polySphere as if it was a polyCube in terms of parameters when they're quite different.
polySphere's don't have any of the parameters you've specified other than name. Instead it's height, width and depth would be defined by it's radius value.
Example:
cmds.polySphere(name='TestSphere', radius=20)
As such you'll want to update your UI to take different inputs for the Sphere and pass them in instead of the current ones. For subdivisions, you should also use subdivisionsX, and subdivisionsY.
cmds.polySphere(name='TestSphere', radius=20, subdivisionsX=5, subdivisionsY=5)
The links above will outline the available parameters and give some examples.
Upvotes: 1