From 080f325557deddd3eca54c94722c75a78a4e13c6 Mon Sep 17 00:00:00 2001 From: Ryan Schultz Date: Fri, 3 May 2024 00:59:33 -0500 Subject: [PATCH] extends bim.select_type by selecting multiple types from a selection of objects. Also when the type is selected and turned on, all other types are automatically turned off. https://imgur.com/a/DQUF0ai --- src/blenderbim/blenderbim/bim/import_ifc.py | 6 ++- .../blenderbim/bim/module/model/ui.py | 1 - .../blenderbim/bim/module/type/operator.py | 48 +++++++++++++------ 3 files changed, 38 insertions(+), 17 deletions(-) diff --git a/src/blenderbim/blenderbim/bim/import_ifc.py b/src/blenderbim/blenderbim/bim/import_ifc.py index 93ebe4b4ee..4e9440ad1c 100644 --- a/src/blenderbim/blenderbim/bim/import_ifc.py +++ b/src/blenderbim/blenderbim/bim/import_ifc.py @@ -1498,7 +1498,11 @@ class IfcImporter: # Occurs when reloading a project pass project_collection = bpy.context.view_layer.layer_collection.children[self.project["blender"].name] - project_collection.children[self.type_collection.name].hide_viewport = True + types_collection = project_collection.children[self.type_collection.name] + types_collection.hide_viewport = False + for obj in types_collection.collection.objects: #turn off all objects inside Types collection. + obj.hide_set(True) + def clean_mesh(self): obj = None diff --git a/src/blenderbim/blenderbim/bim/module/model/ui.py b/src/blenderbim/blenderbim/bim/module/model/ui.py index 367917a3f0..9a174f11ff 100644 --- a/src/blenderbim/blenderbim/bim/module/model/ui.py +++ b/src/blenderbim/blenderbim/bim/module/model/ui.py @@ -134,7 +134,6 @@ class LaunchTypeManager(bpy.types.Operator): op = row.operator("bim.rename_type", icon="GREASEPENCIL", text="") op.element = relating_type["id"] op = row.operator("bim.select_type", icon="OBJECT_DATA", text="") - op.relating_type = relating_type["id"] op = row.operator("bim.duplicate_type", icon="DUPLICATE", text="") op.element = relating_type["id"] op = row.operator("bim.remove_type", icon="X", text="") diff --git a/src/blenderbim/blenderbim/bim/module/type/operator.py b/src/blenderbim/blenderbim/bim/module/type/operator.py index 899dfe4ec1..66d8682965 100644 --- a/src/blenderbim/blenderbim/bim/module/type/operator.py +++ b/src/blenderbim/blenderbim/bim/module/type/operator.py @@ -146,21 +146,39 @@ class SelectType(bpy.types.Operator): relating_type: bpy.props.IntProperty() def execute(self, context): - element = tool.Ifc.get().by_id(self.relating_type) - obj = tool.Ifc.get_object(element) - if obj: - try: - tool.Blender.select_and_activate_single_object(context, obj) - except: - self.report({"INFO"}, "Type object is hidden.") - # IfcTypeProducts are only used for annotations and not part of the model interface. - if element.is_a() != "IfcTypeProduct": - try: - context.scene.BIMModelProperties.ifc_class = element.is_a() - context.scene.BIMModelProperties.relating_type_id = str(self.relating_type) - except: - # Potentially our BIM Tool is filtered to a specific element. - pass + selected_objs = context.selected_objects + active_obj = context.active_object + selected_objs.append(active_obj) #update selected_objs so the active_obj is at the end of the list + last_relating_type_obj = None + types_collection = bpy.data.collections.get("Types") + for obj in types_collection.objects: + obj.hide_set(True) + for obj in selected_objs: + element = tool.Ifc.get_entity(obj) + relating_type = ifcopenshell.util.element.get_type(element) + relating_type_obj = tool.Ifc.get_object(relating_type) + obj.select_set(False) + if relating_type_obj: + if relating_type_obj.hide_get(): + relating_type_obj.hide_set(False) + relating_type_obj.select_set(True) + last_relating_type_obj = relating_type_obj + + context.view_layer.objects.active = last_relating_type_obj #make the active_obj's type the active object + + # if relating_type_obj: + # try: + # tool.Blender.select_and_activate_single_object(context, relating_type_obj) + # except: + # self.report({"INFO"}, "Type object is hidden.") + # # IfcTypeProducts are only used for annotations and not part of the model interface. + # if element.is_a() != "IfcTypeProduct": + # try: + # context.scene.BIMModelProperties.ifc_class = element.is_a() + # context.scene.BIMModelProperties.relating_type_id = str(relating_type) + # except: + # # Potentially our BIM Tool is filtered to a specific element. + # pass return {"FINISHED"}