MotionBuilder Python FBDelete

I’ve been asked a few times now on how to delete objects, files, takes, layers, etc. from MotionBuilder’s Scenes. I thought I would take a few moments to go through the basics of FBDelete(). All examples below share pretty much the exact same structure with there scripts, we create an empty list, we set up condition and if those condition are met than we add to our list, once done we take that list and we perform FBDelete() on it. This is a great little exercise to get familiar with lists.  Each example I have provided will demonstrate performing the script through “user defined name”, “user selected”, “all occurrences within scene” and for some “by file extension”.

I created an index as to make it easier for people to jump to sections.

  1. Folders
  2. Layers
  3. Cameras
  4. Groups
  5. Sets
  6. Lights
  7. Materials
  8. Poses
  9. Shaders
  10. Takes
  11. Textures
  12. Videos

FBDelete() Folders

'''
================================================================
FBDelete Folder By Name
================================================================
'''
##Define The Folder We Are Looking For - Change This Variable To Match Your Desired Folder You Wish To Delete
lFolderDel = "Materials Folder"
##Go Through Every Folder Within The Scene
for item in fb.FBSystem().Scene.Folders:
    ##If The Folder Name Is The Same As The Folder We Are Looking For
    if item.Name == lFolderDel:
        ##Delte Folder
        item.FBDelete()
    ##Skip All Other Folders
    else:
        pass
##Clean Up        
del lFolderDel

Return to index

FBDelete() Layers

'''
================================================================
FBDelete Layers By Name, Selected And All Layers Within The Scene
================================================================
'''
##Create 10 Layers To Help Testing
for i in range (1,10):
    ##Create The Layer
    fb.FBSystem().CurrentTake.CreateNewLayer()

'''
Delete All Layers
'''    
##Get A Layer Count
lCount = fb.FBSystem().CurrentTake.GetLayerCount()
##Create An Empty Layers List
lLayerLst = []
##We Want To Omit The Base Layer Which Is Why Our Range Starts At 1 (Base Layer == 0)
for layer in range(1 ,lCount):
    lLayerLst.extend([fb.FBSystem().CurrentTake.GetLayer(layer)])
##Delete All Layer That Are In The Layers List
for layer in lLayerLst:
    layer.FBDelete()
##Clean Up
del lCount, lLayerLst
    
'''
Delete Layer By Name
'''
##Define The Layer We Are Looking For - Change This Variable To Match Your Desired Layer You Wish To Delete
lDelLayerName = "AnimLayer8"
##Delte Layer By Name
fb.FBSystem().CurrentTake.GetLayerByName(lDelLayerName).FBDelete()
##Clean Up
del lDelLayerName

'''
Delete Selected Layers
'''
lCount = fb.FBSystem().CurrentTake.GetLayerCount()
##Create An Empty Layers List
lLayerLst = []
##Check All Layers On Current Take And If They Are Selected Than Store The Layer's Name To The Layers List
for layer in range(lCount):
    if fb.FBSystem().CurrentTake.GetLayer(layer).Selected == True:
        lLayerLst.extend([fb.FBSystem().CurrentTake.GetLayer(layer).Name])
    else: pass
##Delete Layer That Are Found in Layer List
for layer in lLayerLst:
    fb.FBSystem().CurrentTake.GetLayerByName(layer).FBDelete()
##Clean Up
del lCount, lLayerLst

Return to index

FBDelete() Cameras

'''
================================================================
FBDelete Camera By Name, Selected And All Cameras Within The Scene
================================================================
'''

'''
Delete All Cameras That Are Not Orthographic
'''
##Create A Variable To Protect Our "Producer" Cameras Which Are Used In Orthographic Views
lCamOrth = "Producer"
##Create An Empty Camera List
lCamLst = []
##Go Throuh All Cameras Within The Scene
for camera in fb.FBSystem().Scene.Cameras:
    ##If "Producer" Is Found Within The Name Then Skip The Camera
    if lCamOrth in camera.Name: pass
    ##Store Camera To Camera List
    else: lCamLst.extend([camera])
##Delete Cameras Within The Camera List    
for camera in lCamLst:
    camera.FBDelete()
##Clean Up    
del lCamOrth, lCamLst

'''
Delete All Selected Cameras That Are Not Orthographic
'''
##Create A Variable To Protect Our "Producer" Cameras Which Are Used In Orthographic Views
lCamOrth = "Producer"
##Create An Empty Camera List
lCamLst = []
##Go Throuh All Cameras Within The Scene
for camera in fb.FBSystem().Scene.Cameras:
    ##Selected Cameras
    if camera.Selected == True:
        ##If "Producer" Is Found Within The Name Then Skip The Camera 
        if lCamOrth in camera.Name: pass ##!!This Condition Can Be Removed If The User Does Not Wish To Protect The Orthographic Views
        ##Store Camera To Camera List
        else: lCamLst.extend([camera])
    ##Skip Any Un Selected Cameras    
    else: pass
##Delete Cameras Within The Camera List  
for camera in lCamLst:
    camera.FBDelete()
##Clean Up      
del lCamOrth, lCamLst

'''
Delete Camera By Name
'''
##Define The CAmera We Are Looking For - Change This Variable To Match The Desired Camera You Wish To Delete
lDelCameName = "Camera 2"
##Go Through Every Camera Within The Scene
for camera in fb.FBSystem().Scene.Cameras:
    ##If A Camera's Name Matched Our Desired Camera Name
    if camera.Name == lDelCameName:
        ##Delte Camera
        camera.FBDelete()
    ##Skip All Other Cameras    
    else: pass
##Clean Up    
del lDelCameName  

Return to index

FBDelete() Groups

'''
================================================================
FBDelete Groups By Name, Selected And All Groups Within The Scene
================================================================
'''
##Create 10 Groups
for i in range(1, 10):
    lGroupName = "Group " + str(i)
    fb.FBGroup( lGroupName )
##Clean Up
del lGroupName

'''
Delete All Groups
'''
##Create An Empty Group List
lGroupLst = []
##Go Through All Groups Within Our Scene And Add Them To Oue Group List    
for group in fb.FBSystem().Scene.Groups:
    lGroupLst.extend ([group])
##Delete All Groups That Are In Our Group List
for group in lGroupLst:
    group.FBDelete()
##Clean Up    
del lGroupLst

'''
Delete Selected Groups
'''
##Create An Empty Group List
lGroupLst = []
##Go Through All Groups Within Our Scene And If They Are Seleced Then Add Them To Oue Group List    
for group in fb.FBSystem().Scene.Groups:
    if group.Selected == True:
        lGroupLst.extend ([group])
    else: pass
##Delete All Groups That Are In Our Group List
for group in lGroupLst:
    group.FBDelete()
##Clean Up    
del lGroupLst

'''
Delete Group By Name
'''
##Define The Group We Are Looking For - Change This Variable To Match Your Desired Group You Wish To Delete
lDelGroupName = "Group 2"
##Go Through All Groups Within Our Scene And If They Are Seleced Then Add Them To Oue Group List    
for group in fb.FBSystem().Scene.Groups:
    if group.Name == lDelGroupName:
        group.FBDelete()
    else: pass
##Clean Up
del lDelGroupName

Return to index

FBDelete() Sets

'''
================================================================
FBDelete Sets By Name, Selected And All Sets Within The Scene
================================================================
'''
for i in range(1, 10):
    setname = "Set " + str(i)
    fb.FBSet( setname )
    
'''
Delete All Sets
'''
##Create An Empty Group List
lSetLst = []
##Go Through All Sets Within Our Scene And Add Them To Oue Group List    
for item in fb.FBSystem().Scene.Sets:
    lSetLst.extend ([item])
##Delete All Sets That Are In Our Group List
for item in lSetLst:
    item.FBDelete()
##Clean Up    
del lSetLst

'''
Delete Selected Sets
'''
##Create An Empty Group List
lSetLst = []
##Go Through All Sets Within Our Scene And If They Are Seleced Then Add Them To Oue Group List    
for item in fb.FBSystem().Scene.Sets:
    if item.Selected == True:
        lSetLst.extend ([item])
    else: pass
##Delete All Sets That Are In Our Group List
for item in lSetLst:
    item.FBDelete()
##Clean Up    
del lSetLst

'''
Delete Set By Name
'''
##Define The Group We Are Looking For - Change This Variable To Match Your Desired Group You Wish To Delete
lDelSetName = "Set 6"
##Go Through All Sets Within Our Scene And If They Are Seleced Then Add Them To Oue Group List    
for group in fb.FBSystem().Scene.Sets:
    if group.Name == lDelSetName:
        group.FBDelete()
    else: pass
##Clean Up    
del lDelSetName

Return to index

FBDelete() Lights

'''
================================================================
FBDelete Lights By Name, Selected And All Lights Within The Scene
================================================================
'''

'''
Delete All Lights In The Scene
'''
##Create An Empty Light List
lLightLst = []
##Go Throuh All Lights Within The Scene
for light in fb.FBSystem().Scene.Lights:
    ##Add Each Light To The Light List
    lLightLst.extend([light])
##Delete Lighst Within The Lights List    
for light in lLightLst:
    light.FBDelete()
##Clean Up    
del lLightLst

'''
Delete All Selected Lights
'''
##Create An Empty Light List
lLightLst = []
##Go Throuh All Light Within The Scene
for light in fb.FBSystem().Scene.Lights:
    ##Selected Light
    if light.Selected == True:
        ##Add Each Light To The Light List
        lLightLst.extend([light])
    ##Skip Any Un Selected Light    
    else: pass
##Delete Light Within The Camera List  
for light in lLightLst:
    light.FBDelete()
##Clean Up      
del lLightLst

'''
Delete Light By Name
'''
##Define The Light We Are Looking For - Change This Variable To Match The Desired Light You Wish To Delete
lDelLightName = "Light 2"
##Go Through Every Light Within The Scene
for light in fb.FBSystem().Scene.Lights:
    ##If A Light's Name Matched Our Desired Light Name
    if light.Name == lDelLightName:
        ##Delte Light
        light.FBDelete()
    ##Skip All Other Cameras    
    else: pass
##Clean Up    
del lDelLightName   

Return to index

FBDelete() Material

'''
================================================================
FBDelete Materials By Name, Selected And All Materials Within The Scene
================================================================
'''

'''
Delete All Materials
'''
##Create An Empty Material List
lMatLst = []
##Serach All Materials Within The Scene    
for material in fb.FBSystem().Scene.Materials:
    ##Skip The DefaultMaterial
    if material.Name == "DefaultMaterial": pass
    ##Add Material To Our Material List
    else: lMatLst.extend ([material])
##Go Through Each Material In Our Materail List    
for material in lMatLst:
    ##Delete Material
    material.FBDelete()
##Clean Up
del lMatLst

'''
Delete Selected Materials
'''
##Create An Empty Material List
lMatLst = []
##Serach All Materials Within The Scene    
for material in fb.FBSystem().Scene.Materials:
    ##Materials That Are Selected
    if material.Selected == True:
        ##Skip The DefaultMaterial
        if material.Name == "DefaultMaterial": pass
        ##Add Material To Our Material List
        else: lMatLst.extend ([material])
    ##Skip Materials That Are Not Selected    
    else: pass
##Go Through Each Material In Our Materail List    
for material in lMatLst:
    ##Delete Material
    material.FBDelete()
##Clean Up
del lMatLst

'''
Delete Materials By Name
'''
##Define The Material We Are Looking For - Change This Variable To Match The Desired Material You Wish To Delete
lMaterialDel = "Material 2"
##Serach All Materials Within The Scene    
for material in fb.FBSystem().Scene.Materials:
    ##Look At The Name To See If It Matches The Desired Material You Wish To Delete
    if material.Name == lMaterialDel:
        ##Delete Material
        material.FBDelete()
    ##Skip All Materials That Do Not Match The Desired Material You Wish To Delete   
    else:
        pass
##Clean Up
del lMaterialDel

Return to index

FBDelete() Poses

'''
================================================================
FBDelete Pose By Name, Selected And All Poses Within The Scene
================================================================
'''

'''
Delete All Poses
'''
##Create An Empty Pose List
lPoseLst = []
##Serach All Pose Within The Scene    
for pose in fb.FBSystem().Scene.CharacterPoses:
    lPoseLst.extend ([pose])
##Go Through Each Pose In Our Pose List    
for pose in lPoseLst:
    ##Delte Pose
    pose.FBDelete()
##Clean Up
del lPoseLst

'''
Delete Selected Poses
'''
##Create An Empty Pose List
lPoseLst = []
##Serach All Poses Within The Scene    
for pose in fb.FBSystem().Scene.CharacterPoses:
    ##Poses That Are Selected
    if pose.Selected == True:
        ##Skip The DefaultMaterial
        if pose.Name == "DefaultMaterial": pass
        ##Add Pose To Our Pose List
        else: lPoseLst.extend ([pose])
    ##Skip Poses That Are Not Selected    
    else: pass
##Go Through Each Pose In Our Materail List    
for pose in lPoseLst:
    ##Delte Pose
    pose.FBDelete()
##Clean Up
del lPoseLst

'''
Delete Poses By Name
'''
##Define The Pose We Are Looking For - Change This Variable To Match The Desired Pose You Wish To Delete
lPoseDel = "Character Pose 2"
##Serach All Poses Within The Scene    
for pose in fb.FBSystem().Scene.CharacterPoses:
    ##Look At The Name To See If It Matches The Desired Pose You Wish To Delete
    if pose.Name == lPoseDel:
        ##Delte Pose
        pose.FBDelete()
    ##Skip All Poses That Do Not Match The Desired Pose You Wish To Delete   
    else:
        pass
##Clean Up
del lPoseDel

Return to index

FBDelete() Shaders

'''
================================================================
FBDelete Shader By Name, Selected And All Shaders Within The Scene
================================================================
'''

'''
Delete All Shader
'''
##Create An Empty Shader List
lShaderLst = []
##Serach All Shaders Within The Scene    
for shader in fb.FBSystem().Scene.Shaders:
    ##Skip The Default Shader
    if shader.Name == "Default Shader": pass
    ##Add Shader To Our Shader List
    else: lShaderLst.extend ([shader])
##Go Through Each Shader In Our Shader List    
for shader in lShaderLst:
    ##Delete Shader
    shader.FBDelete()
##Clean Up
del lShaderLst

'''
Delete Selected Shaders
'''
##Create An Empty Shader List
lShaderLst = []
##Serach All Shaders Within The Scene    
for shader in fb.FBSystem().Scene.Shaders:
    ##Shaders That Are Selected
    if shader.Selected == True:
        ##Skip The Default Shader
        if shader.Name == "Default Shader": pass
        ##Add Shader To Our Shader List
        else: lShaderLst.extend ([shader])
    ##Skip Shaders That Are Not Selected    
    else: pass
##Go Through Each Shader In Our Shader List    
for shader in lShaderLst:
    ##Delete Shader
    shader.FBDelete()
##Clean Up
del lShaderLst

'''
Delete Shaders By Name
'''
##Define The Shader We Are Looking For - Change This Variable To Match The Desired Shader You Wish To Delete
lShaderDel = "BumpShader 1"
##Serach All Shaders Within The Scene    
for shader in fb.FBSystem().Scene.Shaders:
    ##Look At The Name To See If It Matches The Desired Shader You Wish To Delete
    if shader.Name == lShaderDel:
        ##Delete Shader
        shader.FBDelete()
    ##Skip All Shaders That Do Not Match The Desired Shader You Wish To Delete   
    else:
        pass
##Clean Up
del lShaderDel

Return to index

FBDelete() Takes

'''
================================================================
FBDelete Takes By Name, Selected And All Takes Within The Scene
================================================================
'''
##Create 10 Takes To Help Testing
for i in range (1,10):
    lTakeName = 'Take Name' + ' 00' + str(i)
    newtake = fb.FBSystem().CurrentTake.CopyTake(lTakeName)
    fb.FBPlayerControl().GotoStart()
    newtake.ClearAllProperties(False)
    newtake.LocalTimeSpan = fb.FBTimeSpan( fb.FBTime(0), fb.FBTime(0, 0, 0, 150) )
##Clean Up    
del lTakeName

'''
Delete Take By Name
'''
##Define The Take We Are Looking For - Change This Variable To Match Your Desired Take You Wish To Delete
lDelTakeName = "Take Name 005"
for i in fb.FBSystem().Scene.Takes:
    if i.Name == lDelTakeName:
        i.FBDelete()
    else: pass
##Clean Up    
del lDelTakeName
'''
Delete Selected Takes
'''
##Create An Empty Take List
lTakeLst = []
##Add Every Selected Take Within Our Scene To Our Take List
for i in range( len(fb.FBSystem().Scene.Takes) ):
    if fb.FBSystem().Scene.Takes[i].Selected == True:
        lTakeLst.extend([fb.FBSystem().Scene.Takes[i]])
    else: pass
##Delete Every Take Within Our Take List    
for take in lTakeLst:
    take.FBDelete()
##Clean Up    
del lTakeLst     
    
'''
Delete All Takes - No Idea Why You Would Want To Do This
'''
##Create An Empty Take List
lTakeLst = []
##Add Every Selected Take Within Our Scene To Our Take List
for i in range( len(fb.FBSystem().Scene.Takes) ):
    lTakeLst.extend([fb.FBSystem().Scene.Takes[i]])
##Delete Every Take Within Our Take List    
for take in lTakeLst:
    take.FBDelete()      
##Clean Up    
del lTakeLst

Return to index

FBDelete() Textures

'''
================================================================
FBDelete Textures By Name, File Extention Selected And All Textures Within The Scene
================================================================
'''

'''
Delete All Textures
'''
##Create An Empty Texture List
lTextureLst = []
##Serach All Textures Within The Scene    
for texture in fb.FBSystem().Scene.Textures:
    ##Skip The Default Texture
    if texture.Name == "Default Shader": pass
    ##Add Texture To Our Texture List
    else: lTextureLst.extend ([texture])
##Go Through Each Texture In Our Texture List    
for texture in lTextureLst:
    ##Delete Texture
    texture.FBDelete()
##Clean Up
del lTextureLst

'''
Delete Selected Textures
'''
##Create An Empty Texture List
lTextureLst = []
##Serach All Textures Within The Scene    
for texture in fb.FBSystem().Scene.Textures:
    ##Textures That Are Selected
    if texture.Selected == True:
        ##Skip The Default Texture
        if texture.Name == "Default Shader": pass
        ##Add Texture To Our Texture List
        else: lTextureLst.extend ([texture])
    ##Skip Textures That Are Not Selected    
    else: pass
##Go Through Each Texture In Our Texture List    
for texture in lTextureLst:
    ##Delete Texture
    texture.FBDelete()
##Clean Up
del lTextureLst

'''
Delete Textures By Name
'''
##Define The Texture We Are Looking For - Change This Variable To Match The Desired Texture You Wish To Delete
lTextureDel = "BlackScreen.png"
##Serach All Textures Within The Scene    
for texture in fb.FBSystem().Scene.Textures:
    ##Look At The Name To See If It Matches The Desired Texture You Wish To Delete
    if texture.Name == lTextureDel:
        ##Delete Texture
        texture.FBDelete()
    ##Skip All Textures That Do Not Match The Desired Texture You Wish To Delete   
    else:
        pass
##Clean Up
del lTextureDel

'''
Delete Textures By File Type
'''
##Define The Texture We Are Looking For - Change This Variable To Match The Desired Texture You Wish To Delete
lTextureExtDel = ".jpg"
##Create An Empty Texture List
lTextureLst = []
##Serach All Textures Within The Scene    
for texture in fb.FBSystem().Scene.Textures:
    ##Look At The Name To See If It Matches The Desired Texture You Wish To Delete
    if lTextureExtDel in texture.Name:
        ##Add Texture To Texture List
        lTextureLst.extend([texture])
    ##Skip All Textures That Do Not Match The Desired Texture You Wish To Delete   
    else:
        pass
for texture in lTextureLst:
    texture.FBDelete()
##Clean Up
del lTextureExtDel, lTextureLst

Return to index

FBDelete() Video

'''
================================================================
FBDelete Videos By Name, File Extention Selected And All Videos Within The Scene
================================================================
'''

'''
Delete All Videos
'''
##Create An Empty Video List
lVideoLst = []
##Serach All Videos Within The Scene    
for media in fb.FBSystem().Scene.VideoClips:
    ##Skip The Default Video
    if media.Name == "Default Shader": pass
    ##Add Video To Our Video List
    else: lVideoLst.extend ([media])
##Go Through Each Video In Our Video List    
for media in lVideoLst:
    ##Delete Video
    media.FBDelete()
##Clean Up
del lVideoLst

'''
Delete Selected Videos
'''
##Create An Empty Video List
lVideoLst = []
##Serach All Videos Within The Scene    
for media in fb.FBSystem().Scene.VideoClips:
    ##Videos That Are Selected
    if media.Selected == True:
        ##Skip The Default Video
        if media.Name == "Default Shader": pass
        ##Add Video To Our Video List
        else: lVideoLst.extend ([media])
    ##Skip Videos That Are Not Selected    
    else: pass
##Go Through Each Video In Our Video List    
for media in lVideoLst:
    ##Delete Video
    media.FBDelete()
##Clean Up
del lVideoLst

'''
Delete Videos By Name
'''
##Define The Video We Are Looking For - Change This Variable To Match The Desired Video You Wish To Delete
lVideoDel = "BlackScreen.png"
##Serach All Videos Within The Scene    
for media in fb.FBSystem().Scene.VideoClips:
    ##Look At The Name To See If It Matches The Desired Video You Wish To Delete
    if media.Name == lVideoDel:
        ##Delete Video
        media.FBDelete()
    ##Skip All Videos That Do Not Match The Desired Video You Wish To Delete   
    else:
        pass
##Clean Up
del lVideoDel

'''
Delete Videos By File Type
'''
##Define The Video We Are Looking For - Change This Variable To Match The Desired Video You Wish To Delete
lVideoExtDel = ".jpg"
##Create An Empty Video List
lVideoLst = []
##Serach All Videos Within The Scene    
for media in fb.FBSystem().Scene.VideoClips:
    ##Look At The Name To See If It Matches The Desired Video You Wish To Delete
    if lVideoExtDel in media.Name:
        ##Add Video To Video List
        lVideoLst.extend([media])
    ##Skip All Videos That Do Not Match The Desired Video You Wish To Delete   
    else:
        pass
for media in lVideoLst:
    media.FBDelete()
##Clean Up
del lVideoExtDel, lVideoLst

Return to index

Like I mentioned the scripts are pretty repetitive, we search the scene, than create a list with all that is found and once done we take all that is on the list and delete them using the “.FBDelete()”.

My next post will cover pretty much the same topic but in the next example we will be creating a list of scene components, and then processing that list to create a list of thing I wish to delete. You will be able to find it here.

I hope this helps.

Add a Comment

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