global, nuke: adding support for first workfile creation

This commit is contained in:
Jakub Jezek 2023-03-06 16:55:05 +01:00
parent 0993fa447d
commit b2eb14914b
No known key found for this signature in database
GPG key ID: 730D7C02726179A7
5 changed files with 39 additions and 21 deletions

View file

@ -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.