PDA

View Full Version : Attaching a popupMenu to each object in a list - Opinion needed


PozestStar
07-26-2012, 04:45 AM
I want to know if I'm doing this the best way possible, or if there's a better/more efficient/smarter way.

I have a text scroll list that lists all of the nCloth objects in the scene, or just the nCloth objects the user has selected. For each object in the list, I want to attach a popupMenu with a basic rename command and a few other things that I defined elsewhere. I figured right clicking and then selecting an option would be better than littering my UI with 10 clunky buttons.

What I was thinking of doing was something like this:

clothList = mc.textScrollList("nClothList", query=True, allItems=True)
startNum = 1
endNum = len(clothList)
for obj in range(startNum, endNum+1):
# attach my popupMenu to obj

I'm still relatively new to scripting (this is my first Python script ever). This seems to me like it's a good option, but I feel like there might be a better way to do it. I'd appreciate any opinions.

Thank you so much!

NaughtyNathan
07-26-2012, 10:01 AM
this won't work because a textScrollList is a single UI entity and has no child controls to attach something to (i.e. a popupMenu). Querying all its items simply returns a list of strings.

The only way to do it is to add a single pop-up to the whole textScrollList. The first thing this pop-up menu proc does (or it's individual cammands do) is to query the highlighted items in the textScrollList and then performs the relevent action on those.

another alternative would be to ditch the textScrollList altogether and build your own scrollList layout of individual controls, one for each entry (using button, or text controls or whatever)

DEVILSAN
11-16-2012, 07:40 AM
Just as Nathan said with the first option, and if the obj are the item in the nClothList then use the method below, where I used selObj .

# inside UI method where you put control#########
clothList = mc.textScrollList("nClothList", query=True, allItems=True)
self.nClothListPopUp()



def nClothListPopUp(self):
scrollListMenu=cmds.popupMenu(parent="nClothList",ctl=False, button=3)
cmds.menuItem(l="Test")
cmds.menuItem(l="test 2")

def selectedObjAction():
selObj = cmds.textScrollList('nClothList',q=True, si=True)
### get selected object from the textScrollList## and perform action related to it.

CGTalk Moderation
11-16-2012, 07:40 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.