Not able to detect the same existing window

121 views
Skip to first unread message

likage

unread,
Sep 17, 2014, 2:22:44 AM9/17/14
to python_in...@googlegroups.com
I have this problem, in which I am trying to check if this particular exists, it will delete the current ui and re-generates a new ui of the same application.
So basically what happens here is that when user imports in a particular format, this ui will then pops up.

So supposedly if the user import in again while the ui is still opened, it will simply kills off the former window and 'reboot' it again.
Thus it keeps printing out "no existence window"

However, as I tried to execute it, it seems to be unable to read the existence of the window, and as a result I have 2 windows instead.
Adding on, this script is part of a plugin execution but I do not think so it affects the window naming, i guess.

Any ideas?


win_name
= "Import chan"
...
...
class CustomNodeTranslator(OpenMayaMPx.MPxFileTranslator):
   
def reader(self, fileObject, optionString, accessMode):
       
if cmds.window(win_name, exists = True):
            cmds
.deleteUI(win_name)
           
print "The application is already opened!"
       
else:
           
print "no existence window"
           
self.initialWindow()
       
...
       
...

   
def initialWindow(self, *args):
       
self.window = cmds.window(title="Import chan", menuBar=True, iconName='.chanFileImport', widthHeight=(335, 221), sizeable=False)
       
...
       
...


Justin Israel

unread,
Sep 17, 2014, 5:37:52 AM9/17/14
to python_in...@googlegroups.com

This code example looks like if the window exists, you delete it and then don't initialize a new one.

Also I would recommend not using a constant for the window name, and instead saving the last window name returned from cmds.window as an instance attribute. That way you can always be sure you are deleting the last window you actually created, even if there was a name clash producing a different name, or Maya decided to rename it. I haven't tested your code, but are you sure Maya isnt replacing that illegal space character in the window name? This would be an ideal reason to save the returned window name, and reuse that on subsequent calls 

--
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_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/8274b1fe-3962-496e-ad9f-33548d835861%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

likage

unread,
Sep 17, 2014, 6:44:44 AM9/17/14
to python_in...@googlegroups.com
Do you mean to say, I should wrote it like this perhaps:

def initialWindow(self, *args):
       
self.window = cmds.window(win_name, menuBar=True, iconName='.chanFileImport', widthHeight=(335, 221), sizeable=False)

And how do I initialize a new one? Cause in my case, the UI will only be prompted if something is imported in followed by the ui prompt

Justin Israel

unread,
Sep 17, 2014, 3:04:41 PM9/17/14
to python_in...@googlegroups.com


On 17/09/2014 10:44 PM, "likage" <dissid...@gmail.com> wrote:
>
> Do you mean to say, I should wrote it like this perhaps:
>
> def initialWindow(self, *args):
>         self.window = cmds.window(win_name, menuBar=True, iconName='.chanFileImport', widthHeight=(335, 221), sizeable=False)
>

Well you would have an initial self.window set in you constructor and always use that as the argument to cmds.window. Then it will give you back the name it actually used. But I am guessing the real problem was the space in the original name and then it giving you back a modified name. So you would never be able to delete it again since you lost the name.

> And how do I initialize a new one? Cause in my case, the UI will only be prompted if something is imported in followed by the ui prompt
>

Not sure what this means. All I know is that your small snippet suggested you only create a window if it didn't already exist. And you don't create a window if it did and you had to delete it.

> --
> 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_m...@googlegroups.com.

> To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/7497217a-956c-463e-836b-d5a0167a792a%40googlegroups.com.

likage

unread,
Sep 17, 2014, 11:07:47 PM9/17/14
to python_in...@googlegroups.com
I tried something like this as a test, but I am prompted with this error where I am unable to create any windows. Or I could create out this TEST window, but when I try to relaunch another one, I got the same error as well
# RuntimeError: Object's name 'TEST' is not unique. #

import maya.cmds as cmds

win_name
= "TEST"
win
= cmds.window(win_name, title = "CHAN Importer", menuBar=True, iconName='.chanFileImport', widthHeight=(335, 221), sizeable=False)
cmds
.showWindow(win)

if cmds.window( win_name, exists = True):

    cmds
.deleteUI(win_name)
   
print "The application is already opened!"
else:

    cmds
.window(win_name)
    cmds
.showWindow(win_name)

damon shelton

unread,
Sep 18, 2014, 12:58:42 AM9/18/14
to python_in...@googlegroups.com
import maya.cmds as cmds

win_name = "TEST"


if cmds.window( win_name, exists = True):
    cmds.deleteUI(win_name)
    print "The application is already opened!"
# vvvvv moved this after the check vvvvvv
win = cmds.window(win_name, title = "CHAN Importer", menuBar=True, iconName='.chanFileImport', widthHeight=(335,221), sizeable=False)
cmds.showWindow(win)

--
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_m...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages