Maya Python Button Callback

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

Thread Tools Search this Thread Display Modes
  01 January 2013
Maya Python Button Callback

Hello guys,

I'm stuck in the classic "all the buttons in my array print the same values" situation. And reading through the web just pointed me to "Pymel" which I don't want to use because I have to build the tool which is shared between different studios and it might not be guaranteed that all of them will use pymel. Is there another way to pass the specific value to a button with python?
Imagine this code-extract:

for lvi in range(0, 10):
button = cmds.button('button_'+str(lvi), label='Update', width=100, height = 50, enable=True, command = lambda *args: printcurrentvalue(lvi))

Again, this is just part of the code, but the result that is printed when I click the button is always 10, which is logical, because there is no callback, but how can I add something like this in Maya to a button?

Thanks in adavance

"Arrogance kills."
  01 January 2013
I have been using this in the past

 class Callback(object): 
 		def __init__(self, func, *args, **kwargs): 
 				self.func = func 
 				self.args = args 
 				self.kwargs = kwargs
 		def __call__(self, *args): 
 				return self.func( *self.args, **self.kwargs )

and this to call it
mc.menuItem(l='Remove set from scene', c=Callback(self.stripObject, obj, member, 1, selButton))

Hope it helps!
  01 January 2013
Wow, that was quick and amazing, it works like a charm!

Thanks a lot, looks like I can go and do some sports today

"Arrogance kills."
  01 January 2013
Thread automatically closed

This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
CGTalk Policy/Legalities
Note that as CGTalk Members, you agree to the terms and conditions of using this website.
Thread Closed share thread

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Society of Digital Artists

Powered by vBulletin
Copyright 2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump

All times are GMT. The time now is 07:39 PM.

Powered by vBulletin
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.