Merge pull request #340 from ynput/enhancement/AY-1052_Context-Validation-Repair-Action-enhancements

Maya: Support to validate/repair the task attributes in validate data in same context
This commit is contained in:
Kayla Man 2024-04-10 15:12:20 +08:00 committed by GitHub
commit bc0cd8dd81
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 30 additions and 31 deletions

View file

@ -38,15 +38,15 @@ class ValidateInstanceInContext(pyblish.api.InstancePlugin,
context_label = "{} > {}".format(*context)
instance_label = "{} > {}".format(folderPath, task)
message = (
"Instance '{}' publishes to different context than current "
"context: {}. Current context: {}".format(
"Instance '{}' publishes to different folder or task "
"than current context: {}. Current context: {}".format(
instance.name, instance_label, context_label
)
)
raise PublishValidationError(
message=message,
description=(
"## Publishing to a different context data\n"
"## Publishing to a different context folder or task\n"
"There are publish instances present which are publishing "
"into a different folder path or task than your current context.\n\n"
"Usually this is not what you want but there can be cases "

View file

@ -11,8 +11,6 @@ from ayon_core.pipeline.publish import (
OptionalPyblishPluginMixin
)
from maya import cmds
class ValidateInstanceInContext(pyblish.api.InstancePlugin,
OptionalPyblishPluginMixin):
@ -38,17 +36,20 @@ class ValidateInstanceInContext(pyblish.api.InstancePlugin,
return
folder_path = instance.data.get("folderPath")
context_folder_path = self.get_context_folder_path(instance)
if folder_path != context_folder_path:
task = instance.data.get("task")
context = self.get_context(instance)
if (folder_path, task) != context:
context_label = "{} > {}".format(*context)
instance_label = "{} > {}".format(folder_path, task)
raise PublishValidationError(
message=(
"Instance '{}' publishes to different folder than current"
"Instance '{}' publishes to different context than current"
" context: {}. Current context: {}".format(
instance.name, folder_path, context_folder_path
instance.name, instance_label, context_label
)
),
description=(
"## Publishing to a different folder\n"
"## Publishing to a different context data\n"
"There are publish instances present which are publishing "
"into a different folder than your current context.\n\n"
"Usually this is not what you want but there can be cases "
@ -64,14 +65,20 @@ class ValidateInstanceInContext(pyblish.api.InstancePlugin,
@classmethod
def repair(cls, instance):
context_folder_path = cls.get_context_folder_path(instance)
instance_node = instance.data["instance_node"]
cmds.setAttr(
"{}.folderPath".format(instance_node),
context_folder_path,
type="string"
context_folder_path, context_task = cls.get_context(
instance)
create_context = instance.context.data["create_context"]
instance_id = instance.data["instance_id"]
created_instance = create_context.get_instance_by_id(
instance_id
)
created_instance["folderPath"] = context_folder_path
created_instance["task"] = context_task
create_context.save_changes()
@staticmethod
def get_context_folder_path(instance):
return instance.context.data["folderPath"]
def get_context(instance):
"""Return asset, task from publishing context data"""
context = instance.context
return context.data["folderPath"], context.data["task"]

View file

@ -84,19 +84,11 @@ class ValidateResolution(pyblish.api.InstancePlugin,
@classmethod
def get_folder_resolution(cls, instance):
folder_attributes = instance.data["folderEntity"]["attrib"]
if (
"resolutionWidth" in folder_attributes
and "resolutionHeight" in folder_attributes
and "pixelAspect" in folder_attributes
):
width = folder_attributes["resolutionWidth"]
height = folder_attributes["resolutionHeight"]
pixelAspect = folder_attributes["pixelAspect"]
return int(width), int(height), float(pixelAspect)
# Defaults if not found in asset document or project document
return 1920, 1080, 1.0
task_attributes = instance.data["taskEntity"]["attrib"]
width = task_attributes["resolutionWidth"]
height = task_attributes["resolutionHeight"]
pixel_aspect = task_attributes["pixelAspect"]
return int(width), int(height), float(pixel_aspect)
@classmethod
def repair(cls, instance):