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)
 |