Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Collect reference items in the selected scene.
import lxu.select
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
self.mItems.append(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)
try:
# 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())
referenceItems.AddItem(sourceItem)
references[filename] = referenceItems
else:
references[filename].AddItem(sourceItem)
except:
continue
return references
# Get the items referenced into the currently selected scene.
referenceScenes = getReferenceScenesAndItems(lxu.select.SceneSelection().current())
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