MotionBuilder Forum
Welcome to Autodesk’s MotionBuilder Forums. Share your knowledge, ask questions, and explore popular MotionBuilder topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Remove entry from FBList?

4 REPLIES 4
Reply
Message 1 of 5
danilobuendia
667 Views, 4 Replies

Remove entry from FBList?

Does anyone know how to remove an entry from an FBList? Either by index or selection?

4 REPLIES 4
Message 2 of 5
tdHendrix
in reply to: danilobuendia

Here's how I did it:

 

from pyfbsdk import *
from pyfbsdk_additions import *


def PopulateListUI():

    myList.Items.removeAll()
    
    # add items to the list
    for number in range(0, 5):
        name = ('name%s') % number
        myList.Items.append(name)


def RemoveSelectedBtnEvent(control, event):
    
    if myList.Items.__len__() > 0:
        selectedItem = myList.Items[myList.ItemIndex]
    
        print ('Deleting %s') % selectedItem

        myList.Items.remove(selectedItem)
    
        # select the first item in the list
        myList.Selected(0, True)
                 

def OnToolDestroy(control,event):
    
    FBSystem().Scene.OnChange.Remove(SceneChanged)
        

def PopulateLayoutUI(mainLayout): 
   
    x = FBAddRegionParam(0,FBAttachType.kFBAttachLeft, "")
    y = FBAddRegionParam(0,FBAttachType.kFBAttachTop, "")
    w = FBAddRegionParam(0,FBAttachType.kFBAttachRight, "")
    h = FBAddRegionParam(25,FBAttachType.kFBAttachBottom, "")
    
    mainLayout.AddRegion("main", "main", x, y, w, h)
    vLayout = FBVBoxLayout()
    mainLayout.SetControl("main", vLayout)
    
    myLabel = FBLabel()
    myLabel.Caption = "My Label"
    vLayout.Add(myLabel, 10)

    global myList
    myList = FBList()
    vLayout.Add(myList, 20)
    
    PopulateListUI()
    
    removeSelectedIndexBtn = FBButton()
    removeSelectedIndexBtn.OnClick.Add(RemoveSelectedBtnEvent)
    removeSelectedIndexBtn.Caption = 'Remove Last Index'
    vLayout.Add(removeSelectedIndexBtn, 30)
    
    # register when this tool is destroyed
    tool.OnUnbind.Add(OnToolDestroy)
           
            
def CreateTool():
    
    global tool
    
    tool = FBCreateUniqueTool("List Removal")
    tool.StartSizeX = 275
    tool.StartSizeY = 110
    PopulateLayoutUI(tool)
    ShowTool(tool)
    

CreateTool()

 


Greg Hendrix - Senior Technical Animator
LinkedIn : Twitter
Message 3 of 5
danilobuendia
in reply to: tdHendrix

Ah, thanks Greg!

 

I ended up doing it round about:

 

  1. Build and initial list based on objects
  2. Made a button that deletes the object in the world by choice
  3. Checked for the existing objects and rebuilt the list accordingly

The remove function is much faster! I couldn't get the syntax correct 😞

 

~Danilo

 

 

Message 4 of 5
tdHendrix
in reply to: danilobuendia

No problem Man Happy

 

I know what you mean about not figuring out the syntax. Whenever I try to figure out how to script something in MotionBuilder it takes forever for me to figure out!


Greg Hendrix - Senior Technical Animator
LinkedIn : Twitter
Message 5 of 5
tdHendrix
in reply to: tdHendrix

Hey, I noticed an error with the code I posted in regards to the SceneChanged part when I was posting it to my blog. Sorry about that.

Instead of reposting the big block of code again, those interested can go to my blog post here.


Greg Hendrix - Senior Technical Animator
LinkedIn : Twitter

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report