Inside Sabertooth
Learn how Sabertooth uses 3ds Max to create 3D interactive projects, including HBO Go’s Game of Thrones interactive experience
  • 1/3
You are here: Forum Home / Autodesk® MotionBuilder® / Python / Mobu: choose character(and rember it) from a dropdown list
  RSS 2.0 ATOM  

Mobu: choose character(and rember it) from a dropdown list
Rate this thread
 
61918
 
Permlink of this thread  
avatar
  • kimi_cin
  • Posted: 13 November 2011 10:02 PM
  • Total Posts: 1
  • Joined: 13 November 2011 07:30 PM

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): 
             
x.Items.append(chararacterList[i].Name)

or #prefer this one

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

Any ideas? Thank you!



Replies: 0
avatar

Hi,

well your suggestions were the first ones that came into my mind when I had the same problem. ;)

In some of the example scripts provided by autodesk they had a totally different approach by setting the actual tool to global:

def CreateTool():
    global 
tool
    
    tool 
CreateUniqueTool("Property Example")
    
tool.StartSizeX 400
    tool
.StartSizeY 200
    PopulateLayout
(tool)
    
ShowTool(tool)
CreateTool()

Later in the PopulateLayout-Function you can access this tool very easily. Here shown in the autodesk example script:

...
def PopulateLayout(mainLyt):    
    
FBAddRegionParam(0,FBAttachType.kFBAttachLeft,"")
    
FBAddRegionParam(0,FBAttachType.kFBAttachTop,"")
    
FBAddRegionParam(0,FBAttachType.kFBAttachRight,"")
    
FBAddRegionParam(25,FBAttachType.kFBAttachBottom,"")
    
mainLyt.AddRegion("main","main"xywh)
    
vlyt VBoxLayout()
    
mainLyt.SetControl("main",vlyt)
    
    
FBLabel()
    
l.Caption "Drag and drop a model into the container. Double click to clear."
    
vlyt.Add(l,30)
    
    
tool.model None
    tool
.container FBContainer()
    
tool.container.OnDragAndDrop.Add(EventContainerDragAndDrop)
    
tool.container.OnDblClick.Add(EventContainerDblClick)
    
vlyt.Add(tool.container,30)
...

In your own code just create a list and make sure it is added to the tool like in the first line below:

...
tool.myDropDownList FBList()
tool.myDropDownList.Style FBListStyle.kFBDropDownList
for obj in myList:
    
tool.myDropDownList.Items.append(obj.Name)
lyt.Add(tool.myDropDownList20#add line 2 with 20 pixels from the top
...

myList contains the actual list that will be shown in the dropdown-list, e.g. myList=["one”,"two”,"three"].

After you set up your button(FBButton()) in its callback-function you can easily access the items in the list with tool.<<your list>>:

def ButtonCallback(controlevent):
    
myList tool.myDropDownList.Items[tool.myDropDownList.ItemIndex]
    
print tool.myDropDownList.Items[tool.myDropDownList.ItemIndex]+" is ready to be processed"
    
# put the rest of the script here

Cheers,

Chris



Replies: 0