diff --git a/avalon/maya/pipeline.py b/avalon/maya/pipeline.py index 498cf078d..31983cf67 100644 --- a/avalon/maya/pipeline.py +++ b/avalon/maya/pipeline.py @@ -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 @@ -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. @@ -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()