5 comments

User ratings
5 star:
 
(2)
4 star:
 
(0)
3 star:
 
(0)
2 star:
 
(0)
1 star:
 
(0)
2 ratings
Average user rating:
5.0 stars
(5.0)
Comment from: Bård [Visitor]
Bård
5 stars

This helped me a lot.

I think that you really don’t need to store the func in an array. It’s better to let the UIElements be a class variable instead of a static (add self. prefix and put on top in __init__). Then you can pass func directly to the command parameter when creating buttons.

Thanks for sharing!

12/11/08 @ 12:58 am
Comment from: o.z [Member]
o.z

Thank you for your comment.
The UIElements variable is a class variable (I had some formatting issues in this post, hope now it’s clearer.) However, it is not necessary to use the UIElements var, I only like to use in case I need to manipulate those UI elements later.
As for storing the event functions in an array (UIEventHandlers), this is necessary, because, as I explain in the post, if you don’t those functions will be garbage collected as soon as the creation function is done, and the event commands won’t work.

o

12/11/08 @ 06:03 am
Comment from: Kiaran Ritchie [Visitor]
Kiaran Ritchie
5 stars

Hey Ofer!!

I went Googling to see if anyone else had hit this little snag before. Low and behold my old friend has already solved it. Thanks a lot for putting this together!

Hope you’re still liking IM Digital. Jas and I are freezing up here in Canada-duh ;) Keep up the good work.

-Kiaran

03/01/09 @ 02:55 pm
Comment from: matt [Visitor]
matt

the python-in-maya group has an elegant solution i stumbled across today; use partial. lets you skip all sorts of class trickery (insert indents where appropiate, can’t html format comments…):

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))

11/09/09 @ 10:37 pm
Comment from: o.z [Member]
o.z

Thanks for sharing this Matt!
I’ll have to test it sometime.

11/10/09 @ 03:41 pm


Form is loading...