From a53e75f68f24bc8cd79b3b87190883247ead06ab Mon Sep 17 00:00:00 2001 From: Braden Jennings Date: Tue, 13 Feb 2024 10:19:25 +1300 Subject: [PATCH 1/4] enhancement/OP-7955_Context_Validation_Repair_Action_enhancement --- client/ayon_core/hosts/maya/api/lib.py | 27 ++++++++-- .../plugins/publish/validate_frame_range.py | 52 ++++++++++++++----- .../plugins/publish/validate_resolution.py | 6 ++- .../publish/collect_context_entities.py | 5 ++ 4 files changed, 72 insertions(+), 18 deletions(-) diff --git a/client/ayon_core/hosts/maya/api/lib.py b/client/ayon_core/hosts/maya/api/lib.py index 7b791c3d51..793a76a430 100644 --- a/client/ayon_core/hosts/maya/api/lib.py +++ b/client/ayon_core/hosts/maya/api/lib.py @@ -19,6 +19,7 @@ from maya import cmds, mel from maya.api import OpenMaya +from ayon_api import get_task_by_name from ayon_core.client import ( get_project, get_asset_by_name, @@ -2614,17 +2615,33 @@ def reset_scene_resolution(): project_name = get_current_project_name() project_doc = get_project(project_name) project_data = project_doc["data"] - asset_data = get_current_project_asset()["data"] + asset_data_root = get_current_project_asset() + asset_data = asset_data_root["data"] + + task_name = get_current_task_name() + task_entity = get_task_by_name( + project_name, asset_data_root["_id"], task_name) # Set project resolution width_key = "resolutionWidth" height_key = "resolutionHeight" pixelAspect_key = "pixelAspect" - width = asset_data.get(width_key, project_data.get(width_key, 1920)) - height = asset_data.get(height_key, project_data.get(height_key, 1080)) - pixelAspect = asset_data.get(pixelAspect_key, - project_data.get(pixelAspect_key, 1)) + # Get frame information from task entity + # NOTE: If there is no task override then the asset + # value is automatically returned instead + width = task_entity["attrib"].get( + width_key, + asset_data.get( + width_key, project_data.get(width_key, 1920))) + height = task_entity["attrib"].get( + height_key, + asset_data.get( + height_key, project_data.get(height_key, 1080))) + pixelAspect = task_entity["attrib"].get( + pixelAspect_key, + asset_data.get( + pixelAspect_key, project_data.get(pixelAspect_key, 1080))) set_scene_resolution(width, height, pixelAspect) diff --git a/client/ayon_core/hosts/maya/plugins/publish/validate_frame_range.py b/client/ayon_core/hosts/maya/plugins/publish/validate_frame_range.py index 85cc606b25..7b79b46f99 100644 --- a/client/ayon_core/hosts/maya/plugins/publish/validate_frame_range.py +++ b/client/ayon_core/hosts/maya/plugins/publish/validate_frame_range.py @@ -53,12 +53,26 @@ def process(self, instance): ) return - frame_start_handle = int(context.data.get("frameStartHandle")) - frame_end_handle = int(context.data.get("frameEndHandle")) - handle_start = int(context.data.get("handleStart")) - handle_end = int(context.data.get("handleEnd")) - frame_start = int(context.data.get("frameStart")) - frame_end = int(context.data.get("frameEnd")) + # Get frame information from task entity + # NOTE: If there is no task override then the asset + # value is automatically returned instead + task_entity = instance.context.data["taskEntity"] + frame_start_handle = task_entity["attrib"]["frameStart"] - \ + task_entity["attrib"]["handleStart"] + frame_end_handle = task_entity["attrib"]["frameEnd"] + \ + task_entity["attrib"]["handleEnd"] + handle_start = task_entity["attrib"]["handleStart"] + handle_end = task_entity["attrib"]["handleEnd"] + frame_start = task_entity["attrib"]["frameStart"] + frame_end = task_entity["attrib"]["frameEnd"] + + # Get frame information from asset context + # frame_start_handle = int(context.data.get("frameStartHandle")) + # frame_end_handle = int(context.data.get("frameEndHandle")) + # handle_start = int(context.data.get("handleStart")) + # handle_end = int(context.data.get("handleEnd")) + # frame_start = int(context.data.get("frameStart")) + # frame_end = int(context.data.get("frameEnd")) inst_start = int(instance.data.get("frameStartHandle")) inst_end = int(instance.data.get("frameEndHandle")) @@ -128,12 +142,26 @@ def repair(cls, instance): node = instance.data["name"] context = instance.context - frame_start_handle = int(context.data.get("frameStartHandle")) - frame_end_handle = int(context.data.get("frameEndHandle")) - handle_start = int(context.data.get("handleStart")) - handle_end = int(context.data.get("handleEnd")) - frame_start = int(context.data.get("frameStart")) - frame_end = int(context.data.get("frameEnd")) + # Get frame information from task entity + # NOTE: If there is no task override then the asset + # value is automatically returned instead + task_entity = instance.context.data["taskEntity"] + frame_start_handle = task_entity["attrib"]["frameStart"] - \ + task_entity["attrib"]["handleStart"] + frame_end_handle = task_entity["attrib"]["frameEnd"] + \ + task_entity["attrib"]["handleEnd"] + handle_start = task_entity["attrib"]["handleStart"] + handle_end = task_entity["attrib"]["handleEnd"] + frame_start = task_entity["attrib"]["frameStart"] + frame_end = task_entity["attrib"]["frameEnd"] + + # Get frame information from asset context + # frame_start_handle = int(context.data.get("frameStartHandle")) + # frame_end_handle = int(context.data.get("frameEndHandle")) + # handle_start = int(context.data.get("handleStart")) + # handle_end = int(context.data.get("handleEnd")) + # frame_start = int(context.data.get("frameStart")) + # frame_end = int(context.data.get("frameEnd")) # Start if cmds.attributeQuery("handleStart", node=node, exists=True): diff --git a/client/ayon_core/hosts/maya/plugins/publish/validate_resolution.py b/client/ayon_core/hosts/maya/plugins/publish/validate_resolution.py index ff552f566d..3310d7ff53 100644 --- a/client/ayon_core/hosts/maya/plugins/publish/validate_resolution.py +++ b/client/ayon_core/hosts/maya/plugins/publish/validate_resolution.py @@ -84,9 +84,13 @@ def get_invalid_resolution(cls, instance): @classmethod def get_db_resolution(cls, instance): + task_doc = instance.context.data["taskEntity"] asset_doc = instance.data["assetEntity"] project_doc = instance.context.data["projectEntity"] - for data in [asset_doc["data"], project_doc["data"]]: + for data in [ + task_doc["attrib"], + asset_doc["data"], + project_doc["data"]]: if ( "resolutionWidth" in data and "resolutionHeight" in data and diff --git a/client/ayon_core/plugins/publish/collect_context_entities.py b/client/ayon_core/plugins/publish/collect_context_entities.py index 8480435e21..d8596e5937 100644 --- a/client/ayon_core/plugins/publish/collect_context_entities.py +++ b/client/ayon_core/plugins/publish/collect_context_entities.py @@ -14,6 +14,7 @@ import pyblish.api +from ayon_api import get_task_by_name from ayon_core.client import get_project, get_asset_by_name from ayon_core.pipeline import KnownPublishError @@ -51,6 +52,10 @@ def process(self, context): context.data["assetEntity"] = asset_entity + task_entity = get_task_by_name( + project_name, asset_entity["_id"], task_name) + context.data["taskEntity"] = task_entity + data = asset_entity['data'] # Task type From 5d92d22da37b23939e7e6bde74cf8c926246391d Mon Sep 17 00:00:00 2001 From: Braden Jennings Date: Tue, 13 Feb 2024 12:01:26 +1300 Subject: [PATCH 2/4] enhancement/OP-7955_Context_Validation_Repair_Action_enhancement --- client/ayon_core/hosts/maya/api/lib.py | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/client/ayon_core/hosts/maya/api/lib.py b/client/ayon_core/hosts/maya/api/lib.py index 793a76a430..54631f41fb 100644 --- a/client/ayon_core/hosts/maya/api/lib.py +++ b/client/ayon_core/hosts/maya/api/lib.py @@ -2630,18 +2630,9 @@ def reset_scene_resolution(): # Get frame information from task entity # NOTE: If there is no task override then the asset # value is automatically returned instead - width = task_entity["attrib"].get( - width_key, - asset_data.get( - width_key, project_data.get(width_key, 1920))) - height = task_entity["attrib"].get( - height_key, - asset_data.get( - height_key, project_data.get(height_key, 1080))) - pixelAspect = task_entity["attrib"].get( - pixelAspect_key, - asset_data.get( - pixelAspect_key, project_data.get(pixelAspect_key, 1080))) + width = task_entity["attrib"][width_key] + height = task_entity["attrib"][height_key] + pixelAspect = task_entity["attrib"][pixelAspect_key] set_scene_resolution(width, height, pixelAspect) From c130fe55c82a5b2af120eaee65b8b46149e63130 Mon Sep 17 00:00:00 2001 From: Braden Jennings Date: Tue, 13 Feb 2024 14:13:36 +1300 Subject: [PATCH 3/4] enhancement/OP-7955_Context_Validation_Repair_Action_enhancement --- .../plugins/publish/validate_frame_range.py | 70 ++++++++++++++----- 1 file changed, 52 insertions(+), 18 deletions(-) diff --git a/client/ayon_core/hosts/maya/plugins/publish/validate_frame_range.py b/client/ayon_core/hosts/maya/plugins/publish/validate_frame_range.py index 7b79b46f99..5e858aa5c3 100644 --- a/client/ayon_core/hosts/maya/plugins/publish/validate_frame_range.py +++ b/client/ayon_core/hosts/maya/plugins/publish/validate_frame_range.py @@ -1,3 +1,6 @@ + +import dataclasses + import pyblish.api from maya import cmds @@ -56,15 +59,13 @@ def process(self, instance): # Get frame information from task entity # NOTE: If there is no task override then the asset # value is automatically returned instead - task_entity = instance.context.data["taskEntity"] - frame_start_handle = task_entity["attrib"]["frameStart"] - \ - task_entity["attrib"]["handleStart"] - frame_end_handle = task_entity["attrib"]["frameEnd"] + \ - task_entity["attrib"]["handleEnd"] - handle_start = task_entity["attrib"]["handleStart"] - handle_end = task_entity["attrib"]["handleEnd"] - frame_start = task_entity["attrib"]["frameStart"] - frame_end = task_entity["attrib"]["frameEnd"] + frames = get_instance_task_frame_range(instance) + frame_start_handle = frames.frame_start_handle + frame_end_handle = frames.frame_end_handle + handle_start = frames.handle_start + handle_end = frames.handle_end + frame_start = frames.frame_start + frame_end = frames.frame_end # Get frame information from asset context # frame_start_handle = int(context.data.get("frameStartHandle")) @@ -145,15 +146,13 @@ def repair(cls, instance): # Get frame information from task entity # NOTE: If there is no task override then the asset # value is automatically returned instead - task_entity = instance.context.data["taskEntity"] - frame_start_handle = task_entity["attrib"]["frameStart"] - \ - task_entity["attrib"]["handleStart"] - frame_end_handle = task_entity["attrib"]["frameEnd"] + \ - task_entity["attrib"]["handleEnd"] - handle_start = task_entity["attrib"]["handleStart"] - handle_end = task_entity["attrib"]["handleEnd"] - frame_start = task_entity["attrib"]["frameStart"] - frame_end = task_entity["attrib"]["frameEnd"] + frames = get_instance_task_frame_range(instance) + frame_start_handle = frames.frame_start_handle + frame_end_handle = frames.frame_end_handle + handle_start = frames.handle_start + handle_end = frames.handle_end + frame_start = frames.frame_start + frame_end = frames.frame_end # Get frame information from asset context # frame_start_handle = int(context.data.get("frameStartHandle")) @@ -230,3 +229,38 @@ def _set_attr_in_layer(cls, node_attr, layer, value): value=value )) cmds.setAttr(node_attr, value) + + +def get_instance_task_frame_range(instance): + # Get frame information from task entity + # NOTE: If there is no task override then the asset + # value is automatically returned instead + attrib = instance.context.data["taskEntity"]["attrib"] + return FrameRange( + frame_start=attrib["frameStart"], + frame_end=attrib["frameEnd"], + handle_start=attrib["handleStart"], + handle_end=attrib["handleEnd"]) + + +@dataclasses.dataclass +class FrameRange: + """Frame range with handles. + + The frame range excludes the handles - and thus the handles are outside + of the frame range. To get the inclusive start and end frame use + `frame_start_handle` and `frame_end_handle`. + + """ + frame_start: int + frame_end: int + handle_start: int + handle_end: int + + @property + def frame_start_handle(self) -> int: + return self.frame_start - self.handle_start + + @property + def frame_end_handle(self) -> int: + return self.frame_end + self.handle_end \ No newline at end of file From 5a9b4f25c45391aa5979ec57de0d8adcf523e8f0 Mon Sep 17 00:00:00 2001 From: Braden Jennings Date: Thu, 15 Feb 2024 17:23:20 +1300 Subject: [PATCH 4/4] enhancement/OP-7955_Context_Validation_Repair_Action_enhancement --- .../hosts/maya/plugins/publish/collect_instances.py | 9 +++++++++ .../hosts/maya/plugins/publish/validate_frame_range.py | 2 +- .../hosts/maya/plugins/publish/validate_resolution.py | 2 +- .../plugins/publish/collect_context_entities.py | 5 ----- 4 files changed, 11 insertions(+), 7 deletions(-) diff --git a/client/ayon_core/hosts/maya/plugins/publish/collect_instances.py b/client/ayon_core/hosts/maya/plugins/publish/collect_instances.py index 0b29851db0..03412f3301 100644 --- a/client/ayon_core/hosts/maya/plugins/publish/collect_instances.py +++ b/client/ayon_core/hosts/maya/plugins/publish/collect_instances.py @@ -3,6 +3,8 @@ import pyblish.api from ayon_core.hosts.maya.api.lib import get_all_children +from ayon_api import get_task_by_name + class CollectNewInstances(pyblish.api.InstancePlugin): """Gather members for instances and pre-defined attribute @@ -91,6 +93,13 @@ def process(self, instance): instance.data["frameEnd"] + instance.data["handleEnd"] ) + project_name = instance.context.data["projectName"] + asset_entity = instance.context.data["assetEntity"] + task_name = instance.data["task"] + task_entity = get_task_by_name( + project_name, asset_entity["_id"], task_name) + instance.data["taskEntity"] = task_entity + def get_all_parents(self, nodes): """Get all parents by using string operations (optimization) diff --git a/client/ayon_core/hosts/maya/plugins/publish/validate_frame_range.py b/client/ayon_core/hosts/maya/plugins/publish/validate_frame_range.py index 5e858aa5c3..5bad2a4529 100644 --- a/client/ayon_core/hosts/maya/plugins/publish/validate_frame_range.py +++ b/client/ayon_core/hosts/maya/plugins/publish/validate_frame_range.py @@ -235,7 +235,7 @@ def get_instance_task_frame_range(instance): # Get frame information from task entity # NOTE: If there is no task override then the asset # value is automatically returned instead - attrib = instance.context.data["taskEntity"]["attrib"] + attrib = instance.data["taskEntity"]["attrib"] return FrameRange( frame_start=attrib["frameStart"], frame_end=attrib["frameEnd"], diff --git a/client/ayon_core/hosts/maya/plugins/publish/validate_resolution.py b/client/ayon_core/hosts/maya/plugins/publish/validate_resolution.py index 3310d7ff53..32064b9c2c 100644 --- a/client/ayon_core/hosts/maya/plugins/publish/validate_resolution.py +++ b/client/ayon_core/hosts/maya/plugins/publish/validate_resolution.py @@ -84,7 +84,7 @@ def get_invalid_resolution(cls, instance): @classmethod def get_db_resolution(cls, instance): - task_doc = instance.context.data["taskEntity"] + task_doc = instance.data["taskEntity"] asset_doc = instance.data["assetEntity"] project_doc = instance.context.data["projectEntity"] for data in [ diff --git a/client/ayon_core/plugins/publish/collect_context_entities.py b/client/ayon_core/plugins/publish/collect_context_entities.py index d8596e5937..8480435e21 100644 --- a/client/ayon_core/plugins/publish/collect_context_entities.py +++ b/client/ayon_core/plugins/publish/collect_context_entities.py @@ -14,7 +14,6 @@ import pyblish.api -from ayon_api import get_task_by_name from ayon_core.client import get_project, get_asset_by_name from ayon_core.pipeline import KnownPublishError @@ -52,10 +51,6 @@ def process(self, context): context.data["assetEntity"] = asset_entity - task_entity = get_task_by_name( - project_name, asset_entity["_id"], task_name) - context.data["taskEntity"] = task_entity - data = asset_entity['data'] # Task type