textFieldButtonGrp selections not applying to multiple buttons


I have a set of 3 buttons that I amusing to select joint chains and pole vectors. When I select the chain, I have the text in the textFieldButtonGrp change to the name of the selected joint.

My problem is that when I create another set of buttons in my UI and select another joint chain, the name still changes in my first set of buttons and not the second set. While I know this is because I declare the textFieldButtonGrp name in the select_joints_afk method I’m not sure how to change this so it could work no matter how many sets of textFieldButtonGrps I add to myUI.

would any know how to go about this?

code for UI:

cmds.text(label = 'Left Arm', align ='center')
tsL0 =cmds.textFieldButtonGrp(ed=False, adj=1,cal=(1,"left"),cw3=(10,100,25), cl3=("left","left","left") , 
                                buttonLabel='Root   FK',bc = 'Create_Selection_Chains.select_joints_afk(right_arm_select)' )
gtF0 = tsL0 

Code for selection

class Create_Selection_Chains:

    def __init__(self, name, Fks, Ikw, ikpv):
        self.name = name
        self.Fks = Fks
        self.Ikw = Ikw
        self.ikpv = ikpv
    def select_joints_afk(self):
        if cmds.ls(selection = True,type=("transform",'nurbsCurve')):
            sel = cmds.ls(sl=True)
            fkCtrls = cmds.listRelatives(sel, allDescendents=True, type=("transform",'nurbsCurve'))
            self.Fks = [nurbsCurve for nurbsCurve in fkCtrls if nurbsCurve.startswith('FK') & nurbsCurve.endswith('_Ctrl')]
            cmds.textFieldButtonGrp(gtF0, edit = True, tx ='' .join(sel),buttonLabel='IK OK',backgroundColor = (.5,.8,.2))
            print self.Fks
            return self.Fks 
            text = cmds.confirmDialog( title='Error', message='Must select joint', button=['OK'], 
                                        defaultButton='Ok', dismissString='No' )

Pass it as an argument to the method.

Systematically it makes sense what your doing - but if validation fails your button group already exists and you’ll need to do fix up code to remove it and do any clean up. I advise you validate your data first prior to dynamically generating your UI elements i.e.:

  1. Validate your selection.
  2. If valid, generate the button group.
  3. Pass the button group to the method.
  4. Have the method work on the selection and group.

There’s broader design questions we can get into about data validation and how much work your methods need to do. LBYL (look before your leap) or EAFP (easier to ask for forgiveness than permission) especially when it comes to duck typing are good to take into consideration: