【发布时间】:2019-06-18 10:00:11
【问题描述】:
我是使用 Maya 编写 Python 脚本的新手,我想自动加载我创建的插件,以在 Maya 主窗口中显示自定义菜单。单击菜单项时,它会显示一个使用我创建的函数的窗口。所以问题是:当我在 Maya 界面中简单地运行我的代码时,它运行正常,但是当我将我的代码放入 python 文件并自动加载它时,它每次都会显示一个不同的错误: 有时它会在打开 Maya 时第一次加载菜单项时显示此错误:
# Error: NameError: file <maya console> line 1: name 'createUI' is not defined #
而且有时会显示这个错误:
// Warning: file: C:/Program Files/Autodesk/MAYA20185/Maya2018/scripts/others/pluginWin.mel line 290: No initializePlugin() or initializePlugin2() function
//
// Error: file: C:/Program Files/Autodesk/MAYA20185/Maya2018/scripts/others/pluginWin.mel line 290: (userInterface) //
这是我的代码:userInterface.py
import maya.cmds as cmds
import functools
import pymel.core as pm
def createUI(pWindowTitle):
windowID = 'myWindowID'
if cmds.window(windowID, exists=True):
cmds.deleteUI(windowID)
cmds.window(windowID, title=pWindowTitle, sizeable=False, resizeToFitChildren=True)
cmds.rowColumnLayout(numberOfColumns=3, columnWidth=[(1,75), (2,60), (3,60) ], columnOffset=[(1,'right',3)])
cmds.text(label='Time Range:')
startTimeField = cmds.intField(value=cmds.playbackOptions(q=True, minTime=True))
endTimeField = cmds.intField(value=cmds.playbackOptions(q=True, maxTime=True))
cmds.text( label='Attribute:' )
targetAttributeField = cmds.textField( text='rotateY' )
cmds.separator( h=10, style='none' )
cmds.separator( h=10, style='none' )
cmds.separator( h=10, style='none' )
cmds.separator( h=10, style='none' )
cmds.separator( h=10, style='none' )
def cancelCallback(*pArgs):
if cmds.window(windowID, exists=True ):
cmds.deleteUI(windowID)
cmds.button(label='Cancel',command=cancelCallback)
cmds.showWindow()
def keyFullRotation(pObjectName, pStartTime, pEndTime, pTargetAttribute):
cmds.cutKey( pObjectName, time=(pStartTime, pEndTime), attribute=pTargetAttribute)
cmds.setKeyframe( pObjectName, time=pStartTime, attribute=pTargetAttribute, value=0)
cmds.setKeyframe( pObjectName, time=pEndTime, attribute=pTargetAttribute, value=360)
cmds.selectKey( pObjectName, time=(pStartTime, pEndTime), attribute=pTargetAttribute, keyframe=True)
cmds.keyTangent( inTangentType='linear', outTangentType='linear' )
MainMayaWindow = pm.language.melGlobals['gMainWindow']
customMenu = pm.menu('TestMenu', parent=MainMayaWindow)
pm.menuItem(label="menu item 'hihi'", command="createUI('My Title')", parent=customMenu)
【问题讨论】: