Hi, I think you confused setting the value of the window title with giving it an object name. You can see this if you print the value of main_win. What you want to do is give it an explicit object name, and then check for that object name when wanting to delete or reshow it:
WINDOW_NAME = "TEST" def ui(): main_win = cmds.window(WINDOW_NAME, title = "TEST", width = 600, height = 600) ... def main(): if cmds.window(WINDOW_NAME, exists = True): cmds.deleteUI(WINDOW_NAME) print "The application is already opened!" else: ui() If you happen to call ui() multiple times though, in this example, it will end up creating new windows with incremented names. Also, if someone else in another app happened to use that same name and a window already existed, your check would fail to match the right window. What you would have to do is save main_win to a persistent state (either a class or a global) and then check for that. On Tue, Jul 22, 2014 at 9:42 PM, likage <dissidia....@gmail.com> wrote: > Hi all, I am still pretty new to scripting and I have run into some > problems of this simple ui I have wrote. > It is as follows: > > def ui(): > main_win = cmds.window(title = "TEST", width = 600, height = 600) > tab_win = cmds.tabLayout() > > # Tab Layout for Outliner > out_layout = cmds.formLayout("Outliner") > out_panel = cmds.outlinerPanel() > cmds.formLayout(out_layout, edit = True, > attachForm=[ > (out_panel, "top", 0), > (out_panel, "left", 0), > (out_panel, "bottom", 0), > (out_panel, "right", 0) > ]) > > def main(): > if cmds.window("TEST", exists = True): > cmds.deleteUI("TEST") > print "The application is already opened!" > else: > ui() > > However, the main function does not seems to be working as I am still able > to open up more than one of the window in which the first part of the > if-else function does not seems to be 'recognizing' it. > > Any ideas? > > -- > 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 python_inside_maya+unsubscr...@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/python_inside_maya/0a89241a-49ab-4e91-93ba-1a85c7006efd%40googlegroups.com > <https://groups.google.com/d/msgid/python_inside_maya/0a89241a-49ab-4e91-93ba-1a85c7006efd%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 python_inside_maya+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA0j_kA2REX-qJdp9GMxPwz4JUBEW19%3DxGnHvuCT9%3DQvYg%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.