diff --git a/materialx/nodes/generate_node_classes.py b/materialx/nodes/generate_node_classes.py index f3e897c3d..0c39a4596 100644 --- a/materialx/nodes/generate_node_classes.py +++ b/materialx/nodes/generate_node_classes.py @@ -274,7 +274,21 @@ from bpy.props import ( ) from {ADDON_ALIAS}.nodes.node import MxNode +""") + if file_path.is_relative_to(utils.MX_LIBS_DIR): + code_strings.append( +f"""from {ADDON_ALIAS}.utils import MX_LIBS_DIR +FILE_PATH = MX_LIBS_DIR / "{(file_path.relative_to(utils.MX_LIBS_DIR)).as_posix()}" +""") + elif file_path.is_relative_to(utils.MX_ADDON_LIBS_DIR): + code_strings.append( +f"""from {ADDON_ALIAS}.utils import MX_ADDON_LIBS_DIR +FILE_PATH = MX_ADDON_LIBS_DIR / "{(file_path.relative_to(utils.MX_ADDON_LIBS_DIR)).as_posix()}" +""") + else: + code_strings.append( +f""" FILE_PATH = "{file_path.as_posix()}" """) diff --git a/materialx/utils.py b/materialx/utils.py index 6964386a4..b6d20bfa6 100644 --- a/materialx/utils.py +++ b/materialx/utils.py @@ -5,6 +5,7 @@ import os from pathlib import Path import tempfile import shutil +import platform import MaterialX as mx import bpy @@ -17,6 +18,8 @@ log = logging.Log('utils') ADDON_ROOT_DIR = Path(__file__).parent ADDON_DATA_DIR = Path(bpy.utils.user_resource('SCRIPTS', path=f"addons/{ADDON_ALIAS}_data", create=True)) BL_DATA_DIR = Path(bpy.utils.resource_path('LOCAL')).parent / "materialx" +if platform.system() == 'Windows': + BL_DATA_DIR = BL_DATA_DIR.parent / "blender.shared" / BL_DATA_DIR.name MX_LIBS_FOLDER = "libraries" MX_LIBS_DIR = BL_DATA_DIR / MX_LIBS_FOLDER