From 39d2159ed462e3e84236ba4497277d2a7f65016a Mon Sep 17 00:00:00 2001 From: Simone Barbieri Date: Thu, 22 Jun 2023 10:57:23 +0100 Subject: [PATCH] Blender: Add support for custom path for app templates (#5137) * Add support for custom path for app templates * Use same env variable as scripts and assure correct path exist --- openpype/hosts/blender/api/lib.py | 21 +++++++++++++++++++++ openpype/hosts/blender/api/pipeline.py | 1 + 2 files changed, 22 insertions(+) diff --git a/openpype/hosts/blender/api/lib.py b/openpype/hosts/blender/api/lib.py index 6526f1fb87..9bb560c364 100644 --- a/openpype/hosts/blender/api/lib.py +++ b/openpype/hosts/blender/api/lib.py @@ -134,6 +134,27 @@ def append_user_scripts(): traceback.print_exc() +def set_app_templates_path(): + # Blender requires the app templates to be in `BLENDER_USER_SCRIPTS`. + # After running Blender, we set that variable to our custom path, so + # that the user can use their custom app templates. + + # We look among the scripts paths for one of the paths that contains + # the app templates. The path must contain the subfolder + # `startup/bl_app_templates_user`. + paths = os.environ.get("OPENPYPE_BLENDER_USER_SCRIPTS").split(os.pathsep) + + app_templates_path = None + for path in paths: + if os.path.isdir( + os.path.join(path, "startup", "bl_app_templates_user")): + app_templates_path = path + break + + if app_templates_path and os.path.isdir(app_templates_path): + os.environ["BLENDER_USER_SCRIPTS"] = app_templates_path + + def imprint(node: bpy.types.bpy_struct_meta_idprop, data: Dict): r"""Write `data` to `node` as userDefined attributes diff --git a/openpype/hosts/blender/api/pipeline.py b/openpype/hosts/blender/api/pipeline.py index 9cc557c01a..0f756d8cb6 100644 --- a/openpype/hosts/blender/api/pipeline.py +++ b/openpype/hosts/blender/api/pipeline.py @@ -60,6 +60,7 @@ def install(): register_creator_plugin_path(str(CREATE_PATH)) lib.append_user_scripts() + lib.set_app_templates_path() register_event_callback("new", on_new) register_event_callback("open", on_open)