Search code examples
pythonuser-interfacemaya

How to query the "selected" item in maya's textScrollList?


I am using python in maya, and trying to query the "selected" item in the textScrollList. In maya's documentation, it shows how to use uniqueTag and selectUniqueTagItem, which I was able to get working properly but its not what I am looking for.

In my textScrollList, its appending a variable which contains a list. When I use the uniqueTag flag, it query's the "tag" I assigned. I am wanting to query the content of the selected item in the list, not the tag name.

For example:

tScrollList = cmds.textScrollList( numberOfRows=8, allowMultiSelection=False,
        append=fileList, showIndexedItem=4, dcc=('doubleClick()') )



def refreshGUI():

    cmds.textScrollList(tScrollList, edit=True, removeAll=True) #removes current list
    newList = searchInput() #this contains a list

    #repopulates list 
    for r in newList:
        cmds.textScrollList(tScrollList, edit=True, append=r, uniqueTag="selectedFile", dcc=('doubleClick()')) 



def doubleClick():

    cmds.textScrollList(tScrollList, edit=True, selectUniqueTagItem=["selectedFile"])

    clickList = cmds.textScrollList(tScrollList, query=True, selectUniqueTagItem= True)   
    print clickList

In my gui upon double clicking the item, this example would print "selectedFile". I am trying to print the actual selected item in that list, not that tag name. I can't seem to find examples after googling, any help/examples would be greatly appreciated! Thank you so much.


Solution

  • You need to use select or double click command please check the docs its very clear about that.

    here is a working minimal version

    import maya.cmds as cmds
    
    cmds.window()
    cmds.paneLayout()
    fooBar = cmds.textScrollList( numberOfRows=8, allowMultiSelection=True,
                append=['one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten',
                        'eleven', 'twelve', 'thirteen', 'fourteen', 'fifteen'],
                selectItem='six', showIndexedItem=4, dcc = "getSelected()")
    cmds.showWindow()
    
    def getSelected():
        someList = cmds.textScrollList(fooBar, q=1, si=1)
        print someList