Reputation: 11
I have a python function here that is supposed to rename object in maya. But when the window showed up and i click the 'rename' button, nothing changed. not even bringing new window. please help
def renameObject():
a = cmds.ls(sl=True)
txt = cmds.textField('txtName', q=True, tx=True)
cmds.rename('a', txt)
cmds.confirmDialog(icn='information', message='Done!')
cmds.showWindow()
return
cmds.window(title='Rename Object')
cmds.columnLayout(adj=1)
cmds.text(label= 'Insert Name', w=300, h=30)
cmds.separator()
cmds.textField('txtName')
cmds.button(label='Rename', width=300, c=lambda*args:'renameObject()')
cmds.showWindow()
Upvotes: 0
Views: 1756
Reputation: 2512
def renameObject(*args):
a = cmds.ls(sl=True)
txt = cmds.textField(txt_field , q=True, tx=True)
cmds.rename(a[0], txt)
cmds.confirmDialog(icn='information', message='Done!')
cmds.showWindow()
cmds.window(title='Rename Object')
cmds.columnLayout(adj=1)
cmds.text(label= 'Insert Name', w=300, h=30)
cmds.separator()
txt_field = cmds.textField('txtName')
cmds.button(label='Rename', width=300, c=renameObject)
cmds.showWindow()
I've corrected your code, it shuold work when ran but there is lots of mistakes in your code, Haggi Krey has pointed lots of them. If you want to dive in UI design, you should look at partial module from functools. There is lots of examples here in Stack
Upvotes: 0
Reputation: 1978
Two reasons:
And the confirmDialog() does not need a cmds.showWindow(), it works without.
Upvotes: 1