Skip to content

validate_instance_asset

ValidateInstanceAsset

Bases: OptionalPyblishPluginMixin, InstancePlugin

Validate the instance folder is the current selected context folder.

As it might happen that multiple worfiles are opened, switching between them would mess with selected context. In that case outputs might be output under wrong folder!

Repair action will use Context folder value (from Workfiles or Launcher) Closing and reopening with Workfiles will refresh Context value.

Source code in client/ayon_photoshop/plugins/publish/validate_instance_asset.py
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
class ValidateInstanceAsset(OptionalPyblishPluginMixin,
                            pyblish.api.InstancePlugin):
    """Validate the instance folder is the current selected context folder.

    As it might happen that multiple worfiles are opened, switching
    between them would mess with selected context.
    In that case outputs might be output under wrong folder!

    Repair action will use Context folder value (from Workfiles or Launcher)
    Closing and reopening with Workfiles will refresh  Context value.
    """

    label = "Validate Instance Folder"
    hosts = ["photoshop"]
    optional = True
    actions = [ValidateInstanceFolderRepair]
    order = ValidateContentsOrder

    def process(self, instance):
        instance_folder_path = instance.data["folderPath"]
        current_folder_path = get_current_folder_path()

        if instance_folder_path != current_folder_path:
            msg = (
                f"Instance folder {instance_folder_path} is not the same"
                f" as current context {current_folder_path}."

            )
            repair_msg = (
                "Repair with 'Repair' button"
                f" to use '{current_folder_path}'.\n"
            )
            formatting_data = {"msg": msg,
                               "repair_msg": repair_msg}
            raise PublishXmlValidationError(self, msg,
                                            formatting_data=formatting_data)

ValidateInstanceFolderRepair

Bases: Action

Repair the instance folder.

Source code in client/ayon_photoshop/plugins/publish/validate_instance_asset.py
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
class ValidateInstanceFolderRepair(pyblish.api.Action):
    """Repair the instance folder."""

    label = "Repair"
    icon = "wrench"
    on = "failed"

    def process(self, context, plugin):

        # Get the errored instances
        failed = []
        for result in context.data["results"]:
            if (
                result["error"] is not None
                and result["instance"] is not None
                and result["instance"] not in failed
            ):
                failed.append(result["instance"])

        # Apply pyblish.logic to get the instances for the plug-in
        instances = pyblish.api.instances_by_plugin(failed, plugin)
        stub = photoshop.stub()
        current_folder_path = get_current_folder_path()
        for instance in instances:
            data = stub.read(instance[0])
            data["folderPath"] = current_folder_path
            stub.imprint(instance[0], data)