From 83b56d591b573274fde1890756070e3d4334bd55 Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Tue, 11 Nov 2025 13:16:11 +0500 Subject: [PATCH] Fix error activating drawing style Example error: ``` TypeError: bpy_struct: item.attr = val: enum "Default" not found in ('city.exr', 'courtyard.exr', 'forest.exr', 'interior.exr', 'night.exr', 'studio.exr', 'sunrise.exr', 'sunset.exr') ``` There was a bug in shading_styles.json where we were using `Default` for `studio_light`, which is only available for `SOLID` shading type. Changed value to `forest.exr`, added code to handle old bugged value since users already copied and possibly modified shading_styles.json --- .../bim/data/assets/shading_styles.json | 4 +-- .../bonsai/bim/module/drawing/operator.py | 26 ++++++++++++++++++- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/src/bonsai/bonsai/bim/data/assets/shading_styles.json b/src/bonsai/bonsai/bim/data/assets/shading_styles.json index e4daf97124..cf88db2949 100644 --- a/src/bonsai/bonsai/bim/data/assets/shading_styles.json +++ b/src/bonsai/bonsai/bim/data/assets/shading_styles.json @@ -355,7 +355,7 @@ 1.0, 1.0 ], - "scene.display.shading.studio_light": "Default", + "scene.display.shading.studio_light": "forest.exr", "scene.display.shading.studiolight_background_alpha": 0.0, "scene.display.shading.studiolight_background_blur": 0.0, "scene.display.shading.studiolight_intensity": 0.0, @@ -594,7 +594,7 @@ 0.800000011920929, 0.800000011920929 ], - "scene.display.shading.studio_light": "Default", + "scene.display.shading.studio_light": "forest.exr", "scene.display.shading.studiolight_background_alpha": 0.0, "scene.display.shading.studiolight_background_blur": 0.0, "scene.display.shading.studiolight_intensity": 0.0, diff --git a/src/bonsai/bonsai/bim/module/drawing/operator.py b/src/bonsai/bonsai/bim/module/drawing/operator.py index a76e187566..6379351de5 100644 --- a/src/bonsai/bonsai/bim/module/drawing/operator.py +++ b/src/bonsai/bonsai/bim/module/drawing/operator.py @@ -2703,6 +2703,8 @@ class ActivateDrawingStyle(bpy.types.Operator, tool.Ifc.Operator): assert (space := tool.Blender.get_view3d_space()) # Do not remove. It is used in exec later style: dict[str, Any] = json.loads(self.drawing_style.raster_style) + VIEWPORT_SHADING_TYPE = "scene.display.shading.type" + def preprocess(path: str, value: Any) -> tuple[str, Any, bool, bool]: warning = False skip = False @@ -2737,6 +2739,19 @@ class ActivateDrawingStyle(bpy.types.Operator, tool.Ifc.Operator): ) warning = True skip = True + # @25.11.11 + elif ( + path == "scene.display.shading.studio_light" + and value == "Default" + and style[VIEWPORT_SHADING_TYPE] in ("RENDERED", "MATERIAL") + ): + value = "forest.exr" + print( + f"Warning: Value 'Default' for property '{path}' and " + f"'{VIEWPORT_SHADING_TYPE}' = '{style[VIEWPORT_SHADING_TYPE]}' is outdated " + "and should be replaced with 'forest.exr' in shading_styles.json." + ) + warning = True # @25.05.12 elif path == "scene.display.shading.wireframe_color_type" and value == "MATERIAL": value = "THEME" @@ -2772,7 +2787,16 @@ class ActivateDrawingStyle(bpy.types.Operator, tool.Ifc.Operator): return path, value, warning, skip - for path, value in style.items(): + paths = list(style.keys()) + PRIORITY_PATHS = ( + # `scene.display.shading.studio_light` values depend on `.type` + # so we got to set it first. + VIEWPORT_SHADING_TYPE, + ) + paths.sort(key=lambda p: p not in PRIORITY_PATHS) + + for path in paths: + value = style[path] path, value, warning, skip = preprocess(path, value) self.has_warnings_during_activation |= warning