Skip to content

Instantly share code, notes, and snippets.

Created July 24, 2018 11:57
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save mattcox/3ac9a8547ac379482a6e4e9b57979d09 to your computer and use it in GitHub Desktop.
Collect reference items in the selected scene.
class ReferencedItems:
def __init__(self, scene):
self.mScene = lx.object.Scene(scene)
self.mSceneFilename = self.mScene.Filename()
self.mItems = []
def AddItem(self, item):
print item
def Scene(self):
return self.mScene
def ItemCount(self):
return len(self.mItems)
def ItemByIndex(self, index):
if index < self.ItemCount():
return self.mItems[index]
return None
def getReferenceScenesAndItems(scene):
references = {}
itemCount = scene.ItemCount(-1)
for i in range(itemCount):
item = scene.ItemByIndex(-1, i)
# Get the referenced item source. If it's not a reference, an exception will be thrown.
sourceItem = item.Reference()
# Get the source item scene (Context) and get the scene filename.
filename = sourceItem.Context().Filename()
# Lookup the ReferencedItem class in the dictionary, and store the reference item in it.
if False == references.has_key(filename):
referenceItems = ReferencedItems(sourceItem.Context())
references[filename] = referenceItems
return references
# Get the items referenced into the currently selected scene.
referenceScenes = getReferenceScenesAndItems(
for referenceFilepath in referenceScenes:
referenceItems = referenceScenes[referenceFilepath]
print "Scene: " + str(referenceItems.Scene()) + " (" + referenceFilepath + ")"
print "Item Count: " + str(referenceItems.ItemCount())
print "Items:"
for i in range(referenceItems.ItemCount()):
print " " + referenceItems.ItemByIndex(i).UniqueName()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment