Blog

Maya GUI button commands, how they work, Maya Scripting

Posted by:

I was a bit confused on how Maya GUI button command calls work.

It seems that when I was following tutorials they put the variables from the GUI into the parameters for the call which of course meant that they needed to be in the definition too.

After working with Maya GUI interactions for a while I realized that information that is derived from the GUI need not be included in the parameters because they are derived directly from the GUI interface, so passing them into the function does nothing because that data is pulled in the body of the function.

So:

def applyLimits(applyLimits, pSetLimits, pTranslateXMax, pTranslateXMin):

limits = cmds.checkBox(setLimits, editable = True, query = True, value = True)#Setting derived from the interface

selection = cmds.ls(selection = True)

if(limits == True):

cmds.transformLimits(selection[0], enableTranslationX = [True, True], tx = (-1.5, 1.5), ty=(-1, 1), tz=(-1, 1))
#called with:

cmds.button(command = functools.partial(applyLimits, setLimits, translateXMinField, translateXMaxField ))

 

behaves the same as:

def applyLimits(applyLimits):

limits = cmds.checkBox(setLimits, editable = True, query = True, value = True)#Setting derived from the interface

selection = cmds.ls(selection = True)

if(limits == True):

cmds.transformLimits(selection[0], enableTranslationX = [True, True], tx = (-1.5, 1.5), ty=(-1, 1), tz=(-1, 1))

 

#called with:

cmds.button(command = functools.partial(applyLimits)

 

So I don’t really know why you would ever pass any values into the function since the nature of the GUI is to take user data from the window.

0
  Related Posts
  • No related posts found.

You must be logged in to post a comment.