NameError:file <maya console =“”>第1行:未定义名称“pasteTheseKeys”

时间:2015-05-08 07:04:42

标签: python maya nameerror

我无法弄清楚如何让我的类方法pasteTheseKeys()工作。我试过了 传递(自我)作为一个参数,但我得到一个错误,我在2个参数传递给我,它看起来我传给我自己。我删除了自我论证,现在收到了这条消息。

# Animation Copy Tool
# Bakari Holmes 5/7/2015
# This is designed to copy and existing animation
# from one rig to another and make the process easier
# with a simple UI

import maya.cmds as mc
import functools
import maya.mel as mm
import pprint

class AnimCopyWindow(object):
    #@classmethod
    def showUI(cls):
        win = cls()
        win.create()
        return win
    def __init__(self):
        self.window = "Animation Copy Tool"
        self.title = "Animation Copier"
        self.size = (546,350)
    def pasteTheseKeys():
        self.offsetVal = mc.intFieldGrp(self.int_offset, q=True, value1=True)
        self.selObj_pasteKeys = mc.ls(sl=True)

        for objectQuant in self.selObj_pasteKeys:
            print objectQuant
            self.ct = mc.currentTime(query = True)
            self.t = self.ct + self.offsetVal
            mc.currentTime(self.t)
           # mc.selectKey(selObj_pasteKeys[objectQuant])
            mc.pasteKey(time=(self.t,self.t), f=(1.0,1.0), option="merge", copies=1, to=0, fo=0, vo=0)
    def create(self):
        # check to see if window exists already
        if mc.window(self.window,exists=True): 
            mc.deleteUI(self.window,window=True)

        self.window = mc.window(self.window, title=self.title,widthHeight=self.size,menuBar=True)
        self.copyAnim = mc.window(title="Transfer Animation Tool", backgroundColor=[0.3,0.3,0.3],sizeable=False,resizeToFitChildren=True)
        #set the layout for UI
        mc.columnLayout(adjustableColumn=True)
        self.tx_src = mc.textFieldGrp(label="Source Object", editable=False, text=sel[0])
        self.int_offset = mc.intFieldGrp(label="Frame Offset Amount", value1=0)
        #add paste animation button
        self.btn1 = mc.button(label="PASTE ANIMATION", command="pasteTheseKeys()", bgc=[0.1,0.1,0.5])

        #add close button window
        self.btn2 = mc.button(label="CLOSE WINDOW", command="mc.deleteUI", bgc=[0.2,0.2,0.2])


        mc.showWindow()


#copyAnim="copyAnim"

#store selected object info
sel = mc.ls(selection=True)

if (len(sel) != 1):
    mm.eval("warning Must select one animated object;")

else:
    mc.copyKey()
    win = AnimCopyWindow()
    win.create()

    pprint.pprint(channels())

1 个答案:

答案 0 :(得分:1)

需要使用自身参数定义函数pasteTheseKeys()以在函数外部使用。如果不需要接受自我,请使用staticmethod装饰。

@staticmethod
def pasteTheseKeys():
    ...