Skip to content

Support creating first workfile with TemplateBuilder#307

Open
tweak-wtf wants to merge 6 commits into
ynput:developfrom
bEpic-studio:enhancement/create-first-templated-workfile
Open

Support creating first workfile with TemplateBuilder#307
tweak-wtf wants to merge 6 commits into
ynput:developfrom
bEpic-studio:enhancement/create-first-templated-workfile

Conversation

@tweak-wtf

@tweak-wtf tweak-wtf commented Jun 25, 2025

Copy link
Copy Markdown

Changelog Description

Supports creating the first initial workfile version from a built template.

Additional review information

This picks up and continues #301.
I took the following commit as reference ynput/ayon-houdini@65db6d3

When testing u have to build and upload this addon as it contains server-side settings changes ⚠️

Testing notes:

  1. configure a templated workfile for maya with create_first_version = True
  2. launch maya from a task that atm has 0 workfiles
  3. check that your template gets applied accordingly
  4. check the workfile is saved as initial v01 in your work-drive

now falsify

  1. use before created template but set create_first_version = False
  2. check that the workfile still gets applied but no workfile is saved

and check already imported templates

  1. open up a workfile that already has your template applied
  2. apply the same again
  3. check script editor that it intentionally didn't do anything

@tweak-wtf

tweak-wtf commented Jun 25, 2025

Copy link
Copy Markdown
Author

i did notice a performance degradation in launching maya.
i suspect this is because the TemplateBuilder now gets called on any new file event. unsure how to circumvent this tho.

@tweak-wtf tweak-wtf changed the title Enhancement/create first templated workfile Support creating first workfile with TemplateBuilder Jun 25, 2025
@antirotor antirotor added type: enhancement Improvement of existing functionality or minor addition community Issues and PRs coming from the community members labels Jun 25, 2025
@BigRoy BigRoy requested a review from LiborBatek June 27, 2025 21:19
@BigRoy BigRoy self-assigned this Jun 27, 2025
@BigRoy BigRoy requested a review from antirotor June 27, 2025 21:19
@BigRoy

BigRoy commented Jun 27, 2025

Copy link
Copy Markdown
Member

i did notice a performance degradation in launching maya.
i suspect this is because the TemplateBuilder now gets called on any new file event. unsure how to circumvent this tho.

I'd say this is quite important to solve. Any ideas on how to improve best @antirotor ?

@BigRoy BigRoy assigned antirotor and unassigned BigRoy Jun 27, 2025
@BigRoy BigRoy self-requested a review July 7, 2025 20:56

@BigRoy BigRoy left a comment

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.

This errors if no workfile templates are currently enabled for current context - other than that it looks good and seems to work as inteded.

@antirotor could you take a look at the code as well please?

Comment thread client/ayon_maya/api/pipeline.py Outdated

@antirotor antirotor left a comment

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.

With catching of the missing template it works, but we need to find out way not to execute the logic on startup when AYON_LAST_WORKFILE is set. So what about just not executing workfile_template_builder.build_workfile_template() if AYON_LAST_WORKFILE exists?

...
    try:
        if not os.getenv("AYON_LAST_WORKFILE"):
            workfile_template_builder.build_workfile_template(
                workfile_creation_enabled=True)
    except TemplateProfileNotFound:
        log.debug(
            "No workfile template profile enabled for current context. "
            "Skipping workfile creation."
        )
...

Ideally we should not query AYON_LAST_WORKFILE directly but call some ayon-core function but I don't think there is one (yet) :)

@BigRoy

BigRoy commented Jul 8, 2025

Copy link
Copy Markdown
Member

With catching of the missing template it works, but we need to find out way not to execute the logic on startup when AYON_LAST_WORKFILE is set. So what about just not executing workfile_template_builder.build_workfile_template() if AYON_LAST_WORKFILE exists?

...
    try:
        if not os.getenv("AYON_LAST_WORKFILE"):
            workfile_template_builder.build_workfile_template(
                workfile_creation_enabled=True)
    except TemplateProfileNotFound:
        log.debug(
            "No workfile template profile enabled for current context. "
            "Skipping workfile creation."
        )
...

Ideally we should not query AYON_LAST_WORKFILE directly but call some ayon-core function but I don't think there is one (yet) :)

This wouldn't work unfortunately, because normally on CTRL+N the workfile template should kick in.. but in this case, it would now never kick in during that session because AYON_LAST_WORKFILE will remain set during the session.

@antirotor

Copy link
Copy Markdown
Member

This wouldn't work unfortunately, because normally on CTRL+N the workfile template should kick in.. but in this case, it would now never kick in during that session because AYON_LAST_WORKFILE will remain set during the session.

You are right. But that means we should unset AYON_LAST_WORKFILE on CTRL+N. Or better, handle the session states more gracefully.

@tweak-wtf

Copy link
Copy Markdown
Author

okay i never tried using CTRL+N for new scenes. always used AYON.
but sure... i'll see what i can come up with

@tweak-wtf

Copy link
Copy Markdown
Author

With catching of the missing template it works, but we need to find out way not to execute the logic on startup when AYON_LAST_WORKFILE is set.

my testing lead me to this docstring
https://github.com/ynput/ayon-core/blob/17f24b5dbf7dff16d815cbeff231589ffa66149d/client/ayon_core/pipeline/workfile/path_resolving.py#L320

from it i'm wondering... is it correct that $AYON_LAST_WORKFILE is always set no matter if workfiles are present or not?
even when skipping opening the last workfile (which is kinda deprecated anyways since ayon-core 0.4.x) i have $AYON_LAST_WORKFILE set.

so that variable seems to be always set and my workfile is built as expected. also when already working on it for a couple of versions the template builder does not kick in.
it only gets triggered when no workfile is present yet as far as i can tell.

but I might be too stoopid to really get the issue here

@BigRoy

BigRoy commented Jul 9, 2025

Copy link
Copy Markdown
Member

@tweak-wtf it was related to this comment by @antirotor where he proposed a code change: #307 (review)

I was referring to the case if the code was changed to that.. that it wouldn't behave as expected.

And the source issue we are trying to solve is what Ondrej wrote there: it should not build if it opens workfile on launch...

@tweak-wtf

Copy link
Copy Markdown
Author

ah thanks for clarifying, i think i understood.

it should not build if it opens workfile on launch...

i'm quite sure that this is how it currently behaves.
admittedly, the templater does run but it isn't modifying the workfile that is launched.

however, i checked for nuke/houdini and noticed that there too the template always gets executed but existing workfiles aren't modified. it bails before modifying.

so isn't this rather a thing for the AbstractTemplateBuilder?
also always having $AYON_LAST_WORKFILE populated even if it isn't present might be troublesome for this?

@BigRoy

BigRoy commented Jul 10, 2025

Copy link
Copy Markdown
Member

however, i checked for nuke/houdini and noticed that there too the template always gets executed but existing workfiles aren't modified. it bails before modifying.

The logic there is that if when the build triggers, and the current scene is alread a saved/named file then it'll not trigger due to the assumption you have opened a workfile.

However, in Maya we have the post initialize last workfile settings (enabled by default?)

image

ayon+settings://maya/open_workfile_post_initialization

And hence likely the workfile is only opened 'later' than when the template build triggers perhaps?

@tweak-wtf

Copy link
Copy Markdown
Author

so i managed to not run the template builder on any file open but it comes with some gotchas:

  • template builder is not invoked on file_new callback anymore
    • user needs to CTRL+N and then trigger the template build manually (AYON -> Template Builder -> Build Workfile from template)
  • template builder only runs if open_workfile_post_initialization is enabled

i'm wondering if there are cases where open_workfile_post_initialization is disabled? btw, i can confirm it is enabled by default.
afaik this it's mandatory for ensuring all needed plugins are actually loaded on file open.

what do u think?
it's in this single commit so easily revertable 684f7fc

@tweak-wtf tweak-wtf requested review from BigRoy and antirotor July 11, 2025 15:02
@moonyuet

Copy link
Copy Markdown
Member

I tested in my side, it is successfully built the workfile by build workfile from template as well as build new workfile
image
@antirotor @BigRoy are we gonna merge this or we still need to fix something?

@BigRoy BigRoy assigned BigRoy and unassigned antirotor Jun 2, 2026
@BigRoy BigRoy assigned moonyuet and unassigned BigRoy Jun 23, 2026
@BigRoy BigRoy requested a review from moonyuet June 23, 2026 14:24
@BigRoy

BigRoy commented Jun 23, 2026

Copy link
Copy Markdown
Member

@moonyuet

This will need changes. Feel free to make a new PR with this as inspiration. But essentially:

  • We should be able to have template builder build on app launch to create first workfile (if no workfile is being opened on launch)
  • Then pressing CTRL+N (or new file) should also build it again, because that's the current default behavior in AYON.
  • Then we should once we have some more settings exposed be able to disable it for CTRL+N, so that it just does a regular clean file. So at some point we'll need to be able to differentiate between "new file" and "app launched".

It should work for both the case where "Open post app initialization" is disabled or enabled in ayon-maya settings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

community Issues and PRs coming from the community members type: enhancement Improvement of existing functionality or minor addition

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants