I'm running into an issue with PyMel where a function I call from a button command isn't reloading correctly after I edit the file. The TestWindow.py example below shows a simple function called TestCommand(self). I call this function from a window button and it prints "Foo". If I change the text to something like "Foo 2", save the file and go back into Maya and click the button I still see "Foo" get printed instead of "Foo 2". If I restart Maya and click the button I see the expected text "Foo 2". In my shelf command listed below I'm reloading TestWindow.py, and if I change the functionality of main() I see those changes reflected correctly when I go back into Maya and click the shelf button. The issue appears to only occur when calling TestCommand(self).
I'm also experiencing a separate issue where I get the error listed at the end of this post when I do the following:
Any ideas? I'm new to Python/PyMel so I may be doing something really stupid here ;)
from pymel.core import *
def main():
#Delete window if it exists
if window("TestWindow", exists=True):
deleteUI("TestWindow")
windowPref( "TestWindow", remove=1 )
winWidth = 175
winHeight = 400
borderStyle = "etchedOut"
testWindowObject = window("TestWindow",title="Test Window")
columnLayout("MainColumn", width=winWidth, adj=1, columnAttach=("both", 5))
frameLayout("Frame", parent="MainColumn", collapsable=1, collapse=0)
rowColumnLayout(parent="Frame",numberOfColumns=2, columnAlign=([1, "left"], [2, "left"]))
button(label="Test Command", height=50, width=100, command=TestCommand)
#Dock Control
allowedAreas = ['right', 'left']
#If dockControl exists, show it and bring it to the front
if dockControl('TestWindowDock', query=True, exists=True):
dockControl('TestWindowDock', edit=True, visible=True, r=True)
else:
#dockControl does not exist, create it (this will show it).
dockControl('TestWindowDock', label="Test Window", area='right', content="TestWindow", allowedArea=allowedAreas)
def TestCommand(self):
print "Foo"
import TestWindow
reload (TestWindow)
TestWindow.main()
# Error: windowPref: Object 'TestWindow' not found.
# Traceback (most recent call last):
# File "<maya console>", line 3, in <module>
# File "C:/Users/brad/Documents/maya/2014-x64/scripts\TestWindow.py", line 7, in main
# windowPref( "TestWindow", remove=1 )
# File "C:\Program Files\Autodesk\Maya2014\Python\lib\site-packages\pymel\internal\pmcmds.py", line 134, in wrappedCmd
# res = new_cmd(*new_args, **new_kwargs)
# RuntimeError: windowPref: Object 'TestWindow' not found. #