mirror of
https://github.com/ynput/ayon-core.git
synced 2026-01-01 16:34:53 +01:00
add loaded containers to published instance
This commit is contained in:
parent
8234529813
commit
1aecfef38a
4 changed files with 95 additions and 1 deletions
|
|
@ -1,9 +1,11 @@
|
|||
import os
|
||||
from maya import cmds
|
||||
from avalon import api
|
||||
from avalon.pipeline import AVALON_CONTAINER_ID
|
||||
from openpype.api import get_project_settings
|
||||
from openpype.lib import get_creator_by_name
|
||||
import openpype.hosts.maya.api.plugin
|
||||
from openpype.hosts.maya.api.pipeline import AVALON_CONTAINERS
|
||||
from openpype.hosts.maya.api.lib import maintained_selection
|
||||
|
||||
|
||||
|
|
@ -125,6 +127,11 @@ class ReferenceLoader(openpype.hosts.maya.api.plugin.ReferenceLoader):
|
|||
|
||||
return new_nodes
|
||||
|
||||
def load(self, context, name=None, namespace=None, options=None):
|
||||
super(ReferenceLoader, self).load(context, name, namespace, options)
|
||||
# clean containers if present to AVALON_CONTAINERS
|
||||
self._organize_containers(self[:])
|
||||
|
||||
def switch(self, container, representation):
|
||||
self.update(container, representation)
|
||||
|
||||
|
|
@ -158,3 +165,17 @@ class ReferenceLoader(openpype.hosts.maya.api.plugin.ReferenceLoader):
|
|||
options={"useSelection": True},
|
||||
data={"dependencies": dependency}
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def _organize_containers(nodes):
|
||||
# type: (list) -> None
|
||||
for node in nodes:
|
||||
id_attr = "{}.id".format(node)
|
||||
if not cmds.attributeQuery("id", node=node, exists=True):
|
||||
print("-" * 80)
|
||||
print("skipping {}".format(node))
|
||||
continue
|
||||
if cmds.getAttr(id_attr) == AVALON_CONTAINER_ID:
|
||||
print("=" * 80)
|
||||
print("moving {}".format(node))
|
||||
cmds.sets(node, forceElement=AVALON_CONTAINERS)
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ from maya import cmds
|
|||
|
||||
import openpype.api
|
||||
from openpype.hosts.maya.api.lib import maintained_selection
|
||||
from avalon.pipeline import AVALON_CONTAINER_ID
|
||||
|
||||
|
||||
class ExtractMayaSceneRaw(openpype.api.Extractor):
|
||||
|
|
@ -57,10 +58,22 @@ class ExtractMayaSceneRaw(openpype.api.Extractor):
|
|||
else:
|
||||
members = instance[:]
|
||||
|
||||
loaded_containers = None
|
||||
if {f.lower() for f in self.add_for_families}.intersection(
|
||||
{f.lower() for f in instance.data.get("families")},
|
||||
{instance.data.get("family").lower()},
|
||||
):
|
||||
loaded_containers = self._add_loaded_containers(members)
|
||||
|
||||
selection = members
|
||||
if loaded_containers:
|
||||
self.log.info(loaded_containers)
|
||||
selection += loaded_containers
|
||||
|
||||
# Perform extraction
|
||||
self.log.info("Performing extraction ...")
|
||||
with maintained_selection():
|
||||
cmds.select(members, noExpand=True)
|
||||
cmds.select(selection, noExpand=True)
|
||||
cmds.file(path,
|
||||
force=True,
|
||||
typ="mayaAscii" if self.scene_type == "ma" else "mayaBinary", # noqa: E501
|
||||
|
|
@ -83,3 +96,33 @@ class ExtractMayaSceneRaw(openpype.api.Extractor):
|
|||
instance.data["representations"].append(representation)
|
||||
|
||||
self.log.info("Extracted instance '%s' to: %s" % (instance.name, path))
|
||||
|
||||
@staticmethod
|
||||
def _add_loaded_containers(members):
|
||||
# type: (list) -> list
|
||||
refs_to_include = [
|
||||
cmds.referenceQuery(ref, referenceNode=True)
|
||||
for ref in members
|
||||
if cmds.referenceQuery(ref, isNodeReferenced=True)
|
||||
]
|
||||
|
||||
refs_to_include = set(refs_to_include)
|
||||
|
||||
obj_sets = cmds.ls("*.id", long=True, type="objectSet", recursive=True,
|
||||
objectsOnly=True)
|
||||
|
||||
loaded_containers = []
|
||||
for obj_set in obj_sets:
|
||||
|
||||
if not cmds.attributeQuery("id", node=obj_set, exists=True):
|
||||
continue
|
||||
|
||||
id_attr = "{}.id".format(obj_set)
|
||||
if cmds.getAttr(id_attr) != AVALON_CONTAINER_ID:
|
||||
continue
|
||||
|
||||
set_content = set(cmds.sets(obj_set, query=True))
|
||||
if set_content.intersection(refs_to_include):
|
||||
loaded_containers.append(obj_set)
|
||||
|
||||
return loaded_containers
|
||||
|
|
|
|||
|
|
@ -502,6 +502,12 @@
|
|||
}
|
||||
}
|
||||
},
|
||||
"ExtractMayaSceneRaw": {
|
||||
"enabled": true,
|
||||
"add_for_families": [
|
||||
"layout"
|
||||
]
|
||||
},
|
||||
"ExtractCameraAlembic": {
|
||||
"enabled": true,
|
||||
"optional": true,
|
||||
|
|
|
|||
|
|
@ -547,6 +547,30 @@
|
|||
"type": "schema",
|
||||
"name": "schema_maya_capture"
|
||||
},
|
||||
{
|
||||
"type": "dict",
|
||||
"collapsible": true,
|
||||
"key": "ExtractMayaSceneRaw",
|
||||
"label": "Maya Scene (Raw)",
|
||||
"checkbox_key": "enabled",
|
||||
"children": [
|
||||
{
|
||||
"type": "boolean",
|
||||
"key": "enabled",
|
||||
"label": "Enabled"
|
||||
},
|
||||
{
|
||||
"type": "label",
|
||||
"label": "Add loaded instances to those published families:"
|
||||
},
|
||||
{
|
||||
"key": "add_for_families",
|
||||
"label": "Families",
|
||||
"type": "list",
|
||||
"object_type": "text"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "dict",
|
||||
"collapsible": true,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue