Skip to content

validate_resolution_setting

ValidateResolution

Bases: InstancePlugin, OptionalPyblishPluginMixin

Validate the resolution setting aligned with DB

Source code in client/ayon_blender/plugins/publish/validate_resolution_setting.py
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
class ValidateResolution(pyblish.api.InstancePlugin,
                         OptionalPyblishPluginMixin):
    """Validate the resolution setting aligned with DB"""

    order = pyblish.api.ValidatorOrder - 0.01
    families = ["render", "review"]
    hosts = ["blender"]
    label = "Validate Resolution"
    optional = True
    actions = [RepairAction]

    def process(self, instance: pyblish.api.Instance) -> None:
        if not self.is_active(instance.data):
            return

        context_resolution = self.get_context_resolution(instance)
        if context_resolution is None:
            self.log.debug(
                "Skipping resolution validation for instance '%s': no "
                "task or folder entity resolution found.", instance.name
            )
            return
        width, height = context_resolution 
        current_width, current_height = self.get_current_resolution()
        if (current_width, current_height) != (width, height):
            raise PublishValidationError(
                "Resolution is incorrect.\n\n"
                f"Current resolution: {current_width}x{current_height}\n"
                f"Expected resolution: {width}x{height}\n\n"
                "The expected resolution is set on the task context. "
                "You can use the repair action to set it.",
                title="Incorrect Resolution",
            )

    def get_current_resolution(self) -> tuple[int, int]:
        """Get the current resolution from the instance data.

        Returns:
            tuple[int, int]: The current resolution (width, height).
        """
        return (
            bpy.context.scene.render.resolution_x,
            bpy.context.scene.render.resolution_y,
        )

    @classmethod
    def get_context_resolution(
        cls,
        instance: pyblish.api.Instance
    ) -> Optional[tuple[int, int]]:
        """Get the resolution set on the task (or folder if no task).

        Args:
            instance (pyblish.api.Instance): The instance to get the
                task or folder resolution from.

        Returns:
            Optional[tuple[int, int]]: The resolution set on the entity
                (width, height), or None when the task/folder entity does
                not define a resolution.
        """
        entity = (
            instance.data.get("taskEntity")
            or instance.data.get("folderEntity")
        )
        if entity:
            attributes = entity["attrib"]
            width = attributes.get("resolutionWidth")
            height = attributes.get("resolutionHeight")
            if width is not None and height is not None:
                return int(width), int(height)

        return None

    @classmethod
    def repair(cls, instance: pyblish.api.Instance) -> None:
        """Repair the resolution setting for the instance.

        Args:
            instance (pyblish.api.Instance): The instance to repair
                the resolution for.
        """
        entity = (
            instance.data.get("taskEntity")
            or instance.data.get("folderEntity")
        )
        set_resolution(entity)

get_context_resolution(instance) classmethod

Get the resolution set on the task (or folder if no task).

Parameters:

Name Type Description Default
instance Instance

The instance to get the task or folder resolution from.

required

Returns:

Type Description
Optional[tuple[int, int]]

Optional[tuple[int, int]]: The resolution set on the entity (width, height), or None when the task/folder entity does not define a resolution.

Source code in client/ayon_blender/plugins/publish/validate_resolution_setting.py
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
@classmethod
def get_context_resolution(
    cls,
    instance: pyblish.api.Instance
) -> Optional[tuple[int, int]]:
    """Get the resolution set on the task (or folder if no task).

    Args:
        instance (pyblish.api.Instance): The instance to get the
            task or folder resolution from.

    Returns:
        Optional[tuple[int, int]]: The resolution set on the entity
            (width, height), or None when the task/folder entity does
            not define a resolution.
    """
    entity = (
        instance.data.get("taskEntity")
        or instance.data.get("folderEntity")
    )
    if entity:
        attributes = entity["attrib"]
        width = attributes.get("resolutionWidth")
        height = attributes.get("resolutionHeight")
        if width is not None and height is not None:
            return int(width), int(height)

    return None

get_current_resolution()

Get the current resolution from the instance data.

Returns:

Type Description
tuple[int, int]

tuple[int, int]: The current resolution (width, height).

Source code in client/ayon_blender/plugins/publish/validate_resolution_setting.py
49
50
51
52
53
54
55
56
57
58
def get_current_resolution(self) -> tuple[int, int]:
    """Get the current resolution from the instance data.

    Returns:
        tuple[int, int]: The current resolution (width, height).
    """
    return (
        bpy.context.scene.render.resolution_x,
        bpy.context.scene.render.resolution_y,
    )

repair(instance) classmethod

Repair the resolution setting for the instance.

Parameters:

Name Type Description Default
instance Instance

The instance to repair the resolution for.

required
Source code in client/ayon_blender/plugins/publish/validate_resolution_setting.py
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
@classmethod
def repair(cls, instance: pyblish.api.Instance) -> None:
    """Repair the resolution setting for the instance.

    Args:
        instance (pyblish.api.Instance): The instance to repair
            the resolution for.
    """
    entity = (
        instance.data.get("taskEntity")
        or instance.data.get("folderEntity")
    )
    set_resolution(entity)