我对Maya中的python还不熟悉,我正在尝试构建一个可以生成形状并对其进行变换的UI。我认为问题在于ObjectCreation函数,但我不确定。到目前为止,我得到的是:import maya.cmds as cmds
#check to see if window exists
if cmds.window("UserInterface", exists = True):
cmds.deleteUI("UserInterface")
#create actual window
UIwindow = cmds.window("UserInterface", title = "User Interface Test", w = 500, h = 700, mnb = False, mxb = False, sizeable = False)
mainLayout = cmds.columnLayout(w = 300, h =500)
def SceneClear(*args):
cmds.delete(all=True, c=True) #Deletes all objects in scene
cmds.button(label = "Reset", w = 300, command=SceneClear)
polygonSelectMenu = cmds.optionMenu(w = 250, label = "Polygon Selection:")
cmds.menuItem(label = " ")
cmds.menuItem(label = "Sphere")
cmds.menuItem(label = "Cube")
cmds.menuItem(label = "Cylinder")
cmds.menuItem(label = "Cone")
def ObjectCreation(*args):
if polygonSelectMenu.index == 2: #tried referring to index
ma.polySphere(name = "Sphere")
elif polygonSelectMenu == "Cube":
ma.polyCube(name = "Cube")
elif polygonSelectMenu == "Cylinder":
ma.polyCylinder(name = "Cylinder")
elif polygonSelectMenu == "Cone":
ma.polyCone(name = "Cone")
cmds.button(label = "Create", w = 200, command=ObjectCreation)
def DeleteButton(*args):
cmds.delete()
cmds.button(label = "Delete", w = 200, command=DeleteButton)#Deletes selected object
cmds.showWindow(UIwindow) #shows window
我要做的是让用户从选项菜单中选择一个选项,然后按“创建”按钮生成该形状。我试着用名字和索引来指代它,但我不知道我遗漏了什么。就像我说的,我是python新手,所以当我自己尝试寻找答案时,我什么也找不到,而当我确实找到了类似的东西时,我无法理解它。另外,由于某些原因,SceneClear功能/重置按钮似乎不起作用,因此如果有答案,请告诉我。在