Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
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
118 changes: 118 additions & 0 deletions client/ayon_nuke/api/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@
env_value_to_bool,
Logger,
StringTemplate,
BoolDef,
UILabelDef,
)

from ayon_core.tools.attribute_defs.dialog import (
AttributeDefinitionsDialog
)

from ayon_core.settings import (
Expand All @@ -44,6 +50,7 @@
AVALON_INSTANCE_ID,
get_current_context,
)
from ayon_core.pipeline.create import CreateContext
from ayon_core.pipeline.load import filter_containers
from ayon_core.pipeline.colorspace import (
get_current_context_imageio_config_preset
Expand Down Expand Up @@ -2560,6 +2567,117 @@ def _launch_workfile_app():
host_tools.show_workfiles(parent=None, on_top=True)


def update_content_on_context_change():
"""Update creator instances when the current folder/task changes."""
host = registered_host()
create_context = CreateContext(host, reset=True)
Comment thread
BigRoy marked this conversation as resolved.
Outdated

project_entity = create_context.get_current_project_entity()
folder_entity = create_context.get_current_folder_entity()
task_entity = create_context.get_current_task_entity()

current_folder_path = folder_entity.get("path")
current_task = task_entity.get("name")

project_name = project_entity.get("name")
Comment thread
sebastianbrandhuber marked this conversation as resolved.
Outdated
host_name = create_context.host_name

_changed = False

for instance in create_context.instances:
if instance.creator_identifier == "workfile":
continue

if (
instance.get("folderPath") == current_folder_path
and instance.get("task") == current_task
):
continue

creator = create_context.creators.get(
instance.creator_identifier
)
if creator is None:
continue
Comment thread
sebastianbrandhuber marked this conversation as resolved.
Outdated

product_name = creator.get_product_name(
project_name=project_name,
project_entity=project_entity,
folder_entity=folder_entity,
task_entity=task_entity,
variant=instance.get("variant"),
host_name=host_name,
)

instance["folderPath"] = current_folder_path
instance["task"] = current_task
instance["productName"] = product_name

_changed = True

if _changed:
create_context.save_changes()


def prompt_reset_context():
"""Prompt the user what context settings to reset.
This prompt is used on saving to a different task to allow the scene to
get matched to the new context.
"""
definitions = [
UILabelDef(
label=(
"You are saving your workfile into a different folder or task."
"\n\n"
"Would you like to update some settings to the new context?\n"
)
),
BoolDef(
"resolution",
label="Resolution",
tooltip="Reset workfile resolution",
default=True
),
BoolDef(
"frame_range_fps",
label="Frame Range / FPS",
tooltip="Reset workfile start/end frame ranges and fps",
default=True
),
BoolDef(
"colorspace",
label="Colorspace",
tooltip="Reset workfile colorspace",
default=True
),
BoolDef(
"instances",
label="Publish instances",
tooltip="Update all publish instance's folder and task to match "
"the new folder and task",
default=True
),
]

dialog = AttributeDefinitionsDialog(definitions)
dialog.setWindowTitle("Saving to different context.")
if not dialog.exec_():
return None

options = dialog.get_values()

if options["resolution"]:
WorkfileSettings().reset_resolution()
if options["frame_range_fps"]:
WorkfileSettings().reset_frame_range_handles()
if options["colorspace"]:
WorkfileSettings().set_colorspace()
if options["instances"]:
update_content_on_context_change()

dialog.deleteLater()


def start_workfile_template_builder():
from .workfile_template_builder import (
build_workfile_template
Expand Down
30 changes: 29 additions & 1 deletion client/ayon_nuke/api/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
set_avalon_knob_data,
read_avalon_data,
on_script_load,
prompt_reset_context,
dirmap_file_name_filter,
add_scripts_menu,
add_scripts_gizmo,
Expand Down Expand Up @@ -92,6 +93,9 @@
if os.getenv("PYBLISH_GUI", None):
pyblish.api.register_gui(os.getenv("PYBLISH_GUI", None))

# Track whether the workfile tool is about to save
_about_to_save = False


class NukeHost(
HostBase, IWorkfileHost, ILoadHost, IPublishHost
Expand Down Expand Up @@ -138,8 +142,10 @@ def install(self):
register_workfile_build_plugin_path(WORKFILE_BUILD_PATH)

# Register AYON event for workfiles loading.
register_event_callback("workfile.save.before", before_workfile_save)
register_event_callback("workfile.save.after", after_workfile_save)
register_event_callback("workio.open_file", check_inventory_versions)
register_event_callback("taskChanged", change_context_label)
register_event_callback("taskChanged", on_task_changed)
Comment thread
sebastianbrandhuber marked this conversation as resolved.
Outdated

def setup_ui_callbacks_and_menu(self):
"""Setup AYON menus."""
Expand Down Expand Up @@ -405,6 +411,28 @@ def change_context_label():
old_label, new_label))


def after_workfile_save():
global _about_to_save
_about_to_save = False


def before_workfile_save(event):
global _about_to_save
_about_to_save = True


def on_task_changed():
global _about_to_save
Comment thread
sebastianbrandhuber marked this conversation as resolved.
Outdated
if not nuke.GUI:
return

change_context_label()

if _about_to_save:
# Let's prompt the user to update the context settings or not
prompt_reset_context()


def add_shortcuts_from_presets(project_settings: dict):
menubar = nuke.menu("Nuke")
nuke_presets = project_settings["nuke"]["general"]
Expand Down
Loading