diff --git a/client/ayon_nuke/plugins/load/load_effects.py b/client/ayon_nuke/plugins/load/load_effects.py index 994281c1d5..8089a236e2 100644 --- a/client/ayon_nuke/plugins/load/load_effects.py +++ b/client/ayon_nuke/plugins/load/load_effects.py @@ -1,7 +1,8 @@ import json import nuke - +from ayon_core.lib import StringTemplate +from ayon_core.pipeline import Anatomy, get_current_project_name from ayon_nuke.api import plugin @@ -28,8 +29,7 @@ def on_update(self, group_node, namespace, context): return group_node def connect_read_node(self, group_node, namespace, product_name): - """ - Finds read node and selects it + """Finds read node and selects it Arguments: group_node (nuke.Node): Group node to connect to. @@ -40,7 +40,7 @@ def connect_read_node(self, group_node, namespace, product_name): nuke node: node is selected None: if nothing found """ - search_name = "{0}_{1}".format(namespace, product_name) + search_name = f"{namespace}_{product_name}" read_node = next( ( @@ -65,9 +65,8 @@ def connect_read_node(self, group_node, namespace, product_name): def _load_effects_to_group( self, context: dict, group_node: nuke.Node) -> str: """Load the json file and create nodes inside the group node""" - file = self.filepath_from_context(context).replace("\\", "/") - with open(file, "r") as f: + with open(file) as f: json_f = json.load(f) # get correct order of nodes by positions on track and subtrack @@ -85,7 +84,6 @@ def _load_effects_to_group( def _create_nodes_order(self, nodes_order: dict): workfile_first_frame = int(nuke.root()["first_frame"].getValue()) - # create input node pre_node = nuke.createNode("Input") pre_node["name"].setValue("rgb") @@ -103,6 +101,26 @@ def _create_nodes_order(self, nodes_order: dict): self.log.warning(e) continue + # check if `file` in knob name then format the path + # so it is multiplatform compatible + if k == "file": + file_path = v + project_name = get_current_project_name() + anatomy = Anatomy(project_name=project_name) + _template_data = { + "root": anatomy.roots, + } + success, rootless_path = \ + anatomy.find_root_template_from_path(file_path) + + self.log.info(f"rootless_path: {rootless_path}") + if success: + abs_resources_path = StringTemplate.format_strict_template( + rootless_path, _template_data + ) + v = abs_resources_path + self.log.info(f"File path: {abs_resources_path}") + # Set node attribute values if isinstance(v, list) and len(v) > 4: node[k].setAnimated() @@ -151,7 +169,6 @@ def _get_item( if track_index == val["trackIndex"]} - class LoadEffectsInputProcess(LoadEffects): """Loading colorspace soft effect exported from nukestudio""" @@ -169,4 +186,4 @@ def on_load(self, group_node, namespace, context): def on_update(self, group_node, namespace, context): # No post-process on update # Only overridden to avoid behavior of LoadEffects - return group_node \ No newline at end of file + return group_node