# Copyright 2009 Autodesk, Inc.  All rights reserved.
# Use of this software is subject to the terms of the Autodesk license agreement 
# provided at the time of installation or download, or which otherwise accompanies
# this software in either electronic or hard copy form.
#
# Topic: FBTexture, FBScene, FBVideo
#

from pyfbsdk import FBSystem, FBComponent

lSystem = FBSystem()

# Since the videos are parented to textures, we need to removed unused
# textures before removing the unused videos.

# Delete any texture whose only parent is Scene.
lList = [ lTexture for lTexture in lSystem.Scene.Textures if (len( lTexture.Parents ) == 1 and lTexture.Parents[0].Name=="Scene") ]
map( FBComponent.FBDelete, lList )

# Delete any VideoClip whose only parent is Scene.
lList = [ lMedia for lMedia in lSystem.Scene.VideoClips if (len( lMedia.Parents ) == 1 and lMedia.Parents[0].Name=="Scene") ]
map( FBComponent.FBDelete, lList )


# Cleanup

# Conditional cleanup
if dir().__contains__( 'lTexture' ): del( lTexture )
if dir().__contains__( 'lMedia' ): del( lMedia )

# Cleanup local variables
del( lSystem, lList )

# Cleanup things from pyfbsdk
del( FBSystem, FBComponent )