Mr.Justin Israel Thank you very much for your perfect answer!!
2015年7月1日水曜日 19時25分23秒 UTC+9 Justin Israel: > > This is an issue concerning scope. If you set a command using a string, > then it is going to expect these symbols to be available in the global > scope. But you are declaring inner functions that disappear after the > dual() scope ends. There is no closure happening here. > > My initial question is, do you need to use an inner function as your > callback? Also, do you need to be using the string form of defining a > command? > > Ideally you would always pass a callable object as your command so that > you don't have to deal with scope problems when the string is evaluated > later on. > > If you must use inner functions for your solution, then you should create > a proper closure, and then pass a callable: > > def dual(): > > def saves(): > print "hello" > > def load(): > print "bye" > > def callback(*args): > saves() > load() > > with pm.window(width=150): > pm.columnLayout(adj=True) > pm.button(label="Button 1", command=callback) > > > Justin > > > On Wed, Jul 1, 2015 at 8:43 PM kurashima <[email protected] <javascript:>> > wrote: > >> It's a question about pymel. >> If a button is pressed, please tell me the way to call saves and load. >> ↓It was written like mel, but the following error goes out. >> # Error: NameError: file <maya console> line 1: name 'saves' is not >> defined # >> >> def dual(): >> def saves(): >> print 'hello.' >> >> def load(): >> print 'bye.' >> >> with pm.window( width=150 ): >> pm.columnLayout( adjustableColumn=True ) >> pm.button(label='Button 1', command='saves();load()') >> >> dual() >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Python Programming for Autodesk Maya" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to [email protected] <javascript:>. >> To view this discussion on the web visit >> https://groups.google.com/d/msgid/python_inside_maya/80ef3762-0d7b-4852-9118-061eebadb2be%40googlegroups.com >> >> <https://groups.google.com/d/msgid/python_inside_maya/80ef3762-0d7b-4852-9118-061eebadb2be%40googlegroups.com?utm_medium=email&utm_source=footer> >> . >> For more options, visit https://groups.google.com/d/optout. >> > -- You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/ec46ea40-a381-4055-aba5-741b90766622%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
