Skip to content

Instantly share code, notes, and snippets.

@BigRoy
Last active June 7, 2019 13:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BigRoy/636917dc1918221ef5a05fa8a65c5f77 to your computer and use it in GitHub Desktop.
Save BigRoy/636917dc1918221ef5a05fa8a65c5f77 to your computer and use it in GitHub Desktop.
Example pseudocode to collect dependencies and publish them in Avalon database
"""Example pseudocode to collect dependencies and publish them in Avalon database.
- Collect dependencies of what is included/used as representation at time of publish (example shows Maya implementation)
- Store in database under version[data][dependencies]
- Debug print dependencies for a representation (see psuedocode at end)
"""
import maya.cmds as mc
import avalon.api as api
def collect_container_dependencies(nodes):
"""Collect loaded container dependencies from nodes
This will return any loaded Avalon container that
contains at least one of the nodes. As such, the
Avalon container is a dependency. Or in short,
there are member nodes of that container.
Returns:
list: Depending avalon containers
"""
# Lookup by node ids
lookup = frozenset(mc.ls(nodes, uuid=True))
dependencies = []
host = api.registered_host()
for container in host.ls():
node = container["objectName"]
members = mc.sets(node, query=True)
members_uuid = mc.ls(members, uuid=True)
# If there's an intersection
if not lookup.isdisjoint(members_uuid):
dependencies.append(container)
return dependencies
for x in collect_container_dependencies(mc.ls(sl=1)):
# Print the dependent loaded representation for a current selection in Maya
print x["representation"]
# todo: now collect this information as we publish (collect_dependencies.py)
# todo: publish list or dependendent representations into the database as version.data["dependencies"] (integrate.py)
# then after we've published representations we can print our dependencies for a representation
def print_dependencies(representation, depth=0):
"""Psuedocode to print dependencies
Prints:
5ced48f4a33d24abab7fb467
'-- 5c123e63c479bb328472cb4b
'-- 59ede406bda2cb8f634a0bea
'-- 54zfe406kio2ilofa34a0cad
'-- 54zfe406kio2ilofa34a0cad
"""
# Print current entry
indent = 0
if depth != 0:
indent = (" " * depth) + "'--"
print(indent + representation["_id"])
# Print dependencies
dependencies = representation.get("dependencies", [])
for dependency in dependencies:
print_dependencies(dependency, depth + 1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment