PDA

View Full Version : What arguments do I send for this button to work in python?


JaredTaylor
06-29-2011, 08:24 AM
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)
# the class that the function is within is a child of this class

dbsmith
06-30-2011, 11:49 PM
Try something like this:
(Although, I dont see self.ikJBC in your code, so I'm assuming you didnt post all of it)


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('..')

def execCrBC(*args):
self.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))

cmds.button(l = 'Create', c = execCrBC)

JaredTaylor
07-01-2011, 09:51 PM
Hi there,

That makes it just tell me :

object '' is invalid

It isn't reading the arguments, and when I print the arguments being received, it says they're all empty

dbsmith
07-04-2011, 03:55 AM
You may need to post up more of your UI code for me to help further

CGTalk Moderation
07-04-2011, 03:55 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.