You are seeing that error because you are trying to pass a “non-keyword arg after keyword arg”:
test1 = cmds.menuItem(label='Export using item selection range', test1_func()) test2 = cmds.menuItem(test2_func(), label='Export using time slide range', test2_func()) When you start using keyword args (label=”foo”), you cannot then pass non-keyword args (x, y ,z) In addition, you are actually executing your functions directly instead of trying to pass the reference to them: # calling the function foo(test2_func())# passing a reference foo(test2_func) With those issues aside, you should be able to just pass your function object directly to the command parameter for each menuItem: test1 = cmds.menuItem(label="foo", command=test1_func) On Mon, Oct 13, 2014 at 5:12 PM, likage <[email protected]> wrote: > Is it possible to pass functions into Maya optionMenuGrp (combobox-alike)? > > I have done up a simple UI where I have this combobox (maya cmds not PyQt) > and there are 2 options in it. > However only then I realized that I am unable to 'call' out the function, > nor are there any similar flags to it in its documentation (maybe there is > but I do not know of it yet...) > > I tried out using the following code but I was prompted with errors in the > menuItem statements: > # Error: non-keyword arg after keyword arg > # File "<maya console>", line 9 > # SyntaxError: non-keyword arg after keyword arg # > > > > Then I tried playing around with the placement of test1_func() or > test2_func, it print out the statement as the code is executed but not > executing it anymore if I tried to select the second menu item... > > My code: > import maya.cmds as cmds > > cmds.window(w=150, h=100) > cmds.columnLayout(adjustableColumn=True) > form = cmds.formLayout(numberOfDivisions=100) > > exportSelection = cmds.optionMenuGrp(label=' Selection Options ', > columnWidth=(1, 90)) > test1 = cmds.menuItem(label='Export using item selection range', > test1_func()) > test2 = cmds.menuItem(test2_func(), label='Export using time slide range', > test2_func()) > > startLbl = cmds.text( label='Start' ) > start = cmds.textField(startLbl, w = 100, h = 20) > > endLbl = cmds.text( label='End' ) > end = cmds.textField(endLbl, w = 100, h = 20) > > > cmds.formLayout(form, edit=True, attachForm=[\ > (exportSelection, 'top', 5),\ > (exportSelection, 'left', 5),\ > > (startLbl, 'top', 40),\ > (startLbl, 'left', 7), > (start, 'top', 35),\ > (start, 'left', 45), > > (endLbl, 'top', 60),\ > (endLbl, 'left', 7), > (end, 'top', 60),\ > (end, 'left', 45)]) > > > def test1_func(*args): > print "option 1 is selected" > > def test2_func(*args): > print "option 2 is selected" > > cmds.showWindow() > > > -- > 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 [email protected]. > To view this discussion on the web visit > https://groups.google.com/d/msgid/python_inside_maya/64b66ab8-a585-4b25-8322-f62e431daced%40googlegroups.com > <https://groups.google.com/d/msgid/python_inside_maya/64b66ab8-a585-4b25-8322-f62e431daced%40googlegroups.com?utm_medium=email&utm_source=footer> > . > For more options, visit https://groups.google.com/d/optout. > -- 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 [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA0LGXEQ%3Dj_3T3vtL7ZWvPCfnAqruYVzK7G%2B%2BU7EtKTXEw%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
