Skip to content

collect_xgen

CollectXgen

Bases: MayaInstancePlugin

Collect Xgen

Source code in client/ayon_maya/plugins/publish/collect_xgen.py
 9
10
11
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
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
class CollectXgen(plugin.MayaInstancePlugin):
    """Collect Xgen"""

    order = pyblish.api.CollectorOrder + 0.499999
    label = "Collect Xgen"
    families = ["xgen"]

    def process(self, instance):
        data = {
            "xgmPalettes": cmds.ls(instance, type="xgmPalette", long=True),
            "xgmDescriptions": cmds.ls(
                instance, type="xgmDescription", long=True
            ),
            "xgmSubdPatches": cmds.ls(instance, type="xgmSubdPatch", long=True)
        }
        data["xgenNodes"] = (
            data["xgmPalettes"] +
            data["xgmDescriptions"] +
            data["xgmSubdPatches"]
        )

        if data["xgmPalettes"]:
            data["xgmPalette"] = data["xgmPalettes"][0]

        data["xgenConnections"] = set()
        for node in data["xgmSubdPatches"]:
            connected_transform = get_attribute_input(
                node + ".transform"
            ).split(".")[0]
            data["xgenConnections"].add(connected_transform)

        # Collect all files under palette root as resources.
        import xgenm

        data_path = xgenm.getAttr(
            "xgDataPath", data["xgmPalette"].replace("|", "")
        ).split(os.pathsep)[0]
        data_path = data_path.replace(
            "${PROJECT}",
            xgenm.getAttr("xgProjectPath", data["xgmPalette"].replace("|", ""))
        )
        transfers = []

        # Since we are duplicating this palette when extracting we predict that
        # the name will be the basename without namespaces.
        predicted_palette_name = data["xgmPalette"].split(":")[-1]
        predicted_palette_name = predicted_palette_name.replace("|", "")

        for root, _, files in os.walk(data_path):
            for file in files:
                source = os.path.join(root, file).replace("\\", "/")
                destination = os.path.join(
                    instance.data["resourcesDir"],
                    "collections",
                    predicted_palette_name,
                    source.replace(data_path, "")[1:]
                )
                transfers.append((source, destination.replace("\\", "/")))

        data["transfers"] = transfers

        self.log.debug(data)
        instance.data.update(data)