It's because you delete the window but leave behind the DockWindow. It doesn't really make sense to try and bring the dock window forward if it exists, since the old one will no longer have a window content (it was deleted). You use a fixed DockWindow name each time, so you end up with duplicates and the window in the wrong one.
Try something like this: http://pastebin.com/N539E4gZ It deletes the DockWindow, which will delete all child objects (including the original window). You kind of either have to do one or the other, where if the dock/window exists you just show the existing one, or you delete them and recreate them. On Sun, Jun 15, 2014 at 7:33 PM, Bradley Newman <[email protected]> wrote: > 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: > > 1. Start Maya. > 2. Click shelf button to open window. > 3. Change TestCommand() print text from "Foo" to "Foo 2" and save. > 4. Go back to Maya and click shelf button again > > Any ideas? I'm new to Python/PyMel so I may be doing something really > stupid here ;) > > *TestWindow.py:* > 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" > > *Shelf Command:* > > import TestWindow > > reload (TestWindow) > > TestWindow.main() > > *Error:* > 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. # > > -- > You received this message because you are subscribed to the Google Groups > "Python Programming for Autodesk Maya" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To view this discussion on the web visit > https://groups.google.com/d/msgid/python_inside_maya/84012ece-5e97-4ad8-aba9-831dd5592537%40googlegroups.com > <https://groups.google.com/d/msgid/python_inside_maya/84012ece-5e97-4ad8-aba9-831dd5592537%40googlegroups.com?utm_medium=email&utm_source=footer> > . > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA3P2A6kcCjYO1quvYtC7qf6WPf_%3DC2hosDkua0ZQfr9BA%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
