Maya python script (selection into textField)


#1

Hi I’m trying to make a window tool in maya and I’m stuck. If I run the script there’s a textField with a button in a window. I want multiple objects’ names to appear in the textField when I press the button, but I only get the first selection in it. I know that it’s because of text=sel[0], but I don’t know how to change it so it could grab multiple selections. Please help.

Blockquote
import maya.cmds as cmds
import maya.mel as mel

window = cmds.window( widthHeight=(490, 485),title=“braid”)
def ygk_SurfaceSelect(*args):
sel = cmds.ls(selection=True)
add = cmds.textField(‘ygk_surfaceText’, edit=True, text=sel[0])

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_surfaceText’, width=240)
cmds.button(label=‘Assign Surface’, command=ygk_SurfaceSelect)
cmds.setParent(’…’)
cmds.showWindow()


#2

If you only need a string instead of a list you can do it with:

sel = cmds.ls(selection=True)
selString = " ".join(sel)
add = cmds.textField(‘ygk_surfaceText’, edit=True, text=selString)

#3

thanks so much