diff --git a/src/bonsai/bonsai/bim/module/profile/__init__.py b/src/bonsai/bonsai/bim/module/profile/__init__.py index c4e4d0a91d..00a6728d32 100644 --- a/src/bonsai/bonsai/bim/module/profile/__init__.py +++ b/src/bonsai/bonsai/bim/module/profile/__init__.py @@ -31,6 +31,7 @@ classes = ( operator.EnableEditingProfile, operator.LoadProfiles, operator.RemoveProfileDef, + operator.SelectByProfile, operator.SelectProfileInProfilesUI, prop.Profile, prop.BIMProfileProperties, diff --git a/src/bonsai/bonsai/bim/module/profile/operator.py b/src/bonsai/bonsai/bim/module/profile/operator.py index c2e95c1730..da91595dc6 100644 --- a/src/bonsai/bonsai/bim/module/profile/operator.py +++ b/src/bonsai/bonsai/bim/module/profile/operator.py @@ -208,16 +208,17 @@ class DuplicateProfileDef(bpy.types.Operator, tool.Ifc.Operator): @classmethod def poll(cls, context): - props = context.scene.BIMProfileProperties - if len(props.profiles) > props.active_profile_index: + active_profile = tool.Profile.get_active_profile_ui() + if active_profile is not None: return True cls.poll_message_set("No profile selected to duplicate.") return False def _execute(self, context): - props = context.scene.BIMProfileProperties ifc_file = tool.Ifc.get() - profile = ifc_file.by_id(props.profiles[props.active_profile_index].ifc_definition_id) + profile_item = tool.Profile.get_active_profile_ui() + assert profile_item + profile = ifc_file.by_id(profile_item.ifc_definition_id) tool.Profile.duplicate_profile(profile) bpy.ops.bim.load_profiles() @@ -337,3 +338,32 @@ class SelectProfileInProfilesUI(bpy.types.Operator): f"Profile '{profile.Name or 'Unnamed'}' is selected in Profiles UI.", ) return {"FINISHED"} + + +class SelectByProfile(bpy.types.Operator): + bl_idname = "bim.select_by_profile" + bl_label = "Select by Profile" + bl_description = "Select objects using the provided profile." + bl_options = {"REGISTER", "UNDO"} + + @classmethod + def poll(cls, context): + active_profile = tool.Profile.get_active_profile_ui() + if active_profile is not None: + return True + cls.poll_message_set("No profile selected to select elements.") + return False + + def execute(self, context): + ifc_file = tool.Ifc.get() + profile_item = tool.Profile.get_active_profile_ui() + assert profile_item + profile = ifc_file.by_id(profile_item.ifc_definition_id) + elements = ifcopenshell.util.element.get_elements_by_profile(profile) + objects = [o for e in elements if (o := tool.Ifc.get_object(e))] + if objects: + tool.Spatial.select_products(elements) + self.report( + {"INFO"}, f"{len(elements)} elements were found using profile, {len(objects)} objects were selected." + ) + return {"FINISHED"} diff --git a/src/bonsai/bonsai/bim/module/profile/ui.py b/src/bonsai/bonsai/bim/module/profile/ui.py index 421ac3fc59..6718396412 100644 --- a/src/bonsai/bonsai/bim/module/profile/ui.py +++ b/src/bonsai/bonsai/bim/module/profile/ui.py @@ -81,6 +81,7 @@ class BIM_PT_profiles(Panel): row.prop(self.props, "profile_classes", text="") row.operator("bim.add_profile_def", text="", icon="ADD") row.operator("bim.duplicate_profile_def", icon="DUPLICATE", text="") + row.operator("bim.select_by_profile", icon="RESTRICT_SELECT_OFF", text="") self.layout.template_list( "BIM_UL_profiles",