Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>It's because the resolution of your <code>c</code> arguments to <code>cmds.button()</code> are happening in another namespace. It appears there are several ways to solve it, but I recommend following the more Pythonic way:</p> <pre><code>from functools import partial self.btnA = cmds.button( label='Press Me - External Func', c=partial(outsideFunc, dic)) self.btnb = cmds.button( label='Populate more items',c=populateDic) </code></pre> <p>For button A, I'm using <a href="http://docs.python.org/library/functools.html#functools.partial" rel="nofollow"><code>partial</code></a> to help pass <code>dic</code> to <code>outsideFunc</code>, so that the resultant function produced by partial doesn't require any arguments (it's been pre-loaded with the <code>dic</code> argument).</p> <p>For button B, this is unnecessary, as it doesn't take any arguments. So we just give it the name of the function to call. Note the lack of quotes. Python will resolve this in the correct namespace, and will work as expected.</p> <p>BTW, this page appears to be helpful and talks about command callbacks: <a href="http://www.luma-pictures.com/tools/pymel/docs/1.0/ui.html" rel="nofollow">http://www.luma-pictures.com/tools/pymel/docs/1.0/ui.html</a></p> <p>UPDATE: Buttons pass an argument to their callback, so you need to wrap it:</p> <pre><code>from functools import partial self.btnA = cmds.button( label='Press Me - External Func', c=lambda arg: outsideFunc(dic)) self.btnb = cmds.button( label='Populate more items',c=lambda arg: populateDic()) </code></pre> <p>This creates a couple of anonymous functions that throw away the argument (since you don't need it).</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload