I guess you can use a lambda also which I didnt know Eric. I gave you a seventh solution to put on your site.
Ryan Character TD www.rtrowbridge.com/blog NaughtyDog Inc. On Jan 21, 1:25 pm, ryant <[email protected]> wrote: > I have not seen it posted so I thought I would mention there are other > options for passing callable functions as well. You can use a partial > function to create a callable function to a command. > > Example: > > from functools import partial > > def myfunc(does, some=1, stuff='test'): > print does > print some > print stuff > > part = partial(myfunc, 10, some=10, stuff='ten') > part() > > # Result # > 10 > 10 > ten > # End Result # > > By using the partial function you can pass a button a partial function > with whatever arguments you need to pass: > > self.button = mc.button(label="Close Window", command=partial > (self.buttonCmd, 'pass', my='arguments', into='something') > > Ryan > Character TDwww.rtrowbridge.com/blog > NaughtyDog Inc. > > On Jan 21, 8:34 am, AK Eric <[email protected]> wrote: > > > Just to add a bit more: The below block of code is one I just stick > > on my shelf, and drag it down to the script editor any time I want to > > start a new window. Like Seth, I just modified it to add a button to > > close the window as well. > > > The finicky bit are button commands, or any command executed from a > > control: They only expect to execute a string, or a function *name*, > > without args. Things get more complex if you want want to pass args > > from your button to your command/method, and like Seth showed you can > > use *args to help capture them on the method side. Furthermore, even > > if you don't want to capture args from your command execution, Maya > > likes to pass out a default value upon execution which your command > > must be able to intercept, again, via *args. If you're interested in > > the specifics of that, I have a couple tutorials\notes > > here:http://mayamel.tiddlyspot.com/#[[Positional%20args%20in%20Python%20authored%20UI%27s]]http://mayamel.tiddlyspot.com/#[[Executing%20external%20functions%20via%20UI%27s%20authord%20in%20Python]] > > Which basically show how to use lambda or functools.partial > > > __version__ = '0.1' > > > import maya.cmds as mc > > > class App(object): > > def __init__(self): > > self.name = "pyWin" > > self.title = "Python Window" > > > if mc.window(self.name, exists=True): > > mc.deleteUI(self.name) > > > self.window = mc.window(self.name, title=self.title+" - v" > > +__version__, resizeToFitChildren=True) > > self.rootLayout = mc.columnLayout(adjustableColumn=True, > > columnAttach=('both', 5)) > > > self.button = mc.button(label="Close Window", > > command=self.buttonCmd) > > > mc.showWindow() > > > def buttonCmd(self, *args): > > mc.deleteUI(self.name) > > > App() > > > On Jan 20, 9:48 pm, Chris Mills <[email protected]> wrote: > > > > Thank you Seth! > > > > Kind regards, > > > Chris > > > > Lizard Lounge Graphics, LTD. > > > Wellington, NZhttp://lizardlounge.com > > > > Int'l: +644-977-5400 / +642-174-8770 > > > NZ local: 04-977-5400 / 021-748-770 > > > > Seth Gibson wrote: > > > > Try this. It's not very elegant and there are probably better > > > > architectural decisions you could make, but it should get you pointed in > > > > the right direction: > >
-- http://groups.google.com/group/python_inside_maya
