Skip to content

action

GenerateUUIDsOnInvalidAction

Bases: Action

Generate UUIDs on the invalid nodes in the instance.

Invalid nodes are those returned by the plugin's get_invalid method. As such it is the plug-in's responsibility to ensure the nodes that receive new UUIDs are actually invalid.

Requires
  • instance.data["folderPath"]
Source code in client/ayon_maya/api/action.py
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
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
class GenerateUUIDsOnInvalidAction(pyblish.api.Action):
    """Generate UUIDs on the invalid nodes in the instance.

    Invalid nodes are those returned by the plugin's `get_invalid` method.
    As such it is the plug-in's responsibility to ensure the nodes that
    receive new UUIDs are actually invalid.

    Requires:
        - instance.data["folderPath"]

    """

    label = "Regenerate UUIDs"
    on = "failed"  # This action is only available on a failed plug-in
    icon = "wrench"  # Icon from Awesome Icon

    def process(self, context, plugin):

        from maya import cmds

        self.log.info("Finding bad nodes..")

        errored_instances = get_errored_instances_from_context(context)

        # Apply pyblish logic to get the instances for the plug-in
        instances = pyblish.api.instances_by_plugin(errored_instances, plugin)

        # Get the nodes from the all instances that ran through this plug-in
        all_invalid = []
        for instance in instances:
            invalid = plugin.get_invalid(instance)

            # Don't allow referenced nodes to get their ids regenerated to
            # avoid loaded content getting messed up with reference edits
            if invalid:
                referenced = {node for node in invalid if
                              cmds.referenceQuery(node, isNodeReferenced=True)}
                if referenced:
                    self.log.warning("Skipping UUID generation on referenced "
                                     "nodes: {}".format(list(referenced)))
                    invalid = [node for node in invalid
                               if node not in referenced]

            if invalid:

                self.log.info("Fixing instance {}".format(instance.name))
                self._update_id_attribute(instance, invalid)

                all_invalid.extend(invalid)

        if not all_invalid:
            self.log.info("No invalid nodes found.")
            return

        all_invalid = list(set(all_invalid))
        self.log.info("Generated ids on nodes: {0}".format(all_invalid))

    def _update_id_attribute(self, instance, nodes):
        """Delete the id attribute

        Args:
            instance: The instance we're fixing for
            nodes (list): all nodes to regenerate ids on
        """

        from . import lib

        # Expecting this is called on validators in which case 'folderEntity'
        #   should be always available, but kept a way to query it by name.
        folder_entity = instance.data.get("folderEntity")
        if not folder_entity:
            folder_path = instance.data["folderPath"]
            project_name = instance.context.data["projectName"]
            self.log.info((
                "Folder is not stored on instance."
                " Querying by path \"{}\" from project \"{}\""
            ).format(folder_path, project_name))
            folder_entity = ayon_api.get_folder_by_path(
                project_name, folder_path, fields={"id"}
            )

        for node, _id in lib.generate_ids(
            nodes, folder_id=folder_entity["id"]
        ):
            lib.set_id(node, _id, overwrite=True)

SelectInvalidAction

Bases: Action

Select invalid nodes in Maya when plug-in failed.

To retrieve the invalid nodes this assumes a static get_invalid() method is available on the plugin.

Source code in client/ayon_maya/api/action.py
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
class SelectInvalidAction(pyblish.api.Action):
    """Select invalid nodes in Maya when plug-in failed.

    To retrieve the invalid nodes this assumes a static `get_invalid()`
    method is available on the plugin.

    """
    label = "Select invalid"
    on = "failed"  # This action is only available on a failed plug-in
    icon = "search"  # Icon from Awesome Icon

    def process(self, context, plugin):

        try:
            from maya import cmds
        except ImportError:
            raise ImportError("Current host is not Maya")

        # Get the invalid nodes for the plug-ins
        self.log.info("Finding invalid nodes..")
        invalid = list()
        if issubclass(plugin, pyblish.api.ContextPlugin):
            errored_plugins = get_errored_plugins_from_context(context)
            if plugin in errored_plugins:
                invalid = plugin.get_invalid(context)
        else:
            errored_instances = get_errored_instances_from_context(
                context, plugin=plugin
            )
            for instance in errored_instances:
                invalid_nodes = plugin.get_invalid(instance)
                if invalid_nodes:
                    if isinstance(invalid_nodes, (list, tuple)):
                        invalid.extend(invalid_nodes)
                    else:
                        self.log.warning("Plug-in returned to be invalid, "
                                         "but has no selectable nodes.")

        # Ensure unique (process each node only once)
        invalid = list(set(invalid))

        if invalid:
            self.log.info("Selecting invalid nodes: %s" % ", ".join(invalid))
            cmds.select(invalid, replace=True, noExpand=True)
        else:
            self.log.info("No invalid nodes found.")
            cmds.select(deselect=True)