我需要Python编程类制作的帮助

时间:2014-07-21 09:21:10

标签: python maya

我编写了一个代码,我想直接从Maya脚本文件夹中访问它。 什么时候我尝试从托盘中访问“poly”或“srfc”。它说“名字没有定义”。 我是python编程的新手,但想要制作这样的工具。请在这方面提供帮助。我甚至想把所有这些包装在一个类中。请帮助那个问题..

import maya.cmds as mc
def win():
    if mc.window("filters", exists = True):
        mc.deleteUI("filters")

    myWindow = mc.window("filters", t= "Tools", s = False, rtf= True, wh = (3, 500))
    mc.rowColumnLayout(nc=20)
    mc.button(l = "mesh", w= 30, h= 18, c = "poly()", bgc = (.3,.3,.3))
    mc.showWindow(myWindow)


def poly():
    currentPanel = mc.getPanel(wf = True)
    if mc.modelEditor(currentPanel, q=True, polymeshes = True) == 1:
        mc.modelEditor(currentPanel, e=True, polymeshes = False)
    elif mc.modelEditor(currentPanel, q=True, polymeshes = True) == 0:
        mc.modelEditor(currentPanel, e=True, polymeshes = True)

1 个答案:

答案 0 :(得分:0)

您将poly()函数称为字符串。只有在与调用win()的代码相同的命名空间中定义poly时,这才有效。将两个函数包装在一个类中会让他们看到对方:

class Tool(object):

     def win(self):
         self.myWindow = mc.window("filters", t= "Tools", s = False, rtf= True, wh = (3, 500))
         mc.rowColumnLayout(nc=20)
         mc.button(l = "mesh", w= 30, h= 18, c = self.poly, bgc = (.3,.3,.3))
         mc.showWindow(self.myWindow)


     def poly(self, ignore):
         # ignore is needed because the button always passes an argument
         currentPanel = mc.getPanel(wf = True)
         if mc.modelEditor(currentPanel, q=True, polymeshes = True) == 1:
              mc.modelEditor(currentPanel, e=True, polymeshes = False)
         elif mc.modelEditor(currentPanel, q=True, polymeshes = True) == 0:
              mc.modelEditor(currentPanel, e=True, polymeshes = True)


t = Tool()
t.win()

你也应该直接引用函数对象poly而不是字符串(注意这里没有引号)

这是reference on the different ways to hook controls up cleanly