Skip to content

Commit

Permalink
Merge pull request #330 from BigRoy/enhancement/maya_load_published_w…
Browse files Browse the repository at this point in the history
…orkfile_as_template

Maya: Load published workfile as template
  • Loading branch information
tokejepsen authored Apr 29, 2024
2 parents fdc86c6 + 02f2381 commit 2b76b3d
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 12 deletions.
3 changes: 2 additions & 1 deletion client/ayon_core/hosts/maya/api/workfile_template_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,8 @@ def _parent_in_hierarchy(self, placeholder, container):
if scene_parent:
cmds.parent(node, scene_parent)
else:
cmds.parent(node, world=True)
if cmds.listRelatives(node, parent=True):
cmds.parent(node, world=True)

holding_sets = cmds.listSets(object=placeholder.scene_identifier)
if not holding_sets:
Expand Down
39 changes: 39 additions & 0 deletions client/ayon_core/hosts/maya/plugins/load/load_as_template.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
from ayon_core.lib import (
BoolDef
)
from ayon_core.pipeline import (
load,
registered_host
)
from ayon_core.hosts.maya.api.workfile_template_builder import (
MayaTemplateBuilder
)


class LoadAsTemplate(load.LoaderPlugin):
"""Load workfile as a template """

product_types = {"workfile", "mayaScene"}
label = "Load as template"
representations = ["ma", "mb"]
icon = "wrench"
color = "#775555"
order = 10

options = [
BoolDef("keep_placeholders",
label="Keep Placeholders",
default=False),
BoolDef("create_first_version",
label="Create First Version",
default=False),
]

def load(self, context, name, namespace, data):
keep_placeholders = data.get("keep_placeholders", False)
create_first_version = data.get("create_first_version", False)
path = self.filepath_from_context(context)
builder = MayaTemplateBuilder(registered_host())
builder.build_template(template_path=path,
keep_placeholders=keep_placeholders,
create_first_version=create_first_version)
30 changes: 19 additions & 11 deletions client/ayon_core/pipeline/workfile/workfile_template_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -498,15 +498,21 @@ def build_template(
process if version is created
"""
template_preset = self.get_template_preset()

if template_path is None:
template_path = template_preset["path"]

if keep_placeholders is None:
keep_placeholders = template_preset["keep_placeholder"]
if create_first_version is None:
create_first_version = template_preset["create_first_version"]
if any(
value is None
for value in [
template_path,
keep_placeholders,
create_first_version,
]
):
template_preset = self.get_template_preset()
if template_path is None:
template_path = template_preset["path"]
if keep_placeholders is None:
keep_placeholders = template_preset["keep_placeholder"]
if create_first_version is None:
create_first_version = template_preset["create_first_version"]

# check if first version is created
created_version_workfile = False
Expand Down Expand Up @@ -772,12 +778,14 @@ def get_template_preset(self):
- 'project_settings/{host name}/templated_workfile_build/profiles'
Returns:
str: Path to a template file with placeholders.
dict: Dictionary with `path`, `keep_placeholder` and
`create_first_version` settings from the template preset
for current context.
Raises:
TemplateProfileNotFound: When profiles are not filled.
TemplateLoadFailed: Profile was found but path is not set.
TemplateNotFound: Path was set but file does not exists.
TemplateNotFound: Path was set but file does not exist.
"""

host_name = self.host_name
Expand Down

0 comments on commit 2b76b3d

Please sign in to comment.