【发布时间】:2020-09-11 07:15:58
【问题描述】:
我正在阅读 Adrian Herbez 编写的 Maya Programming with Python Cookbook,但遇到了一个示例(第 31 页),该示例创建了一个类,该类生成用于在 Maya 中制作简单球体的用户界面。当我重现代码并运行脚本时,它会加载但在 Maya 中没有任何反应。我之前能够在不使用类方法的情况下创建用户界面,所以我想知道类代码是否有问题。我对课程的理解有点不稳定,但我找不到它可能有什么问题。我正在使用 Atom 并使用调用脚本
import(makeSpheres) 和 reload(makeSpheres)。
代码如下:
import maya.cmds as cmds
class SpheresClass:
def __init__(self):
self.win = cmds.window(title="Make Spheres",widthHeight=(300,200))
cmds.columnLayout()
self.numSpheres = cmds.intField(minValue=1)
cmds.button(label="Make some spheres", command=self.makeSpheres)
cmds.showWindow(self.win)
def makeSpheres(self, *args):
number = cmds.intField(self.numSpheres,query=True,value=True)
for i in range(0,number):
cmds.polySphere()
cmds.move(i*2.2,0,0)
SpheresClass()
在 Atom 中,self.win、self.numSpheres 和 self.makeSpheres 以红色突出显示,但 linter 没有任何错误消息。
【问题讨论】:
-
已解决错误是我在 SpheresClass() 之前有一个缩进,所以现在已经修复了!哦,不,多么糟糕的第一个问题!
-
您实际上是在该类的
makeSpheres函数中调用SpheresClass。你打算这样做吗? -
别担心@3orange1red,欢迎使用 Maya 中的 Stack Overflow 和 Python!随时发布您的解决方案作为答案并接受它。祝你一切顺利:)
-
谢谢@meepzh,我现在就这样做:)
-
是的,那是我做错了,谢谢@AnnaNevison
标签: python oop user-interface maya