What arguments do I send a function being called by a button in python?
Posted
by
Jared
on Stack Overflow
See other posts from Stack Overflow
or by Jared
Published on 2011-06-29T04:24:31Z
Indexed on
2011/06/29
8:22 UTC
Read the original article
Hit count: 288
I have a UI, in that UI is 4 text fields and 1 int field, then I have a function that calls to another function based on what's inside of the text fields, this function has (self, *args). My function that is being called to takes five arguments and I don't know what to put in it to make it actually work with my UI because python button's send an argument of their own.
I have tried self and *args, but it doesn't work.
Here is my code, didn't include most of the UI code since it is self explanatory:
def crBC(self, IKJoint, FKJoint, bindJoint, xQuan, switch):
'''
You should have a controller with an attribute 'ikFkBlend' - The name can be changed after the script executes.
Controller should contain an enum - FK/DYN(0), IK(1).
Specify the IK joint, then either the dynamic or FK joint, then the bind joint. Then a quantity of joints to pass
through and connect. Tested currently on 600 joints (200 x 3), executed in less than a second.
Returns nothing.
Please open your script editor for details.
'''
import itertools
# gets children joints of the selected joint
chHipIK = cmds.listRelatives(IKJoint, ad = True, type = 'joint')
chHipFK = cmds.listRelatives(FKJoint, ad = True, type = 'joint')
chHipBind = cmds.listRelatives(bindJoint, ad = True, type = 'joint')
# list is built backwards, this reverses the list
chHipIK.reverse()
chHipFK.reverse()
chHipBind.reverse()
# appends the initial joint to the list
chHipIK.append(IKJoint)
chHipFK.append(FKJoint)
chHipBind.append(bindJoint)
# puts the last joint at the start of the list because the initial joint
# was added to the end
chHipIK.insert(0, chHipIK.pop())
chHipFK.insert(0, chHipFK.pop())
chHipBind.insert(0, chHipBind.pop())
# pops off the remaining joints in the list the user does not wish to be blended
chHipBind[xQuan:] = []
chHipIK[xQuan:] = []
chHipFK[xQuan:] = []
# goes through the bind joints, makes a blend colors for each one, connects
# the switch to the blender
for a, b, c in itertools.izip(chHipBind, chHipIK, chHipFK):
rotBC = cmds.shadingNode('blendColors', asUtility = True, n = a + 'rotate_BC')
tranBC = cmds.shadingNode('blendColors', asUtility = True, n = a + 'tran_BC')
scaleBC = cmds.shadingNode('blendColors', asUtility = True, n = a + 'scale_BC')
cmds.connectAttr(switch + '.ikFkSwitch', rotBC + '.blender')
cmds.connectAttr(switch + '.ikFkSwitch', tranBC + '.blender')
cmds.connectAttr(switch + '.ikFkSwitch', scaleBC + '.blender')
# goes through the ik joints, connects to the blend colors
cmds.connectAttr(b + '.rotate', rotBC + '.color1', force = True)
cmds.connectAttr(b + '.translate', tranBC + '.color1', force = True)
cmds.connectAttr(b + '.scale', scaleBC + '.color1', force = True)
# connects FK joints to the blend colors
cmds.connectAttr(c + '.rotate', rotBC + '.color2')
cmds.connectAttr(c + '.translate', tranBC + '.color2')
cmds.connectAttr(c + '.scale', scaleBC + '.color2')
# connects blend colors to bind joints
cmds.connectAttr(rotBC + '.output', a + '.rotate')
cmds.connectAttr(tranBC + '.output', a + '.translate')
cmds.connectAttr(scaleBC + '.output', a + '.scale')
-------------------
def execCrBC(self, *args):
g.crBC(cmds.textField(self.ikJBC, q = True, tx = True), cmds.textField(self.fkJBC, q = True, tx = True), cmds.textField(self.bindJBC, q = True, tx = True), cmds.intField(self.bQBC, q = True, v = True), cmds.textField(self.sCBC, q = True, tx = True))
-------------------
self.bQBC = cmds.intField()
cmds.text(l = '')
self.sCBC = cmds.textField()
cmds.text(l = '')
cmds.button(l = 'Help Docs', c = self.crBC.__doc__)
cmds.setParent('..')
cmds.button(l = 'Create', c = self.execCrBC)
Here is the code causing the problem as requested:
import maya.cmds as cmds
import jtRigUI.createDummyRig as dum
import jtRigUI.createSkeleton as sk
import jtRigUI.generalUtilities as gu
import jtRigUI.createLegRig as lr
import jtRigUI.createArmRig as ar
class RUI(dum.Dict, dum.Dummy, sk.Skel, sk.FiSkel, lr.LeanLocs, lr.LegRig, ar.ArmRig, gu.Gutils):
def __init__(self, charNameUI, gScaleUI, fingButtonGrp, thumbCheckBox, spineButtonGrp, neckButtonGrp, ikJBC, fkJBC, bindJBC, bQBC, sCBC):
rigUI = 'rigUI'
if cmds.window(rigUI, exists = True):
cmds.deleteUI(rigUI)
rigUI = cmds.window(rigUI, t = 'JT Rigging UI', sizeable = False, tb = True, mnb = False, mxb = False, menuBar = True, tlb = True, nm = 5)
form = cmds.formLayout()
tabs = cmds.tabLayout(innerMarginWidth = 1, innerMarginHeight = 1)
rigUIMenu = cmds.menu('Help', hm = True)
aboutMenu = cmds.menuItem('about')
cmds.popupMenu('about', button = 1)
deleteUIMenu = cmds.menu('Delete', hm = True)
cmds.menuItem('dummySkeleton')
cmds.formLayout(form, edit = True, attachForm = ((tabs, 'top', 0), (tabs, 'left', 0), (tabs, 'bottom', 0), (tabs, 'right', 0)), w = 30)
tab1 = cmds.rowColumnLayout('Dummy')
#cmds.columnLayout(rowSpacing = 10)
#cmds.setParent('..')
cmds.frameLayout(l = 'A: Dummy Skeleton Setup', w = 400)
self.charNameUI = cmds.textFieldGrp (label="Optional Character Name:", ann="Insert a name for the character or leave empty.", tx = '', w = 1)
fingJUI = cmds.frameLayout(l = 'B: Number of Fingers', w = 10)
cmds.text('\n', h = 5)
self.fingButtonGrp = cmds.radioButtonGrp('fingRadio', p = fingJUI, l = 'Fingers: ', sl = 4, w = 1, numberOfRadioButtons = 4, labelArray4 = ['One', 'Two', 'Three', 'Four'], ct2 = ('left', 'left'), cw5 = [60,60,60,60,60])
self.thumbCheckBox = cmds.checkBoxGrp(l = 'Thumb: ', v1 = True)
cmds.text('\n', h = 5)
spineJUI = cmds.frameLayout(l = 'C: Number of Spine Joints')
cmds.text('\n', h = 5)
self.spineButtonGrp = cmds.radioButtonGrp('spineRadio', p = spineJUI, l = 'Spine Joints: ', sl = 2, w = 1, numberOfRadioButtons = 3, labelArray3 = ['Three', 'Five', 'Ten'], ct2 = ('left', 'left'), cw4 = [95,95,95,95])
cmds.text('\n', h = 5)
neckJUI = cmds.frameLayout(l = 'D: Number of Neck Joints')
cmds.text('\n', h = 5)
self.neckButtonGrp = cmds.radioButtonGrp('neckRadio', p = neckJUI, l = 'Neck Joints: ', sl = 0, w = 1, numberOfRadioButtons = 3, labelArray3 = ['Two', 'Three', 'Four'], ct2 = ('left', 'left'), cw4 = [95,95,95,95])
cmds.text('\n', h = 5)
cmds.setParent('..')
cmds.setParent('..')
cmds.setParent('..')
cmds.frameLayout('E: Creation')
cmds.text('SAVE FIRST: CAN NOT UNDO', bgc = (0.2,0.2,0.2))
cmds.button(l = '\nCreate Dummy Skeleton\n', c = self.build) # also have it make char name field grey
cmds.text('Elbows and Knees must have bend.', bgc = (0.2,0.2,0.2))
cmds.columnLayout()
cmds.setParent('..')
cmds.setParent('..')
cmds.setParent('..')
cmds.setParent('..')
tab2 = cmds.rowColumnLayout('Skeleton')
cmds.columnLayout(columnAttach = ('both', 5), rowSpacing = 10, columnWidth = 150)
cmds.setParent('..')
cmds.frameLayout(l = 'A: Skeleton Setup')
cmds.text('SAVE FIRST: CAN NOT UNDO', bgc = (0.2,0.2,0.2))
cmds.button(l = '\nConvert to Skeleton - Orient - Set LRA\n', c = self.buildSkel)
self.gScaleUI = cmds.textFieldGrp (label="Scale Multiplier:", ann="Scale multipler of Character: basis for all further base controllers", tx = '1.0', w = 1, ed = False, en = False, visible = True)
cmds.frameLayout('B: Manual Orientation')
cmds.text('You must manually check finger, thumb, leg, foot orientation specifically.\nConfirm rest of joints.\nSpine: X aim, Y point backwards from spine, Z to the side.\nFingers: X is aim, Y points upwards, Z to the side - Spread on Y, curl on Z.\nFoot: Pivots on Y, rolls on Z, leans on X.')
cmds.columnLayout()
cmds.setParent('..')
cmds.frameLayout('C: Finalize Creation of Skeleton')
cmds.button(l = '\nFinalize Skeleton\n', c = self.finishS)
cmds.setParent('..')
cmds.setParent('..')
cmds.setParent('..')
cmds.setParent('..')
tab3 = cmds.rowColumnLayout('Legs')
cmds.columnLayout(columnAttach = ('both', 5), rowSpacing = 10, columnWidth = 150)
cmds.setParent('..')
cmds.frameLayout(l = 'A: Leg Rig Setup')
cmds.button(l = '\nGenerate Foot Lean Locators\n', c = self.makeLean)
cmds.text('Place on either side of the foot.\nDo not rotate: Automatic orientation in place.')
cmds.frameLayout(l = 'B: Rig Legs')
cmds.button(l = '\nRig Legs\n', c = self.makeLegs)
cmds.setParent('..')
cmds.setParent('..')
cmds.setParent('..')
tab4 = cmds.rowColumnLayout('Arms')
cmds.columnLayout(columnAttach = ('both', 5), rowSpacing = 10, columnWidth = 150)
cmds.setParent('..')
cmds.frameLayout(l = 'A: Arm Rig Setup')
cmds.button(l = '\nA: Rig Arms\n', c = self.makeArms)
cmds.setParent('..')
cmds.setParent('..')
tab5 = cmds.rowColumnLayout('Spine and Head')
cmds.columnLayout(columnAttach = ('both', 5), rowSpacing = 10, columnWidth = 150)
cmds.setParent('..')
cmds.frameLayout(l = 'Spine Rig Setup')
cmds.setParent('..')
cmds.setParent('..')
tab6 = cmds.rowColumnLayout('Stretchy IK')
cmds.columnLayout(columnAttach = ('both', 5), rowSpacing = 10, columnWidth = 150)
cmds.setParent('..')
cmds.frameLayout(l = 'Stretchy Setup')
cmds.setParent('..')
cmds.setParent('..')
tab6 = cmds.rowColumnLayout('Extras')
cmds.scrollLayout(saw = 600, sah = 600, cr = True)
cmds.columnLayout(columnAttach = ('both', 5), rowSpacing = 10, columnWidth = 150)
cmds.setParent('..')
cmds.frameLayout(l = 'General Utitlities')
cmds.text('\nHere are all my general utilities for various things')
cmds.frameLayout(l = 'Automatic Blend Colors Creation and Connection')
cmds.rowColumnLayout(nc = 5, w = 10)
cmds.text('IK Joint:')
cmds.text(l = '')
cmds.text('FK/Dyn Joint:')
cmds.text(l = '')
cmds.text('Bind Joint:')
self.ikJBC = cmds.textField()
cmds.text(l = '')
self.fkJBC = cmds.textField()
cmds.text(l = '')
self.bindJBC = cmds.textField()
cmds.text(' \nBlend Quantity:')
cmds.text(l = '')
cmds.text(' \nSwitch Control:')
cmds.text(l = '')
cmds.text(l = '')
self.bQBC = cmds.intField()
cmds.text(l = '')
self.sCBC = cmds.textField()
cmds.text(l = '')
cmds.button(l = 'Help Docs', c = self.crBC.__doc__)
cmds.setParent('..')
cmds.button(l = 'Create', c = self.execCrBC)
cmds.text(l = '')
cmds.setParent('..')
cmds.frameLayout(l = 'Make Spline IK Curve Stretch And Squash')
cmds.rowColumnLayout(nc = 5, w = 10)
cmds.text('Curve Name:')
cmds.text(l = '')
cmds.text('Setup Name:')
cmds.text(l = '')
cmds.text('Joint Quantity:')
self.ikJBC = cmds.textField()
cmds.text(l = '')
self.fkJBC = cmds.textField()
cmds.text(l = '')
self.bindJBC = cmds.textField()
cmds.text(' \nSwitch Control:')
cmds.text(l = '')
cmds.text(' \nGlobal Control:')
cmds.text(l = '')
cmds.text(l = '')
self.bQBC = cmds.intField()
cmds.text(l = '')
self.sCBC = cmds.textField()
cmds.text(l = '')
cmds.button(l = 'Help Docs', c = self.crBC.__doc__)
cmds.setParent('..')
cmds.button(l = 'Create', c = self.execCrBC)
cmds.setParent('..')
cmds.showWindow(rigUI)
r = RUI('charNameUI', 'gScaleUI', 'fingButtonGrp', 'thumbCheckBox', 'spineButtonGrp', 'neckButtonGrp', 'ikJBC', 'fkJBC', 'bindJBC', 'bQBC', 'sCBC')
# last modified at 6.20 pm 29th June 2011
© Stack Overflow or respective owner