def CreateMenu():
...
toolUI = fileName.className()
pm.menuItem(label="Tool", command=toolUI.run)Try this.
pm.menuItem(label="Tool", command=lambda _=None: toolUI.run())
What happens is, the menuItem will try and call your function with an argument (the index of the menu item itself? I forget), and this lambda will simply intercept and discard it. You could have written lambda: toolUI.run() but by having the lambda take an argument you allow the call to be repeated via the g key, like it normally would without the lambda.
Another option is to accept the argument in the run() function, something you discard.
Yet another option is to make a second “wrapper” function that you use solely for menus.
def run(_):
return toolUI.run()
pm.menuItem(label="Tool", command=run)
--
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+unsub...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/b5ce5c79-4757-4d48-8229-a03fa0b447ca%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.