Remove unused image clips

From The Foundry MODO SDK wiki
Jump to: navigation, search

Description:

Example for finding unused image clips and deleting them from the Scene

Code:

################################################################################
#
# RemoveUnusedClips.py
#
# Version: 1
#
# Author: Ivo Grigull
#
# Description: Example for finding unused image clips and deleting them from 
# the Scene using the TD SDK
#
################################################################################
 
import lx
import lxifc
import lxu.command
import modo
 
 
class CmdMyCustomCommand(lxu.command.BasicCommand):
 
    def __init__(self):
        lxu.command.BasicCommand.__init__(self)
 
    def cmd_Flags(self):
        return lx.symbol.fCMD_MODEL {{!}} lx.symbol.fCMD_UNDO
 
    def basic_Enable(self, msg):
        return True
 
    def basic_Execute(self, msg, flags):
 
        scn = modo.Scene()
 
        # Loop through all image clips
        for imageClip in scn.items( itype=lx.symbol.sITYPE_VIDEOSTILL ):
 
            # We will get the 'shadeLoc' graph and check if there are any connections.
            graph = imageClip.itemGraph('shadeLoc')
 
            # If no connections are found for this graph, we delete the clip item from the scene.
            if len(graph.forward()) is 0 and len(graph.reverse()) is 0:
 
                lx.out("Deleting clip: %s" % imageClip.name)
                scn.removeItems(imageClip)
 
 
lx.bless(CmdMyCustomCommand, "clip.removeUnused")