Skip to content

remap_to_publish

AYONRemapPaths

Bases: OutputProcessor

Remap paths based on a mapping dict on rop node.

Source code in client/ayon_houdini/startup/husdplugins/outputprocessors/remap_to_publish.py
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
72
class AYONRemapPaths(OutputProcessor):
    """Remap paths based on a mapping dict on rop node."""

    def __init__(self):
        self._mapping = dict()

    @staticmethod
    def name():
        return "ayon_remap_paths"

    @staticmethod
    def displayName():
        return "AYON Remap Paths"

    @staticmethod
    def hidden():
        return True

    @staticmethod
    def parameters():
        group = hou.ParmTemplateGroup()

        parm_template = hou.StringParmTemplate(
            "ayon_remap_paths_remap_json",
            "Remapping dict (json)",
            default_value="{}",
            num_components=1,
            string_type=hou.stringParmType.Regular,
        )
        group.append(parm_template)

        return group.asDialogScript()

    def beginSave(self,
                  config_node,
                  config_overrides,
                  lop_node,
                  t,
                  # Added in Houdini 20.5.182
                  stage_variables=_COMPATIBILITY_PLACEHOLDER):

        args = [config_node, config_overrides, lop_node, t]
        if stage_variables is not _COMPATIBILITY_PLACEHOLDER:
            args.append(stage_variables)
        super(AYONRemapPaths, self).beginSave(*args)

        value = config_node.evalParm("ayon_remap_paths_remap_json")
        mapping = json.loads(value)
        assert isinstance(self._mapping, dict)

        # Ensure all keys are normalized paths so the lookup can be done
        # correctly
        mapping = {
            os.path.normpath(key): value for key, value in mapping.items()
        }
        self._mapping = mapping

    def processReferencePath(self,
                             asset_path,
                             referencing_layer_path,
                             asset_is_layer):
        return self._mapping.get(os.path.normpath(asset_path), asset_path)