MoBu choose character from a list

Hey,
I am new to scripting in python for MotionBuilder, and I am having some difficulty with a script that needs to allow the user to choose a selected character from a dropdown list, and plot the animation.
I managed to create the window and the dropdown list with all the characters in the scene, I just need to find out how to remeber the selected characters- preferably when clicking the ok button.

print control.Items[control.ItemIndex] #prints the selected characters on selection
    varTest = 0
    for x in control.Items[control.ItemIndex]:
        if x.IsSelected(varTest)==True: 
             x.Items.append(chararacterList[i].Name)

or #prefer this one

def ClosePopupCallback(control, event):
    characterList=[]
    for x in Items[control.ItemIndex]:
        if x.selected (True):
             x.Items.append(chararacterList[i].Name)           
    CloseTool(t)

Any ideas? Thank you!

I’m having a lot of trouble understanding what you want to do. Can you back up and explain in more detail?

I want to:
-check what characters I have in a scene(done)
-show the availbale characters in a pop-up window(done)
-choose one or more characters(found out how to remeber the chosen characters, having difficulty with selecting multiple characters while holding CTRL)
-plot their specific animation(done)

I think what her intention is to automate the process of plotting multiple characters…

Because if you want to do this by hand, you have to Make the character the active one, click plot character, select next next and make active, plot character, and so on…

Not really sure about the functionality of your code there, but if I were you, I would make this tool inside of a class with a list holding all the characters to have a function for looping over the list and doing the steps above for automating the process

EDIT: answered thread without seeing you latest reply

Exactly tistatos :slight_smile: but at the same time I would like to have the option to pick wichever characters i want to plot, that is what my issue is. If i select them individually it works, but if i select them while holding down CTRL it doesn’t because when it does this piece of code
x = charList[control.ItemIndex]

if x in arrList:
    arrList.remove(x)
else:
    arrList.append(x)

it treats the selected characters as a whole not as individual entities so it keeps removing the first item(when holding down ctrl) among other odd behaviours. Not sure how that list works.

I don’t think you can’t use a dropdown menu for this since it only has one active Index, perhaps some sort of checkbox list where you can have multiple selections

FBList.ItemIndex is only a single int, so it won’t do you any good for a multi-select list. You have the right idea in using IsSelected(), you’re just not using it quite as intended.

Forget about ItemIndex; you just want to iterate over the entire list and call IsSelected() for each index:


for i in range(0, len(characterList.Items)):
    if characterList.IsSelected(i):
        # characterList.Items[i] is selected

Full example code, if you want to paste it into MotionBuilder:
http://awforsythe.com/files/ListMultiSelectTestGUI.py

Great piece of code awforsythe, ^^ thank you so much for the help.