mirror of
https://github.com/ynput/ayon-core.git
synced 2025-12-24 21:04:40 +01:00
global, nuke: adding support for first workfile creation
This commit is contained in:
parent
0993fa447d
commit
b2eb14914b
5 changed files with 39 additions and 21 deletions
|
|
@ -2682,11 +2682,12 @@ def start_workfile_template_builder():
|
|||
build_workfile_template
|
||||
)
|
||||
|
||||
# to avoid looping of the callback, remove it!
|
||||
# nuke.removeOnCreate(start_workfile_template_builder, nodeClass="Root")
|
||||
log.info("Starting workfile template builder...")
|
||||
build_workfile_template(run_from_callback=True)
|
||||
|
||||
# to avoid looping of the callback, remove it!
|
||||
log.info("Starting workfile template builder...")
|
||||
build_workfile_template(workfile_creation_enabled=True)
|
||||
|
||||
nuke.removeOnCreate(start_workfile_template_builder, nodeClass="Root")
|
||||
|
||||
@deprecated
|
||||
def recreate_instance(origin_node, avalon_data=None):
|
||||
|
|
|
|||
|
|
@ -155,8 +155,8 @@ def add_nuke_callbacks():
|
|||
# Set context settings.
|
||||
nuke.addOnCreate(
|
||||
workfile_settings.set_context_settings, nodeClass="Root")
|
||||
nuke.addOnCreate(start_workfile_template_builder, nodeClass="Root")
|
||||
nuke.addOnCreate(workfile_settings.set_favorites, nodeClass="Root")
|
||||
nuke.addOnCreate(start_workfile_template_builder, nodeClass="Root")
|
||||
nuke.addOnCreate(process_workfile_builder, nodeClass="Root")
|
||||
|
||||
# fix ffmpeg settings on script
|
||||
|
|
|
|||
|
|
@ -56,7 +56,6 @@ class NukeTemplateBuilder(AbstractTemplateBuilder):
|
|||
|
||||
return True
|
||||
|
||||
|
||||
class NukePlaceholderPlugin(PlaceholderPlugin):
|
||||
node_color = 4278190335
|
||||
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ def has_unsaved_changes():
|
|||
|
||||
def save_file(filepath):
|
||||
path = filepath.replace("\\", "/")
|
||||
nuke.scriptSaveAs(path)
|
||||
nuke.scriptSaveAs(path, overwrite=1)
|
||||
nuke.Root()["name"].setValue(path)
|
||||
nuke.Root()["project_directory"].setValue(os.path.dirname(path))
|
||||
nuke.Root().setModified(False)
|
||||
|
|
|
|||
|
|
@ -443,7 +443,7 @@ class AbstractTemplateBuilder(object):
|
|||
level_limit=None,
|
||||
keep_placeholders=None,
|
||||
create_first_version=None,
|
||||
run_from_callback=False
|
||||
workfile_creation_enabled=False
|
||||
):
|
||||
"""Main callback for building workfile from template path.
|
||||
|
||||
|
|
@ -461,7 +461,7 @@ class AbstractTemplateBuilder(object):
|
|||
hosts to decide if they want to remove
|
||||
placeholder after it is used.
|
||||
create_first_version (bool): create first version of a workfile
|
||||
run_from_callback (bool): If True, it might create first version
|
||||
workfile_creation_enabled (bool): If True, it might create first version
|
||||
but ignore process if version is created
|
||||
|
||||
"""
|
||||
|
|
@ -475,13 +475,25 @@ class AbstractTemplateBuilder(object):
|
|||
if create_first_version is None:
|
||||
create_first_version = template_preset["create_first_version"]
|
||||
|
||||
# run creation of first version only if it is
|
||||
# run from callback and no new version is created
|
||||
first_creation = False
|
||||
if create_first_version and run_from_callback:
|
||||
first_creation = not self.create_first_workfile_version()
|
||||
# check if first version is created
|
||||
created_version_workfile = self.create_first_workfile_version()
|
||||
|
||||
if first_creation:
|
||||
# if first version is created, import template and populate placeholders
|
||||
if (
|
||||
create_first_version
|
||||
and workfile_creation_enabled
|
||||
and created_version_workfile
|
||||
):
|
||||
self.import_template(template_path)
|
||||
self.populate_scene_placeholders(
|
||||
level_limit, keep_placeholders)
|
||||
|
||||
# save workfile after template is populated
|
||||
self.save_workfile(created_version_workfile)
|
||||
|
||||
# ignore process if first workfile is enabled
|
||||
# but a version is already created
|
||||
if workfile_creation_enabled:
|
||||
return
|
||||
|
||||
self.import_template(template_path)
|
||||
|
|
@ -546,20 +558,26 @@ class AbstractTemplateBuilder(object):
|
|||
host's template file.
|
||||
"""
|
||||
last_workfile_path = os.environ.get("AVALON_LAST_WORKFILE")
|
||||
self.log.info("__ last_workfile_path: {}".format(last_workfile_path))
|
||||
if os.path.exists(last_workfile_path):
|
||||
# ignore in case workfile existence
|
||||
self.log.info("Workfile already exists, skipping creation.")
|
||||
return False
|
||||
|
||||
# Save current scene, continue to open file
|
||||
if isinstance(self.host, IWorkfileHost):
|
||||
self.host.save_workfile(last_workfile_path)
|
||||
else:
|
||||
self.host.save_file(last_workfile_path)
|
||||
# Create first version
|
||||
self.log.info("Creating first version of workfile.")
|
||||
self.save_workfile(last_workfile_path)
|
||||
|
||||
# Confirm creation of first version
|
||||
return True
|
||||
return last_workfile_path
|
||||
|
||||
def save_workfile(self, workfile_path):
|
||||
"""Save workfile in current host."""
|
||||
# Save current scene, continue to open file
|
||||
if isinstance(self.host, IWorkfileHost):
|
||||
self.host.save_workfile(workfile_path)
|
||||
else:
|
||||
self.host.save_file(workfile_path)
|
||||
|
||||
def _prepare_placeholders(self, placeholders):
|
||||
"""Run preparation part for placeholders on plugins.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue