master container is now with the namespace

This commit is contained in:
Kayla Man 2023-08-17 21:22:34 +08:00
parent 8345298913
commit b2a6e16ae8
11 changed files with 134 additions and 14 deletions

View file

@ -6,7 +6,7 @@ from typing import Any, Dict, Union
import six
from openpype.pipeline.context_tools import (
get_current_project, get_current_project_asset,)
get_current_project, get_current_project_asset)
from pymxs import runtime as rt
JSON_PREFIX = "JSON::"
@ -312,3 +312,59 @@ def set_timeline(frameStart, frameEnd):
"""
rt.animationRange = rt.interval(frameStart, frameEnd)
return rt.animationRange
def unique_namespace(namespace, format="%02d",
prefix="", suffix="", con_suffix="CON"):
from pymxs import runtime as rt
"""Return unique namespace
Arguments:
namespace (str): Name of namespace to consider
format (str, optional): Formatting of the given iteration number
suffix (str, optional): Only consider namespaces with this suffix.
con_suffix: max only, for finding the name of the master container
>>> unique_namespace("bar")
# bar01
>>> unique_namespace(":hello")
# :hello01
>>> unique_namespace("bar:", suffix="_NS")
# bar01_NS:
"""
def current_namespace():
current = namespace
# When inside a namespace Maya adds no trailing :
if not current.endswith(":"):
current += ":"
return current
# Always check against the absolute namespace root
# There's no clash with :x if we're defining namespace :a:x
ROOT = ":" if namespace.startswith(":") else current_namespace()
# Strip trailing `:` tokens since we might want to add a suffix
start = ":" if namespace.startswith(":") else ""
end = ":" if namespace.endswith(":") else ""
namespace = namespace.strip(":")
if ":" in namespace:
# Split off any nesting that we don't uniqify anyway.
parents, namespace = namespace.rsplit(":", 1)
start += parents + ":"
ROOT += start
iteration = 1
increment_version = True
while increment_version:
nr_namespace = namespace + format % iteration
unique = prefix + nr_namespace + suffix
container_name = f"{unique}:{namespace}{con_suffix}"
if not rt.getNodeByName(container_name):
name_space = start + unique + end
increment_version = False
return name_space
else:
increment_version = True
iteration +=1

View file

@ -154,17 +154,18 @@ def ls() -> list:
yield lib.read(container)
def containerise(name: str, nodes: list, context, loader=None, suffix="_CON"):
def containerise(name: str, nodes: list, context,
namespace=None, loader=None, suffix="_CON"):
data = {
"schema": "openpype:container-2.0",
"id": AVALON_CONTAINER_ID,
"name": name,
"namespace": "",
"namespace": namespace,
"loader": loader,
"representation": context["representation"]["_id"],
}
container_name = f"{name}{suffix}"
container_name = f"{namespace}:{name}{suffix}"
container = rt.container(name=container_name)
for node in nodes:
node.Parent = container

View file

@ -1,6 +1,7 @@
import os
from openpype.hosts.max.api import lib, maintained_selection
from openpype.hosts.max.api.lib import unique_namespace
from openpype.hosts.max.api.pipeline import (
containerise,
import_custom_attribute_data,
@ -38,8 +39,14 @@ class FbxLoader(load.LoaderPlugin):
for selection in selections:
selection.Parent = container
namespace = unique_namespace(
name + "_",
suffix="_",
)
return containerise(
name, [container], context, loader=self.__class__.__name__)
name, [container], context,
namespace, loader=self.__class__.__name__)
def update(self, container, representation):
from pymxs import runtime as rt

View file

@ -1,6 +1,7 @@
import os
from openpype.hosts.max.api import lib
from openpype.hosts.max.api.lib import unique_namespace
from openpype.hosts.max.api.pipeline import (
containerise, import_custom_attribute_data,
update_custom_attribute_data
@ -34,8 +35,15 @@ class MaxSceneLoader(load.LoaderPlugin):
import_custom_attribute_data(container, max_objects)
max_container.append(container)
max_container.extend(max_objects)
namespace = unique_namespace(
name + "_",
suffix="_",
)
return containerise(
name, max_container, context, loader=self.__class__.__name__)
name, max_container, context,
namespace, loader=self.__class__.__name__)
def update(self, container, representation):
from pymxs import runtime as rt

View file

@ -6,7 +6,9 @@ from openpype.hosts.max.api.pipeline import (
update_custom_attribute_data
)
from openpype.hosts.max.api import lib
from openpype.hosts.max.api.lib import maintained_selection
from openpype.hosts.max.api.lib import (
maintained_selection, unique_namespace
)
class ModelAbcLoader(load.LoaderPlugin):
@ -51,8 +53,15 @@ class ModelAbcLoader(load.LoaderPlugin):
abc_container = abc_containers.pop()
import_custom_attribute_data(
abc_container, abc_container.Children)
namespace = unique_namespace(
name + "_",
suffix="_",
)
return containerise(
name, [abc_container], context, loader=self.__class__.__name__
name, [abc_container], context,
namespace, loader=self.__class__.__name__
)
def update(self, container, representation):

View file

@ -4,6 +4,7 @@ from openpype.hosts.max.api.pipeline import (
containerise, import_custom_attribute_data, update_custom_attribute_data
)
from openpype.hosts.max.api import lib
from openpype.hosts.max.api.lib import unique_namespace
from openpype.hosts.max.api.lib import maintained_selection
@ -36,8 +37,13 @@ class FbxModelLoader(load.LoaderPlugin):
for selection in selections:
selection.Parent = container
namespace = unique_namespace(
name + "_",
suffix="_",
)
return containerise(
name, [container], context, loader=self.__class__.__name__
name, [container], context,
namespace, loader=self.__class__.__name__
)
def update(self, container, representation):

View file

@ -1,6 +1,7 @@
import os
from openpype.hosts.max.api import lib
from openpype.hosts.max.api.lib import unique_namespace
from openpype.hosts.max.api.lib import maintained_selection
from openpype.hosts.max.api.pipeline import (
containerise,
@ -34,8 +35,13 @@ class ObjLoader(load.LoaderPlugin):
for selection in selections:
selection.Parent = container
namespace = unique_namespace(
name + "_",
suffix="_",
)
return containerise(
name, [container], context, loader=self.__class__.__name__)
name, [container], context,
namespace, loader=self.__class__.__name__)
def update(self, container, representation):
from pymxs import runtime as rt

View file

@ -1,6 +1,7 @@
import os
from openpype.hosts.max.api import lib
from openpype.hosts.max.api.lib import unique_namespace
from openpype.hosts.max.api.lib import maintained_selection
from openpype.hosts.max.api.pipeline import (
containerise,
@ -38,8 +39,14 @@ class ModelUSDLoader(load.LoaderPlugin):
import_custom_attribute_data(asset, asset.Children)
namespace = unique_namespace(
name + "_",
suffix="_",
)
return containerise(
name, [asset], context, loader=self.__class__.__name__)
name, [asset], context,
namespace, loader=self.__class__.__name__)
def update(self, container, representation):
from pymxs import runtime as rt

View file

@ -7,6 +7,7 @@ Because of limited api, alembics can be only loaded, but not easily updated.
import os
from openpype.pipeline import load, get_representation_path
from openpype.hosts.max.api import lib, maintained_selection
from openpype.hosts.max.api.lib import unique_namespace
from openpype.hosts.max.api.pipeline import (
containerise,
import_custom_attribute_data,
@ -59,9 +60,14 @@ class AbcLoader(load.LoaderPlugin):
for cam_shape in abc.Children:
cam_shape.playbackType = 2
namespace = unique_namespace(
name + "_",
suffix="_",
)
return containerise(
name, [abc_container], context, loader=self.__class__.__name__
name, [abc_container], context,
namespace, loader=self.__class__.__name__
)
def update(self, container, representation):

View file

@ -1,6 +1,7 @@
import os
from openpype.hosts.max.api import lib, maintained_selection
from openpype.hosts.max.api.lib import unique_namespace
from openpype.hosts.max.api.pipeline import (
containerise,
import_custom_attribute_data,
@ -31,8 +32,14 @@ class PointCloudLoader(load.LoaderPlugin):
obj.Parent = prt_container
import_custom_attribute_data(prt_container, [obj])
namespace = unique_namespace(
name + "_",
suffix="_",
)
return containerise(
name, [prt_container], context, loader=self.__class__.__name__)
name, [prt_container], context,
namespace, loader=self.__class__.__name__)
def update(self, container, representation):
"""update the container"""

View file

@ -11,6 +11,7 @@ from openpype.hosts.max.api.pipeline import (
update_custom_attribute_data
)
from openpype.hosts.max.api import lib
from openpype.hosts.max.api.lib import unique_namespace
class RedshiftProxyLoader(load.LoaderPlugin):
@ -40,8 +41,14 @@ class RedshiftProxyLoader(load.LoaderPlugin):
import_custom_attribute_data(container, [rs_proxy])
asset = rt.getNodeByName(name)
namespace = unique_namespace(
name + "_",
suffix="_",
)
return containerise(
name, [asset], context, loader=self.__class__.__name__)
name, [asset], context,
namespace, loader=self.__class__.__name__)
def update(self, container, representation):
from pymxs import runtime as rt