I’m trying to combine a list of objects into one and I’m having a rough time understanding how to accomplish this since I’m new to this.
I have three functions in a Chain_select class; each create a list containing objects I’ve selected in the viewport. List 1 (Fks) contains three items corresponding to my shoulder, elbow and wrist fk controls. List 2 (ikw) and list 3 (ikpv)contain only one object each, for my ik wrist and pole vector control
For now what I want to happen is when I press a button in my ui, I want a list to be created containing all the previous items in a flattened list. verified by having the list printed in the output.
As stated before, I believe I have the first part figured out. The functions below make my three lists. but please correct me if I’m wrong:
class Chain_Selection():
def selectJointLAFK():
Fks = []
Fks.clear()
if cmds.ls(selection = True,type=("transform",'nurbsCurve')):
sel = cmds.ls(sl=True)
fkCtrls = cmds.listRelatives(sel, allDescendents=True, type=("transform",'nurbsCurve'))
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))
del Fks[1]
del Fks[2]
Fks.extend(sel)
print Fks[0]
print Fks[1]
print Fks[2]
else:
text = cmds.confirmDialog( title='Error', message='Must select joint', button=['OK'], defaultButton='Ok', dismissString='No' )
def selectJointLwristIK():
ikw = []
ikw.clear()
if cmds.ls(selection = True,type=("transform",'nurbsCurve')):
ikwrist=cmds.ls(selection = True)
ikw = [nurbsCurve for nurbsCurve in ikwrist if nurbsCurve.startswith('IK') & nurbsCurve.endswith('Ctrl')]
cmds.textFieldButtonGrp(gtF1, edit = True, tx ='' .join(ikwrist),buttonLabel='IK OK',backgroundColor = (.5,.8,.2))
else:
text = cmds.confirmDialog( title='Error', message='Must select joint', button=['OK'], defaultButton='Ok', dismissString='No' )
def selectJointLelbowIK():
ikpv = []
ikpc.clear()
if cmds.ls(selection = True,type=("transform",'nurbsCurve')):
ikPvsel = cmds.ls(selection = True)
ikpv = [locator for locator in ikPvsel if locator.startswith('IK') & locator.endswith('Ctrl')]
cmds.textFieldButtonGrp(gtF2, edit = True, tx ='' .join(ikPvsel),buttonLabel='IK OK',backgroundColor = (.5,.8,.2))
print ikpv
else:
text = cmds.confirmDialog( title='Error', message='Must select joint', button=['OK'], defaultButton='Ok', dismissString='No' )
The part I don’t understand is getting these lists into my other function in a different class. I’ve tried different things but I’m not getting it obviously. I know this is wrong but here is what I last had
class Combined_Selection():
@staticmethod
def __init__(self,*arg):
combined_selection=[]
@staticmethod
def combine_lists():
self.Fks = Chain_Selection.selectJointLAFK(Fks)
self.ikw = Chain_Selection.selectJointLwristIK(ikw)
self.ikpv = Chain_Selection.selectJointLelbowIK(ikpv)
self.combined_selection.append(Fks,ikw,ikpv)
print combined_Selection
This is for my button to call the function:
cmds.button(label='Test 1', command = '', width=100)
cmds.button(label='Combine', command = Combined_Selection, width=100)
cmds.setParent('..')
cmds.separator(h=5, style = 'none')
cmds.separator(h=5)
any help would be greatly appreciated