From dac1aaa7f342c1120f912731d6534b2644d449f9 Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Sat, 31 Aug 2024 13:25:11 +0500 Subject: [PATCH] Errors adding roof, stair, railing types #5261 It wasn't considering that type object can be hidden and can't be active. Removed obj property since it can be covered with just temp_override. --- src/bonsai/bonsai/bim/module/model/door.py | 10 +++++----- src/bonsai/bonsai/bim/module/model/window.py | 10 +++++----- src/bonsai/bonsai/bim/module/type/operator.py | 20 +++++++++---------- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/bonsai/bonsai/bim/module/model/door.py b/src/bonsai/bonsai/bim/module/model/door.py index 4e9a826104..1483b47482 100644 --- a/src/bonsai/bonsai/bim/module/model/door.py +++ b/src/bonsai/bonsai/bim/module/model/door.py @@ -40,7 +40,8 @@ import json import collections -def update_door_modifier_representation(context: bpy.types.Context, obj: bpy.types.Object) -> None: +def update_door_modifier_representation(context: bpy.types.Context) -> None: + obj = context.active_object props = obj.BIMDoorProperties element = tool.Ifc.get_entity(obj) ifc_file = tool.Ifc.get() @@ -534,10 +535,9 @@ class AddDoor(bpy.types.Operator, tool.Ifc.Operator): bl_idname = "bim.add_door" bl_label = "Add Door" bl_options = {"REGISTER"} - obj: bpy.props.StringProperty() def _execute(self, context): - obj = bpy.data.objects.get(self.obj) if self.obj else context.active_object + obj = context.active_object element = tool.Ifc.get_entity(obj) props = obj.BIMDoorProperties @@ -558,7 +558,7 @@ class AddDoor(bpy.types.Operator, tool.Ifc.Operator): pset=pset, properties={"Data": tool.Ifc.get().createIfcText(json.dumps(door_data, default=list))}, ) - update_door_modifier_representation(context, obj) + update_door_modifier_representation(context) return {"FINISHED"} @@ -612,7 +612,7 @@ class FinishEditingDoor(bpy.types.Operator, tool.Ifc.Operator): props.is_editing = False - update_door_modifier_representation(context, obj) + update_door_modifier_representation(context) pset = tool.Pset.get_element_pset(element, "BBIM_Door") door_data = tool.Ifc.get().createIfcText(json.dumps(door_data, default=list)) diff --git a/src/bonsai/bonsai/bim/module/model/window.py b/src/bonsai/bonsai/bim/module/model/window.py index 257a2e1349..6e35896814 100644 --- a/src/bonsai/bonsai/bim/module/model/window.py +++ b/src/bonsai/bonsai/bim/module/model/window.py @@ -36,7 +36,8 @@ from bmesh.types import BMVert from mathutils import Vector -def update_window_modifier_representation(context, obj): +def update_window_modifier_representation(context): + obj = context.active_object element = tool.Ifc.get_entity(obj) props = obj.BIMWindowProperties ifc_file = tool.Ifc.get() @@ -427,10 +428,9 @@ class AddWindow(bpy.types.Operator, tool.Ifc.Operator): bl_idname = "bim.add_window" bl_label = "Add Window" bl_options = {"REGISTER"} - obj: bpy.props.StringProperty() def _execute(self, context): - obj = bpy.data.objects.get(self.obj) if self.obj else context.active_object + obj = context.active_object element = tool.Ifc.get_entity(obj) props = obj.BIMWindowProperties @@ -450,7 +450,7 @@ class AddWindow(bpy.types.Operator, tool.Ifc.Operator): pset=pset, properties={"Data": tool.Ifc.get().createIfcText(json.dumps(window_data, default=list))}, ) - update_window_modifier_representation(context, obj) + update_window_modifier_representation(context) return {"FINISHED"} @@ -502,7 +502,7 @@ class FinishEditingWindow(bpy.types.Operator, tool.Ifc.Operator): props.is_editing = False - update_window_modifier_representation(context, obj) + update_window_modifier_representation(context) pset = tool.Pset.get_element_pset(element, "BBIM_Window") window_data = tool.Ifc.get().createIfcText(json.dumps(window_data, default=list)) diff --git a/src/bonsai/bonsai/bim/module/type/operator.py b/src/bonsai/bonsai/bim/module/type/operator.py index 05f4d0ff54..b072f0fd67 100644 --- a/src/bonsai/bonsai/bim/module/type/operator.py +++ b/src/bonsai/bonsai/bim/module/type/operator.py @@ -414,8 +414,8 @@ class AddType(bpy.types.Operator, tool.Ifc.Operator): ifc_class="IfcWindowType" if tool.Ifc.get_schema() != "IFC2X3" else "IfcWindowStyle", should_add_representation=False, ) - tool.Blender.select_and_activate_single_object(context, obj) - bpy.ops.bim.add_window(obj=obj.name) + with context.temp_override(active_object=obj): + bpy.ops.bim.add_window() elif template == "DOOR": mesh = bpy.data.meshes.new(name) @@ -429,8 +429,8 @@ class AddType(bpy.types.Operator, tool.Ifc.Operator): ifc_class="IfcDoorType" if tool.Ifc.get_schema() != "IFC2X3" else "IfcDoorStyle", should_add_representation=False, ) - tool.Blender.select_and_activate_single_object(context, obj) - bpy.ops.bim.add_door(obj=obj.name) + with context.temp_override(active_object=obj): + bpy.ops.bim.add_door() elif template == "STAIR": mesh = bpy.data.meshes.new(name) @@ -444,8 +444,8 @@ class AddType(bpy.types.Operator, tool.Ifc.Operator): ifc_class=ifc_class, should_add_representation=False, ) - tool.Blender.select_and_activate_single_object(context, obj) - bpy.ops.bim.add_stair() + with context.temp_override(active_object=obj): + bpy.ops.bim.add_stair() elif template == "RAILING": mesh = bpy.data.meshes.new(name) @@ -460,8 +460,8 @@ class AddType(bpy.types.Operator, tool.Ifc.Operator): should_add_representation=True, context=body, ) - tool.Blender.select_and_activate_single_object(context, obj) - bpy.ops.bim.add_railing() + with context.temp_override(active_object=obj): + bpy.ops.bim.add_railing() elif template == "ROOF": mesh = bpy.data.meshes.new(name) @@ -476,8 +476,8 @@ class AddType(bpy.types.Operator, tool.Ifc.Operator): should_add_representation=True, context=body, ) - tool.Blender.select_and_activate_single_object(context, obj) - bpy.ops.bim.add_roof() + with context.temp_override(active_object=obj): + bpy.ops.bim.add_roof() bpy.ops.bim.load_type_thumbnails(ifc_class=ifc_class) props.type_class = props.type_class