Search code examples
pythonmaya

python query selection type


Hi I want to make a window that when I click the button, only the curves are selected and their names are printed inside the textField. I only know how to select everything and print them all in the textField . Please help. thanks

window = cmds.window( widthHeight=(490, 485),title="braid")
def ygk_CurveSelect(*args):         
sels = cmds.ls(selection=True, long=True)
cmds.objectType(str(sels))
    for sel in sels:
        if sel == cmds.objectType('nurbsCurve'):
            selString = " ".join(sel)
            add = cmds.textField('ygk_PathText', edit=True, text=selString)
            print  'yeah!'
        else: 
            print 'no!'


cmds.columnLayout(adjustableColumn=True)
cmds.rowLayout( numberOfColumns=3, columnAttach=(1, 'right', 10), 
columnWidth=[(1,143),(2,245),(3,20)] )
cmds.text(label='Surface')
ygk_textFld = cmds.textField('ygk_PathText', width=240)
cmds.button(label='Assign Curves', command=ygk_CurveSelect)

cmds.showWindow()

Solution

  • def ygk_CurveSelect(*args):
        sel_sh = cmds.ls(sl=True, dag=True, type='nurbsCurve', ni=True)
        sel_tr = cmds.listRelatives(sel_sh, p=True)
        seltoText = ' '.join(sel_tr)
        cmds.textField('ygk_PathText', edit=True, text=seltoText)
        cmds.select(sel_tr)
    

    you can use also a loop and the command cmds.nodeType(), remember that nurbsCurve is the type on the shape only