the 'partial' trick doesn't work for you?

import maya.cmds as cmds
from functools import partial

def myFunc(set,*args):
  print 'you chose ', set

occSets = ['A','B','C','D']
for i in occSets():
   cmds.menuItem(l=i, c=partial(myFunc,i))



On Wed, Jan 12, 2011 at 6:08 AM, PixelMuncher <[email protected]> wrote:
> Thanks Oren:
> I'm not familiar w/using classes, but I did try your suggestion.
> Assuming that I unwrapped your Class correctly:
> class Callback(object):
>    def __init__(self, func, *args, **kwargs):
>        self.func= func
>        self.args = args
>        self.kwargs = kwargs
>    def __call__(self):
>        return self.func( *self.args, **self.kwargs )
>
> When run the script, I get this error:
> #   File "C:\Documents and Settings\Administrator\My Documents\maya
> \myScripts\panelContentChange.py", line 125
> #     cmds.button(l='Sel',w=20, command =
> *Callback(selectMe,fullName)* )
> #                                         ^
> # SyntaxError: invalid syntax #
>
> On Jan 11, 12:29 pm, Ofer Koren <[email protected]> wrote:
>> If you have pymel you should use the Callback class implemented there. It
>> has better handling of errors and undos and whatnot.
>> If you don't have pymel you could just define this simple version and use
>> it:
>>
>> class Callback(object): def __init__(self, func, *args, **kwargs): self.func
>> = func self.args = args self.kwargs = kwargs def __call__(self): return
>> self.func( *self.args, **self.kwargs )
>>
>> def fillUDPanel():
>>        global sliderContainer
>>        sel=cmds.ls(sl=1)
>>        if len(sel) == 0:
>>                mel.error("You must have an object selected!")
>>
>>        for obj in sel:
>>                attributes=cmds.listAttr(obj,   ud=1)
>>                if not  attributes :
>>                        print obj,'doesn\'t have obj user-defined atttrs.'
>>                        continue
>>                cmds.setParent('frameBegin')
>>                sliderContainer
>> = cmds.frameLayout('sliderFrame',collapsable=1,l=obj  ,bs="etchedOut")
>>                cmds.rowColumnLayout('sliderPanel', nc = 2, columnWidth=[(2,
>> 40)])
>>                for attr in attributes:
>>                        fullName=(str(obj) + "." + str(attr))
>>                        cmds.attrFieldSliderGrp(cw=(1,
>> 90),at=fullName,cat=(1, 'left', 10))
>>                        cmds.button(l='Sel',w=20, command = 
>> *Callback(selectMe,
>> fullName)* )
>>
>> - Oferwww.mrbroken.com
>>
>> On Tue, Jan 11, 2011 at 7:55 PM, PixelMuncher <[email protected]> wrote:
>> > and this is the command I'm trying to assign to the buttons:
>> > def selectMe(who):
>> >    print 'selectMe:',who
>> >    cmds.select (who)
>>
>> > --
>> >http://groups.google.com/group/python_inside_maya
>>
>>
>
> --
> http://groups.google.com/group/python_inside_maya
>

-- 
http://groups.google.com/group/python_inside_maya

Reply via email to