mirror of
https://github.com/ynput/ayon-core.git
synced 2025-12-26 05:42:15 +01:00
global,nuke,maya: on demand placeholder removal preset attribute
This commit is contained in:
parent
5bda706df7
commit
95b15a9f00
4 changed files with 62 additions and 15 deletions
|
|
@ -28,7 +28,7 @@ class MayaTemplateBuilder(AbstractTemplateBuilder):
|
|||
|
||||
Args:
|
||||
path (str): A path to current template (usually given by
|
||||
get_template_path implementation)
|
||||
get_template_preset implementation)
|
||||
|
||||
Returns:
|
||||
bool: Wether the template was succesfully imported or not
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ class NukeTemplateBuilder(AbstractTemplateBuilder):
|
|||
|
||||
Args:
|
||||
path (str): A path to current template (usually given by
|
||||
get_template_path implementation)
|
||||
get_template_preset implementation)
|
||||
|
||||
Returns:
|
||||
bool: Wether the template was succesfully imported or not
|
||||
|
|
@ -273,6 +273,15 @@ class NukePlaceholderLoadPlugin(NukePlaceholderPlugin, PlaceholderLoadMixin):
|
|||
|
||||
placeholder.data["nb_children"] += 1
|
||||
reset_selection()
|
||||
|
||||
# remove placeholders marked as delete
|
||||
if (
|
||||
placeholder.data.get("delete")
|
||||
and not placeholder.data.get("keep_placeholder")
|
||||
):
|
||||
self.log.debug("Deleting node: {}".format(placeholder_node.name()))
|
||||
nuke.delete(placeholder_node)
|
||||
|
||||
# go back to root group
|
||||
nuke.root().begin()
|
||||
|
||||
|
|
@ -454,12 +463,12 @@ class NukePlaceholderLoadPlugin(NukePlaceholderPlugin, PlaceholderLoadMixin):
|
|||
)
|
||||
for node in placeholder_node.dependent():
|
||||
for idx in range(node.inputs()):
|
||||
if node.input(idx) == placeholder_node:
|
||||
if node.input(idx) == placeholder_node and output_node:
|
||||
node.setInput(idx, output_node)
|
||||
|
||||
for node in placeholder_node.dependencies():
|
||||
for idx in range(placeholder_node.inputs()):
|
||||
if placeholder_node.input(idx) == node:
|
||||
if placeholder_node.input(idx) == node and input_node:
|
||||
input_node.setInput(0, node)
|
||||
|
||||
def _create_sib_copies(self, placeholder):
|
||||
|
|
|
|||
|
|
@ -401,7 +401,12 @@ class AbstractTemplateBuilder(object):
|
|||
key=lambda i: i.order
|
||||
))
|
||||
|
||||
def build_template(self, template_path=None, level_limit=None):
|
||||
def build_template(
|
||||
self,
|
||||
template_path=None,
|
||||
level_limit=None,
|
||||
keep_placeholders=None
|
||||
):
|
||||
"""Main callback for building workfile from template path.
|
||||
|
||||
Todo:
|
||||
|
|
@ -410,16 +415,22 @@ class AbstractTemplateBuilder(object):
|
|||
|
||||
Args:
|
||||
template_path (str): Path to a template file with placeholders.
|
||||
Template from settings 'get_template_path' used when not
|
||||
Template from settings 'get_template_preset' used when not
|
||||
passed.
|
||||
level_limit (int): Limit of populate loops. Related to
|
||||
'populate_scene_placeholders' method.
|
||||
"""
|
||||
template_preset = self.get_template_preset()
|
||||
|
||||
if template_path is None:
|
||||
template_path = self.get_template_path()
|
||||
template_path = template_preset["path"]
|
||||
|
||||
if keep_placeholders is None:
|
||||
keep_placeholders = template_preset["placeholder_keep"]
|
||||
|
||||
self.import_template(template_path)
|
||||
self.populate_scene_placeholders(level_limit)
|
||||
self.populate_scene_placeholders(
|
||||
level_limit, keep_placeholders)
|
||||
|
||||
def rebuild_template(self):
|
||||
"""Go through existing placeholders in scene and update them.
|
||||
|
|
@ -489,7 +500,9 @@ class AbstractTemplateBuilder(object):
|
|||
plugin = plugins_by_identifier[identifier]
|
||||
plugin.prepare_placeholders(placeholders)
|
||||
|
||||
def populate_scene_placeholders(self, level_limit=None):
|
||||
def populate_scene_placeholders(
|
||||
self, level_limit=None, keep_placeholders=None
|
||||
):
|
||||
"""Find placeholders in scene using plugins and process them.
|
||||
|
||||
This should happen after 'import_template'.
|
||||
|
|
@ -541,6 +554,11 @@ class AbstractTemplateBuilder(object):
|
|||
" is already in progress."
|
||||
))
|
||||
continue
|
||||
|
||||
# add flag for keeping placeholders in scene
|
||||
# after they are processed
|
||||
placeholder.data["keep_placeholder"] = keep_placeholders
|
||||
|
||||
filtered_placeholders.append(placeholder)
|
||||
|
||||
self._prepare_placeholders(filtered_placeholders)
|
||||
|
|
@ -599,8 +617,8 @@ class AbstractTemplateBuilder(object):
|
|||
["profiles"]
|
||||
)
|
||||
|
||||
def get_template_path(self):
|
||||
"""Unified way how template path is received usign settings.
|
||||
def get_template_preset(self):
|
||||
"""Unified way how template preset is received usign settings.
|
||||
|
||||
Method is dependent on '_get_build_profiles' which should return filter
|
||||
profiles to resolve path to a template. Default implementation looks
|
||||
|
|
@ -637,6 +655,13 @@ class AbstractTemplateBuilder(object):
|
|||
).format(task_name, task_type, host_name))
|
||||
|
||||
path = profile["path"]
|
||||
|
||||
# switch to remove placeholders after they are used
|
||||
placeholder_keep = profile.get("placeholder_keep")
|
||||
# backward compatibility, since default is True
|
||||
if placeholder_keep is not False:
|
||||
placeholder_keep = True
|
||||
|
||||
if not path:
|
||||
raise TemplateLoadFailed((
|
||||
"Template path is not set.\n"
|
||||
|
|
@ -657,7 +682,10 @@ class AbstractTemplateBuilder(object):
|
|||
|
||||
if path and os.path.exists(path):
|
||||
self.log.info("Found template at: '{}'".format(path))
|
||||
return path
|
||||
return {
|
||||
"path": path,
|
||||
"placeholder_keep": placeholder_keep
|
||||
}
|
||||
|
||||
solved_path = None
|
||||
while True:
|
||||
|
|
@ -683,7 +711,10 @@ class AbstractTemplateBuilder(object):
|
|||
|
||||
self.log.info("Found template at: '{}'".format(solved_path))
|
||||
|
||||
return solved_path
|
||||
return {
|
||||
"path": solved_path,
|
||||
"placeholder_keep": placeholder_keep
|
||||
}
|
||||
|
||||
|
||||
@six.add_metaclass(ABCMeta)
|
||||
|
|
|
|||
|
|
@ -25,8 +25,15 @@
|
|||
{
|
||||
"key": "path",
|
||||
"label": "Path to template",
|
||||
"type": "text",
|
||||
"object_type": "text"
|
||||
"type": "path",
|
||||
"multiplatform": false,
|
||||
"multipath": false
|
||||
},
|
||||
{
|
||||
"key": "placeholder_keep",
|
||||
"label": "Keep placeholders",
|
||||
"type": "boolean",
|
||||
"default": true
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue