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.
ShareDEC
2017
About the Author:
I RUN this joint! And I am a digital artist. BFA from the University of Colorado with an emphasis in 3D Animation. I worked in medical animation for some time. I then narrowly escaped with an only partially crushed spirit. Since then I have been expanding my skill set, reaching out into custom coding, game and app development.