From 00a87819e492980d13f030f3765083e926f555cf Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Mon, 12 Jun 2023 16:04:14 +0500 Subject: [PATCH] switch to external styles for rendered shading in viewport Unfortunately I couldn't find a way to make it work with areas that user created during current blender session. But new areas will have this feature too after blender restart --- src/blenderbim/blenderbim/bim/handler.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/blenderbim/blenderbim/bim/handler.py b/src/blenderbim/blenderbim/bim/handler.py index 5c7888bb0f..9fff5d4836 100644 --- a/src/blenderbim/blenderbim/bim/handler.py +++ b/src/blenderbim/blenderbim/bim/handler.py @@ -259,6 +259,12 @@ def get_application_version(): ) +def viewport_shading_changed_callback(area): + shading = area.spaces.active.shading.type + if shading == "RENDERED": + bpy.context.scene.BIMStylesProperties.active_style_type = "External" + + @persistent def setDefaultProperties(scene): global global_subscription_owner @@ -266,6 +272,21 @@ def setDefaultProperties(scene): bpy.msgbus.subscribe_rna( key=active_object_key, owner=global_subscription_owner, args=(), notify=active_object_callback ) + + # subscribe to changes in viewport shading mode + # NOTE: couldn't find a way to make it work for new areas too + # it starts working for them after blender restart though + for screen in bpy.data.screens: + for area in screen.areas: + if area.type != "VIEW_3D": + continue + shading = area.spaces.active.shading + key = shading.path_resolve("type", False) + + bpy.msgbus.subscribe_rna( + key=key, owner=global_subscription_owner, args=(area,), notify=viewport_shading_changed_callback + ) + ifcopenshell.api.owner.settings.get_user = lambda ifc: core_owner.get_user(tool.Owner) ifcopenshell.api.owner.settings.get_application = get_application AuthoringData.type_thumbnails = {}