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 CLOSED
 
Thread Tools Search this Thread Display Modes
Old 01 January 2013   #1
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

kogen
__________________
"Arrogance kills."
 
Old 01 January 2013   #2
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!
 
Old 01 January 2013   #3
Wow, that was quick and amazing, it works like a charm!

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

kogen
__________________
"Arrogance kills."
 
Old 01 January 2013   #4
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.
 
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
CGSociety
Society of Digital Artists
www.cgsociety.org

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

All times are GMT. The time now is 12:47 PM.


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