Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 43 additions & 6 deletions avalon/maya/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import contextlib

from maya import cmds, OpenMaya
import maya.api.OpenMaya as om
from pyblish import api as pyblish

from . import lib, compat
Expand Down Expand Up @@ -427,6 +428,8 @@ def parse_container(container, validate=True):

Args:
container (str): A container node name.
validate (bool, optional): Whether to validate the container schema.
Defaults to True.

Returns:
dict: The container schema data for this container node.
Expand All @@ -447,21 +450,55 @@ def parse_container(container, validate=True):


def _ls():
containers = list()
for identifier in (AVALON_CONTAINER_ID,
"pyblish.mindbender.container"):
containers += lib.lsattr("id", identifier)
"""Yields Avalon container node names.

return containers
Used by `ls()` to retrieve the nodes and then query the full container's
data.

Yields:
str: Avalon container node name (objectSet)

"""

def _maya_iterate(iterator):
"""Helper to iterate a maya iterator"""
while not iterator.isDone():
yield iterator.thisNode()
iterator.next()

ids = {AVALON_CONTAINER_ID,
# Backwards compatibility
"pyblish.mindbender.container"}

# Iterate over all 'set' nodes in the scene to detect whether
# they have the avalon container ".id" attribute.
fn_dep = om.MFnDependencyNode()
iterator = om.MItDependencyNodes(om.MFn.kSet)
for mobject in _maya_iterate(iterator):
if mobject.apiTypeStr != "kSet":
# Only match by exact type
continue

fn_dep.setObject(mobject)
if not fn_dep.hasAttribute("id"):
continue

plug = fn_dep.findPlug("id", True)
value = plug.asString()
if value in ids:
yield fn_dep.name()


def ls():
"""List containers from active Maya scene
"""Yields containers from active Maya scene

This is the host-equivalent of api.ls(), but instead of listing
assets on disk, it lists assets already loaded in Maya; once loaded
they are called 'containers'

Yields:
dict: container

"""
container_names = _ls()

Expand Down