Reputation: 841
I need to know how to properly close this window after the user presses enter.
txtA = cmds.textField(w = 345, h = 28, text = item, ec = renFc, aie = True)
That calls to this function upon pressing enter: def ren():
I tried putting in cmds.deleteUI(renUI)
into the refFc function but that makes it crash.
Here is the full code:
import maya.cmds as cmds
'''
Rename popup box for outliner - copy/paste this script into a hotkey field in the hotkey editor
'''
class ReUI():
def __init__(self):
renUI = 'renUI'
if cmds.window(renUI, exists = True):
cmds.deleteUI(renUI)
renUI = cmds.window(renUI, t = 'JT Rename UI', sizeable = True, tb = True, mnb = False, mxb = False, menuBar = True, tlb = False, nm = 5)
form = cmds.formLayout()
rowA = cmds.rowColumnLayout(w = 350, h = 30)
item = cmds.ls(os = True)[0]
def ren():
def renFc(self):
print 'yes'
tval = cmds.textField(txtA, text = True, q = True)
cmds.rename(item, tval)
txtA = cmds.textField(w = 345, h = 28, text = item, ec = renFc, aie = True)
ren()
cmds.showWindow(renUI)
r = ReUI()
Upvotes: 0
Views: 7012
Reputation: 284
You're running into a teensy little bug I'm afraid.. for more details check out the thread here: http://forums.cgsociety.org/archive/index.php/t-1000345.html .
Just incase the link dies - basically, in 2011/2012 it looks like there's an issue where hitting enter and invoking deleteUI deletes the object before Maya/QT have finished cleanup, and thus giving you a segfault type situation.
There's a sort of a workaround for it though, you want to import the maya.utils
package and use the executeDeferred()
command (see: http://download.autodesk.com/global/docs/maya2013/en_us/index.html?url=files/Python_Python_in_Maya.htm,topicNumber=d30e725143 ) around your deleteUI call. Check in 2013 to see if this is fixed perhaps?
I've just hacked your code a little to insert the relevant line to demo it works, but it's heavily dependent on that string 'renUI'
(oh, and that function ren() isn't reaaaly helping.. you can get rid of it and unindent that block.)
import maya.utils # you need this line!
class ReUI():
def __init__(self):
renUI = 'renUI'
if cmds.window(renUI, exists = True):
cmds.deleteUI(renUI)
renUI = cmds.window(renUI, t = 'JT Rename UI', sizeable = True, tb = True, mnb = False, mxb = False, menuBar = True, tlb = False, nm = 5)
form = cmds.formLayout()
rowA = cmds.rowColumnLayout(w = 350, h = 30)
item = cmds.ls(os = True)[0]
def ren():
def renFc(self):
print 'yes'
tval = cmds.textField(txtA, text = True, q = True)
cmds.rename(item, tval)
maya.utils.executeDeferred("cmds.deleteUI('renUI')") # and this one!
txtA = cmds.textField(w = 345, h = 28, text = item, ec = renFc, aie = True)
ren()
cmds.showWindow(renUI)
r = ReUI()
Upvotes: 2