Skip to content
Draft
Changes from 2 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
453dc01
enhancement: implement the related attributes for the templated workf…
moonyuet Jun 24, 2026
1342660
Update client/ayon_core/pipeline/workfile/workfile_template_builder.py
moonyuet Jun 24, 2026
a429ae1
wip: use profile changes instead, and implement the changes by hosts.
moonyuet Jun 24, 2026
380b321
revert the change for explcit_build_requested
moonyuet Jun 24, 2026
d3a3e3a
revert the change on the additonal attributes.
moonyuet Jun 24, 2026
9d8d998
revert arguments changes
moonyuet Jun 24, 2026
fcbbf49
revert
moonyuet Jun 24, 2026
b52cbf9
revert the line changes in populate_scene_placeholders
moonyuet Jun 24, 2026
8fb9955
bugfix: make sure building workfile action should be aligning with th…
moonyuet Jun 26, 2026
cfdc41f
Merge remote-tracking branch 'origin/develop' into enhancement/AY-724…
moonyuet Jun 26, 2026
bc10f94
Merge branch 'develop' into enhancement/AY-7243_Template-builder-alwa…
moonyuet Jun 30, 2026
b7451d9
cleanup: remove the redundent condition.
moonyuet Jun 30, 2026
8553813
revert the changes on the removal of explicit_build_requested
moonyuet Jun 30, 2026
f92bf17
revert the change for the build_template code and implement denfensiv…
moonyuet Jul 1, 2026
74369ed
update doctstrings
moonyuet Jul 1, 2026
50fed12
refactor: implement the functions with new dataclass, backward compat…
moonyuet Jul 2, 2026
6da9537
ruff fix
moonyuet Jul 2, 2026
1e69afc
ruff fix
moonyuet Jul 2, 2026
91a949c
improve the backward compatibility function
moonyuet Jul 2, 2026
e3b3ea4
add the getter function for create first version.
moonyuet Jul 3, 2026
bff9133
set the default values of keep_placeholder and create_first_version a…
moonyuet Jul 6, 2026
17a3c8f
Merge branch 'develop' into enhancement/AY-7243_Template-builder-alwa…
moonyuet Jul 6, 2026
ada3de8
Update client/ayon_core/pipeline/workfile/workfile_template_builder.py
moonyuet Jul 6, 2026
73315d6
Update client/ayon_core/pipeline/workfile/workfile_template_builder.py
moonyuet Jul 6, 2026
8264473
Update client/ayon_core/pipeline/workfile/workfile_template_builder.py
moonyuet Jul 6, 2026
03bd696
Update client/ayon_core/pipeline/workfile/workfile_template_builder.py
moonyuet Jul 6, 2026
e4e39b7
Update client/ayon_core/pipeline/workfile/workfile_template_builder.py
moonyuet Jul 6, 2026
8bb2ff4
Update client/ayon_core/pipeline/workfile/workfile_template_builder.py
moonyuet Jul 6, 2026
4f234e3
Update client/ayon_core/pipeline/workfile/workfile_template_builder.py
moonyuet Jul 6, 2026
584ed01
Update client/ayon_core/pipeline/workfile/workfile_template_builder.py
moonyuet Jul 6, 2026
ff7b4a1
Rename save_first_version to save_next_workfile_version
moonyuet Jul 6, 2026
3783033
wip: do not rely on the env variable for get_workfile_path and add co…
moonyuet Jul 6, 2026
f0443d9
Merge branch 'develop' into enhancement/AY-7243_Template-builder-alwa…
moonyuet Jul 7, 2026
e236dd2
Merge branch 'develop' into enhancement/AY-7243_Template-builder-alwa…
moonyuet Jul 7, 2026
f3eb885
do not trigger save next version during application launch as it woul…
moonyuet Jul 7, 2026
97c8b61
check if the path has already existed yet.
moonyuet Jul 7, 2026
82f2006
wip: use save_next_version()
moonyuet Jul 8, 2026
385d0bf
clean up the self.workfile_path()
moonyuet Jul 8, 2026
4ccf4d5
Merge remote-tracking branch 'origin/develop' into enhancement/AY-724…
moonyuet Jul 8, 2026
bcb9413
fix the logic issue on checking the workfile path if it is existed.
moonyuet Jul 8, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 25 additions & 4 deletions client/ayon_core/pipeline/workfile/workfile_template_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,8 @@ def build_template(
level_limit=None,
keep_placeholders=None,
create_first_version=None,
apply_to_empty_scene=None,
apply_on_app_launch=None,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think apply_on_app_launch is something this method can't resolve. It probably is duplicate of workfile_creation_enabled.

workfile_creation_enabled=False
):
Comment thread
moonyuet marked this conversation as resolved.
"""Main callback for building workfile from template path.
Expand All @@ -532,6 +534,10 @@ def build_template(
When set to True, this option initiates the saving of the
workfile for an initial version. It will skip saving if
a version already exists.
apply_to_empty_scene (bool): Whether to apply the template

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we rename this apply_on_new_file?

to an empty scene(Act as 'new file' template).
apply_on_app_launch (bool): Whether to apply the template on
application launch if no workfile exists yet.
workfile_creation_enabled (bool): Whether the call is part of
creating a new workfile.
When True, we only build if the current file is not
Expand Down Expand Up @@ -559,15 +565,22 @@ def build_template(
keep_placeholders: bool = preset["keep_placeholder"]
if create_first_version is None:
create_first_version: bool = preset["create_first_version"]
if apply_to_empty_scene is None:
apply_to_empty_scene: bool = preset["apply_to_empty_scene"]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

apply_to_empty_scene and apply_on_app_launch probably won't be available for old addons?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
apply_to_empty_scene: bool = preset["apply_to_empty_scene"]
apply_to_empty_scene: bool = preset.get("apply_to_empty_scene", False)

if apply_on_app_launch is None:
apply_on_app_launch: bool = preset["apply_on_app_launch"]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
apply_on_app_launch: bool = preset["apply_on_app_launch"]
apply_on_app_launch: bool = preset.get("apply_on_app_launch", False)


# Build the template if we are explicitly requesting it or if it's
# an unsaved "new file".
is_new_file = not self.host.get_current_workfile()
if is_new_file or explicit_build_requested:
if (
apply_to_empty_scene
or explicit_build_requested
or (apply_on_app_launch and is_new_file)
):
self.log.info(f"Building the workfile template: {template_path}")
Comment thread
moonyuet marked this conversation as resolved.
self.import_template(template_path)
self.populate_scene_placeholders(
level_limit, keep_placeholders)
self.populate_scene_placeholders(level_limit, keep_placeholders)

# Do not consider saving a first workfile version, if this is not set
# to be a "workfile creation" or `create_first_version` is disabled.
Expand Down Expand Up @@ -863,6 +876,10 @@ def get_template_preset(self):
filter_data,
logger=self.log
)
if not profile.get("enabled", True):
self.log.info("Template profile is disabled for current context.")
return

if not profile:
raise TemplateProfileNotFound((
Comment thread
moonyuet marked this conversation as resolved.
Outdated
"No matching profile found for task '{}' of type '{}' "
Expand Down Expand Up @@ -890,6 +907,8 @@ def get_template_preset(self):
# switch to remove placeholders after they are used
keep_placeholder = profile.get("keep_placeholder")
create_first_version = profile.get("create_first_version")
Comment thread
moonyuet marked this conversation as resolved.
apply_to_empty_scene = profile.get("apply_to_empty_scene", True)
apply_on_app_launch = profile.get("apply_on_app_launch", True)

# backward compatibility, since default is True
if keep_placeholder is None:
Expand All @@ -898,7 +917,9 @@ def get_template_preset(self):
return {
"path": resolved_path,
Comment thread
moonyuet marked this conversation as resolved.
Outdated
"keep_placeholder": keep_placeholder,
"create_first_version": create_first_version
"create_first_version": create_first_version,
"apply_to_empty_scene": apply_to_empty_scene,
"apply_on_app_launch": apply_on_app_launch,

@iLLiCiTiT iLLiCiTiT Jun 24, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Idea:
"apply_to_empty_scene" and "apply_on_app_launch" really don't make sense (from my point of view) to be resolved within the logic of workfile builder.

Rather store the profile to the output, and use correct arguments in build_template based on host logic:

  • apply_to_empty_scene is duplicate of workfile_creation_enabled.
  • apply_on_app_launch cannot be resolved in any way shape or form in workfile builder logic, it is used only for the import (again, duplicate of workfile_creation_enabled).
return {
    "path": resolved_path,
    "keep_placeholder": keep_placeholder,
    "create_first_version": create_first_version,
    "profile": profile,
}

Then you can do

# Somehow find out
just_lauched = ...

host = registered_host()
builder = TemplateBuilder(host)

preset = builder.get_template_preset()
profile = preset["profile"]
is_new_workfile = False
is_new_file = not self.host.get_current_workfile()
if just_lauched:
    is_new_workfile = profile["apply_to_empty_scene"]
elif is_new_file:
    is_new_workfile = profile["apply_on_app_launch"]
    
builder.build_template(
    template_path=preset["path"],
    keep_placeholder=preset["keep_placeholder"],
    create_first_version=preset["create_first_version"],
    workfile_creation_enabled=is_new_file,
)

I know this means the code has to be duplicated in each host that would want to do that, but this is the least affecting invasive code changes to avoid being even more blocked with future enhancements. Both values do affect the workfile template builder, but are not really related to the workfile builder. And yes we do have already the is_new_file logic, but why to add more to the pile.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have two questions with this:

  1. Isn't that we have discussed with @BigRoy about using dataclass for the return value? Or we dont need this now(Kinda offtrack though)
  2. Aren't keep_placeholder and create_first_version already part of the profiles? So, I believe apply_to_empty_scene and apply_on_app_launch should be part of the profile settings?
image

@iLLiCiTiT iLLiCiTiT Jun 24, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, I believe apply_to_empty_scene and apply_on_app_launch should be part of the profile settings?

They can be part of the profile, but it doesn't make sense to have them as part of the workfile build preset. The workfile builder has nothing to do with the values. It is additional values that describe context before the workfile builder is being used.

The point is that the workfile template builder really needs more refactoring and adding more stuff that is at the end not used by the builder will only complicate future possible enhancements.

Apply to empty scene and on application launch cannot be handled by the workfile builder, it even should not be handled by the builder, you as someone who explicitly do trigger the builder know it, and you should pass that information to the build method, for both options and cases there already is argument that does handle that as far as I understand. If the same method is triggered manually from action the values from the preset should have no value, because at that moment it is not triggered on launch, or on empty workfile, and it should not apply the same logic (you can still trigger the builder manually).

}

Comment thread
moonyuet marked this conversation as resolved.
def resolve_template_path(self, path, fill_data=None) -> str:
Expand Down
Loading