Skip to content

Added setting for disabling forcing context settings#193

Open
splidje wants to merge 10 commits into
ynput:developfrom
splidje:optional_set_context_settings_on_load_script
Open

Added setting for disabling forcing context settings#193
splidje wants to merge 10 commits into
ynput:developfrom
splidje:optional_set_context_settings_on_load_script

Conversation

@splidje
Copy link
Copy Markdown
Contributor

@splidje splidje commented Feb 11, 2026

Changelog Description

Added setting for disabling forcing context settings (e.g. frame range) upon opening an existing Script.

Additional review information

Added a new setting under general described as "Set Context Settings on Script Open".
Defaults to True, but if False opening a Nuke Script by any means - e.g. via Ayon -> Workfiles, selecting from the Launcher, using vanilla Nuke Open - skips calling set_context_settings, so e.g. keeps Root node first/last frame as it was on save.

Testing notes:

  1. Create a new blank Nuke Script
  2. Set frame range to something different from the context's frame range (except not 1-100, which is Nuke's default and it won't save into the .nk)
  3. Save
  4. Close Nuke
  5. Open the script again
  6. Frame range should be the same as it was when it was saved

Copy link
Copy Markdown
Member

@BigRoy BigRoy left a comment

Choose a reason for hiding this comment

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

Very nice - disabling the integration to mess with your scenes on open I think is a good thing. My personal preference, I don't want to open your scene and have it altered without your knowledge. So this is a step the good way.

I'd love to still be notified and asked if I want to fix certain things though, but not super important.

@jakubjezek001 @LiborBatek thoughts?

Comment thread server/settings/general.py
Comment thread client/ayon_nuke/api/lib.py Outdated
Comment thread client/ayon_nuke/api/lib.py Outdated
@BigRoy BigRoy added type: enhancement Improvement of existing functionality or minor addition community Issues and PRs coming from the community members labels Feb 11, 2026
@nebukadhezer
Copy link
Copy Markdown

But isnt that exactly what a pipeline should do set the correct frame range ? what is the use case ? under a task with a defined frame range you dont want to have that frame range ? Or maybe I am not getting what this is ment for...
But if egg editorial changes frame ranges on a running production I want those ranges to propagate, does it need to be on startup ? No, easy on publish with validation plus fix method...

@splidje splidje closed this Feb 12, 2026
@splidje splidje reopened this Feb 12, 2026
@splidje
Copy link
Copy Markdown
Contributor Author

splidje commented Feb 12, 2026

My particular use case is an artist working under a test shot doing various experiments.

In my previous job we did consider it very important to ensure people are working with the correct context settings, however we also didn't like to impose too much in the way of changing someone's work file automatically without flagging the changes.

We had a "set the correct context settings" menu item so an artist could ensure it's all correct, and also various moments where they'd be checked and if wrong a dialog would pop up telling them which were wrong and asking whether to set them correctly or not.

Then obviously on creating a new work file, those settings would be set correctly.

I guess another example might be the frame changing after a work file has been created. The artist does need to have their frame changed, but they need to be notified about it before it happens as they might want to sort a few things out before setting it.

@nebukadhezer
Copy link
Copy Markdown

nebukadhezer commented Feb 12, 2026

I agree that user notification is a good thing, a validator on publish does that... I still think that I lean more towards maybe an "opt out" button per script, rather than a studio wide setting ? Would be nice to have some metadata stored on root and if that says "dont update me" the callback just skips the update ? Just thinking out loud ... but I do get the usecase ... that if you are testing stuff too strict pipelines are not helpful...

@splidje
Copy link
Copy Markdown
Contributor Author

splidje commented Feb 12, 2026

Yes, that makes sense. I could modify this to do that? Remove the new setting and add a knob to Root for opting out a particular script?

@splidje
Copy link
Copy Markdown
Contributor Author

splidje commented Feb 12, 2026

Oh, actually I'm gonna predict that my artist would still want to be clearly notified / asked to change the settings even on a proper shot.

If I did the above change, I could also roll in some kind of question dialog popping up (only if anything needs changing)?

@jakubjezek001
Copy link
Copy Markdown
Member

Oh, actually I'm gonna predict that my artist would still want to be clearly notified / asked to change the settings even on a proper shot.

If I did the above change, I could also roll in some kind of question dialog popping up (only if anything needs changing)?

I really like the way you think! Yes this could be very good design from my perspective.

Settings in studio/project overrides are also good, to be honest. Some productions might want to prefer to disable it but for about 5 years in productions no one was complaining.

I am sharing openion with @BigRoy that someone might not like to have workfile changed at starting without notification about the changes.

We already do this for example with colorspace config change. There is alrady mechanism in place that if OCIO config is not the same as in settings so it is popping up dialogue with notification. Trigger for the change is I believe hooked to onScriptsave callback. Not ideall but to be honest better then an interval check, since users tent to Ctrl+s quite often.

Comment thread client/ayon_nuke/api/plugin.py
@splidje
Copy link
Copy Markdown
Contributor Author

splidje commented Feb 13, 2026

Random question/suggestion:

I've got into the habit over the last few years of running Black on Python code to 1) have a consistent formatting and 2) not have to really think about formatting.

Reckon something like that might be a nice idea for these repos?

@BigRoy
Copy link
Copy Markdown
Member

BigRoy commented Feb 13, 2026

Random question/suggestion:

I've got into the habit over the last few years of running Black on Python code to 1) have a consistent formatting and 2) not have to really think about formatting.

Reckon something like that might be a nice idea for these repos?

Pretty sure majority of our repos are set up for ruff - with not too strict rules, but running ruff should match the code style. However, to avoid mental PRs we tend to avoid just ruff fixing full files to avoid PRs becoming very hard to parse for changes (even if that'd be just a short period.)

And just ruff fixing all files would make anyone with forks less happy to fix 'code conflicts' :)

Comment thread client/ayon_nuke/api/pipeline.py Outdated
# set apply all workfile settings on script load and save
nuke.addOnScriptLoad(WorkfileSettings().set_context_settings)
if nuke_settings["general"]["set_context_settings_on_script_open"]:
# set apply all workfile settings on script load and save
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.

Pretty sure this comment above it was just wrong?

Suggested change
# set apply all workfile settings on script load and save
# set apply all workfile settings on script load

Comment thread client/ayon_nuke/api/pipeline.py Outdated
nuke.addOnScriptLoad(WorkfileSettings().set_context_settings)
if nuke_settings["general"]["set_context_settings_on_script_open"]:
# set apply all workfile settings on script load and save
nuke.addOnScriptLoad(WorkfileSettings().set_context_settings)
Copy link
Copy Markdown
Member

@BigRoy BigRoy Feb 13, 2026

Choose a reason for hiding this comment

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

Pretty sure this is actually wrong - and apparently always has been?

Because this initializes WorkfileSettings DIRECTLY here - and not on the callback. As such, this is set to the context of AYON when Nuke is launched. If you open a workfile in a different context, it'd still be applying the workfile settings of the context you launched into.

Suggested change
nuke.addOnScriptLoad(WorkfileSettings().set_context_settings)
nuke.addOnScriptLoad(lambda: WorkfileSettings().set_context_settings)

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

# adding favorites to file browser
nuke.addOnCreate(workfile_settings.set_favorites, nodeClass="Root")
nuke.addOnCreate(WorkfileSettings().set_favorites, nodeClass="Root")
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.

Pretty sure this is actually wrong - and apparently always has been?

Because this initializes WorkfileSettings DIRECTLY here - and not on the callback. As such, this is set to the context of AYON when Nuke is launched. If you open a workfile in a different context, it'd still be applying the workfile settings of the context you launched into.

Suggested change
nuke.addOnCreate(WorkfileSettings().set_favorites, nodeClass="Root")
nuke.addOnCreate(lambda: WorkfileSettings().set_favorites, nodeClass="Root")

@jakubjezek001 right?

…tion before setting format or frame range. Can also set a specific script to check context settings on load or not, overriding the general setting if on.
@splidje
Copy link
Copy Markdown
Contributor Author

splidje commented Feb 16, 2026

I've made those tweaks you pointed out, and also put in asking for confirmation, changing the general setting to "check" rather than "set" and added support for a specific script to have checking turned off.

Copy link
Copy Markdown
Member

@BigRoy BigRoy left a comment

Choose a reason for hiding this comment

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

Thanks - I think code got worse now with latest changes - so more tweaks will be needed. I'll comment my first pass - @jakubjezek001 who's off this week may be better suited to comment from Nuke's perspective so my comments are mainly on the coded approach, not anything nuke-specific.

Comment on lines +1493 to +1502
if not ASSIST:
self._always_check_check_box = QtWidgets.QCheckBox(
"Always check this Script's context settings on load\n"
"(if switched off, can be switched back on in Project Settings User tab)"
)
self._always_check_check_box.setChecked(True)
layout.addWidget(
self._always_check_check_box
)
self._always_check_check_box.toggled.connect(self._always_check_check_box_toggled)
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.

Please do not expose to the user to change the settings. Not every user has these permissions, or should even be allowed to care. That's for admin permissions, and even then you don't want anyone in production to accidentally misclick here either.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is just for excluding the current script from context setting checks on load, rather than the global setting.

Comment on lines +2282 to 2286
def set_context_settings(self, requires_confirmation=False):
self.reset_resolution(requires_confirmation)
self.reset_frame_range_handles(requires_confirmation)
# todo: No need to check confirmation for color?
self.set_colorspace()
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 will start prompting once for every thing it needs to reset - we'll definitely want to avoid that, especially if we may add more over time. I'd rather present the user of all things invalid in current context, and then tell them about all. Not a massive issue, but may as well tackle now.

Also, when Nuke is running in headless mode - there's no such things as showing user a pop-up. In that case it should just log the fact that it's not the right values and allow it to continue without automatically fixing it (that's my personal preference though; @jakubjezek001 ?)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, good point about headless mode. I'll fix that.

With one pop-up showing all required changes, are their options "all or nothing" or should that pop-up let them control which to set, and if so how granular should it be?

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 one pop-up showing all required changes, are their options "all or nothing" or should that pop-up let them control which to set, and if so how granular should it be?

Probably a single prompt with checkboxes:

  • Fix resolution
  • Fix frame range
  • Fix colorspace

With default having all checkboxes enabled? and the prompt can be confirmed or cancelled.

Comment on lines +2160 to +2187
if knob_name_current_new_value_triplets_by_node:
if not requires_confirmation or ConfirmSetContextSettingMessageBox.ask_for_confirmation(
"\n\n".join(
"{}:\n{}".format(
node.name(),
"\n".join(
f"{knob_name}: {current_value} -> {new_value}" for knob_name, current_value, new_value in knob_name_current_new_value_triplets
)
) for node, knob_name_current_new_value_triplets in knob_name_current_new_value_triplets_by_node.items()
)
):
was_node_graph_updated = False
for node, knob_name_current_new_value_triplets in knob_name_current_new_value_triplets_by_node.items():
# Root node will be first.
# Based on how the code was when I found it,
# `update_node_graph` needs calling between
# root node and viewers - splidje
if not was_node_graph_updated and node != self._root_node:
# update node graph so knobs are updated
update_node_graph()
was_node_graph_updated = True
for knob_name, _, new_value in knob_name_current_new_value_triplets:
node[knob_name].setValue(new_value)

# in case no Viewers needed knob changes
if not was_node_graph_updated:
# update node graph so knobs are updated
update_node_graph()
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.

Why does this suddenly need all this complexity? This is very hard to read and grasp.

Admittedly - all we're really changing is:

  • Before reset_frame_range_handles gets called, ask for confirmation of changes.
  • Or better, before any of the reset_..._ gets called handle confirmation.

To know whether we need to ask the user we need two things:

    1. Are we checking?
    1. Is there anything to change?

The way I see it is what we should do is separate the logic of getting the current and expected state from the setting the state.

# overly simplified psuedocode
should_check = ...[settings][check][blabla]
if not should_check:
    return

current, expected = get_current_state()
if current == expected:
    return

if headless:
    # log difference
    log.warning("Values mismatch: {current} != {headless}")
    return

accepted = prompt_user(current, expected):
if accepted:
    set_state(expected)

But in short, the setting of the values should not be changing or get more complicated at all?
We just end up having a library set_frame_range, set_colorspace and set_frame_range functions that will end up being called, right?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, makes sense to make this neater and more readable.

Above psuedocode makes sense to me.

When I find the time I'll do another sweep and make these changes.

@splidje
Copy link
Copy Markdown
Contributor Author

splidje commented Feb 25, 2026

Random question/suggestion:
I've got into the habit over the last few years of running Black on Python code to 1) have a consistent formatting and 2) not have to really think about formatting.
Reckon something like that might be a nice idea for these repos?

Pretty sure majority of our repos are set up for ruff - with not too strict rules, but running ruff should match the code style. However, to avoid mental PRs we tend to avoid just ruff fixing full files to avoid PRs becoming very hard to parse for changes (even if that'd be just a short period.)

And just ruff fixing all files would make anyone with forks less happy to fix 'code conflicts' :)

Back to this. How do I use ruff? I can see a ruff.toml file there. Is it similar to black in that I can just run ruff . when in the repo folder?

@jakubjezek001
Copy link
Copy Markdown
Member

Back to this. How do I use ruff? I can see a ruff.toml file there. Is it similar to black in that I can just run ruff . when in the repo folder?

try ruff check . inside the addon root dir. But you need to be in venv with installed ruff.

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