MotionBuilder Python -Choose Interaction Mode Tool

On the Discrete Motionbuilder Forum there was a discussion on how to use python the change Motionbuilder’s InteractionMode.

Sunil (the person that started the post) was able to figure out a solution to his original post and I suggested that a hotkey could be setup to trigger the script via the ActionScript.Txt file(more on that in later post).

The script made me quickly realize that I often jump onto other people’s systems to help them out with any MotionBuilder problem they maybe facing. More often than not they are using Maya or 3dmax InteractionModes and I have to change them “MotionBuilder” so that I may work comfortably.

I wrote a very simple script that will generate a tool that lists all InteractionModes and allows you to instantly change them on the fly with a simple single click.

import pyfbsdk as fb
import pyfbsdk_additions as fba

##Change InteractionMode On List Item Click
def DrpDwn_intModeList_CallBack(control, event):
    ##Change Mode
    fb.FBActionManager().CurrentInteractionMode = control.Items[control.ItemIndex]
    ##Update UI To Communicate CurrentInteractionMode
    interactionMode.Caption = fb.FBActionManager().CurrentInteractionMode
 
    
'''
UI Layout
'''
def PopulateTool(t):    
    ##Inter Active Mode Label------------------------------------------------------------------------------
    intModeList = fb.FBLabel()
    
    x = fb.FBAddRegionParam(   5, fb.FBAttachType.kFBAttachNone, "" )
    y = fb.FBAddRegionParam(   5, fb.FBAttachType.kFBAttachNone, "" )
    w = fb.FBAddRegionParam( -5, fb.FBAttachType.kFBAttachRight, "" )
    h = fb.FBAddRegionParam(  20, fb.FBAttachType.kFBAttachNone, "" )
    
    t.AddRegion( "intModeList", "intModeList", x, y, w, h )
    t.SetControl( "intModeList", intModeList )
    
    intModeList.Caption                                 = "Choose InteractionMode:"
    intModeList.Style                                   = fb.FBTextStyle.kFBTextStyleBold
    intModeList.Justify                                 = fb.FBTextJustify.kFBTextJustifyCenter
        
    ##Inter Active Drop Down List------------------------------------------------------------------------------
    DrpDwn_intModeList                                  = fb.FBList()
    
    x = fb.FBAddRegionParam(   0, fb.FBAttachType.kFBAttachLeft, "intModeList" )
    y = fb.FBAddRegionParam(   5, fb.FBAttachType.kFBAttachBottom, "intModeList" )
    w = fb.FBAddRegionParam(  -5, fb.FBAttachType.kFBAttachRight, "" )
    h = fb.FBAddRegionParam( 95, fb.FBAttachType.kFBAttachNone, "" )
    
    t.AddRegion( "DrpDwn_intModeList", "DrpDwn_intModeList", x, y, w, h )
    t.SetControl( "DrpDwn_intModeList", DrpDwn_intModeList )
    
    DrpDwn_intModeList.MultiSelect                      = False
    DrpDwn_intModeList.ExtendedSelect                   = False
    DrpDwn_intModeList.Style                            = fb.FBListStyle.kFBVerticalList
    
    ##Generate List And Have The Current InteractiveMode Selected------------------------------------------------------------------------------
    interactionModes = [ "MotionBuilder", "MotionBuilder Classic", "Maya", "3ds Max", "Lightwave", "Softimage" ]
    for mode in interactionModes:
        DrpDwn_intModeList.Items.append(mode)
        
        if fb.FBActionManager().CurrentInteractionMode == mode:
            myMode = interactionModes.index(mode)
        
    DrpDwn_intModeList.ItemIndex = myMode
        
    DrpDwn_intModeList.OnChange.Add(DrpDwn_intModeList_CallBack)
        
    ##Current Inter Active Mode Label------------------------------------------------------------------------------
    currentMode = fb.FBLabel()
    x = fb.FBAddRegionParam(   0, fb.FBAttachType.kFBAttachLeft, "DrpDwn_intModeList" )
    y = fb.FBAddRegionParam(   5, fb.FBAttachType.kFBAttachBottom, "DrpDwn_intModeList" )
    w = fb.FBAddRegionParam(   0, fb.FBAttachType.kFBAttachRight, "" )
    h = fb.FBAddRegionParam(  20, fb.FBAttachType.kFBAttachNone, "" )
    
    t.AddRegion( "currentMode", "currentMode", x, y, w, h )
    t.SetControl( "currentMode", currentMode )
    
    currentMode.Caption                                 = "Current InteractionMode:"
    currentMode.Style                                   = fb.FBTextStyle.kFBTextStyleBold
    currentMode.Justify                                 = fb.FBTextJustify.kFBTextJustifyLeft
        
    ##Current Interactive Mode------------------------------------------------------------------------------
    global interactionMode
    interactionMode = fb.FBLabel()
    
    x = fb.FBAddRegionParam(   0, fb.FBAttachType.kFBAttachLeft, "currentMode" )
    y = fb.FBAddRegionParam(   5, fb.FBAttachType.kFBAttachBottom, "currentMode" )
    w = fb.FBAddRegionParam(   0, fb.FBAttachType.kFBAttachRight, "" )
    h = fb.FBAddRegionParam(  20, fb.FBAttachType.kFBAttachNone, "" )
    
    t.AddRegion( "interactionMode", "interactionMode", x, y, w, h )
    t.SetControl( "interactionMode", interactionMode )
    
    interactionMode.Caption                                 = fb.FBActionManager().CurrentInteractionMode
    interactionMode.Style                                   = fb.FBTextStyle.kFBTextStyleBold
    interactionMode.Justify                                 = fb.FBTextJustify.kFBTextJustifyCenter


    
def CreateTool():
    t               = fba.FBCreateUniqueTool( "Switch InteractionMode" )
    t.MinSizeX      = 160
    t.MaxSizeX      = 160
    t.MinSizeY      = 175
    t.MaxSizeY      = 175
    
    PopulateTool(t)
    fb.ShowTool(t)

CreateTool()

This was quick script to make but I know it will save me some time and frustration when helping other at their computers.

Add a Comment

Your email address will not be published. Required fields are marked *