PDA

View Full Version : If window exists delete?


nottoshabi
11-16-2011, 07:23 PM
Im trying to create a window and then check to see if it exists and delete it. I ran this code


if cmds.window(myWindow, exists=True):
cmds.deleteUI('myWindow')
window = cmds.window( title="myWindow", iconName='myWindow', widthHeight=(500, 150) )
cmds.columnLayout( adjustableColumn=True )
cmds.button( label='close', command=('cmds.deleteUI(\"' + window + '\", window=True)') )
cmds.setParent( '..' )
cmds.showWindow( window )



This gives an error. What am I doing wrong?

BigRoyNL
11-16-2011, 07:35 PM
The myWindow in your window exists line is currently a variable instead of a string. Put quotes/parentheses around it. :)

import maya.cmds as cmds if cmds.window('myWindow', exists=True):

cmds.deleteUI('myWindow')

window = cmds.window( title="myWindow", iconName='myWindow', widthHeight=(500, 150) )

cmds.columnLayout( adjustableColumn=True )

cmds.button( label='close', command=('cmds.deleteUI(\"' + window + '\", window=True)') )

cmds.setParent( '..' )

cmds.showWindow( window )

nottoshabi
11-16-2011, 08:29 PM
Thanks man. I have one more question. On a check box grp how do you pass the command? The code looks like this to create the check box group, but I dont know where to plug in the command.


import maya.cmds as cmds

exampleWindow = cmds.window()
cmds.columnLayout()
cmds.checkBoxGrp( numberOfCheckBoxes=3, label='Three Buttons', labelArray3=['One', 'Two', 'Three'] )
cmds.checkBoxGrp( numberOfCheckBoxes=4, label='Four Buttons', labelArray4=['I', 'II', 'III', 'IV'] )
cmds.showWindow( exampleWindow )


I copyed this straight from the docs since I will be refereing back to this later on.

Azrail
11-17-2011, 09:53 AM
The docs say you have plenty of choices:
changeCommand(cc)/changeCommand#(cc#) - executed when state changes
onCommand(onc)/onCommand#(on#) - executed when a checkbox is turned on
offCommand(ofc)/offCommand#(of#) - reverse to the previous one

so you can either put a global command for the whole group and later on try to get which checkbox is the actual trigger or you can setup different commands for every checkbox and state:

# this applies to all
cmds.checkBoxGrp( ncb=3, l='Three Buttons', la3=['One', 'Two', 'Three'], onc=anyBoxOn, ofc=anyBoxOff)
#this one is per checkbox
cmds.checkBoxGrp( ncb=3, l='Three Buttons', la3=['One', 'Two', 'Three'], on1=box1On, of3=box3Off)

CGTalk Moderation
11-17-2011, 09:53 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.