From 7b2339559432972a993a4d5d849c9a2f42d57580 Mon Sep 17 00:00:00 2001 From: Bogdan Nagirniak Date: Tue, 11 Apr 2023 13:26:59 +0300 Subject: [PATCH] Make FILE_PATH in generated node classes to be local for MX_LIBS_DIR and MX_ADDON_LIBS_DIR. Adde blender.shared to BL_DATA_DIR for Windows. --- materialx/nodes/generate_node_classes.py | 14 ++++++++++++++ materialx/utils.py | 3 +++ 2 files changed, 17 insertions(+) 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 fbb1bb21d..a9a680f2e 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 -- 2.30.2