mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-24 01:47:55 +00:00
Bonsai - Select By Profile operator
Location - https://imgur.com/a/gInY1sl
This commit is contained in:
@@ -31,6 +31,7 @@ classes = (
|
|||||||
operator.EnableEditingProfile,
|
operator.EnableEditingProfile,
|
||||||
operator.LoadProfiles,
|
operator.LoadProfiles,
|
||||||
operator.RemoveProfileDef,
|
operator.RemoveProfileDef,
|
||||||
|
operator.SelectByProfile,
|
||||||
operator.SelectProfileInProfilesUI,
|
operator.SelectProfileInProfilesUI,
|
||||||
prop.Profile,
|
prop.Profile,
|
||||||
prop.BIMProfileProperties,
|
prop.BIMProfileProperties,
|
||||||
|
|||||||
@@ -208,16 +208,17 @@ class DuplicateProfileDef(bpy.types.Operator, tool.Ifc.Operator):
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def poll(cls, context):
|
def poll(cls, context):
|
||||||
props = context.scene.BIMProfileProperties
|
active_profile = tool.Profile.get_active_profile_ui()
|
||||||
if len(props.profiles) > props.active_profile_index:
|
if active_profile is not None:
|
||||||
return True
|
return True
|
||||||
cls.poll_message_set("No profile selected to duplicate.")
|
cls.poll_message_set("No profile selected to duplicate.")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def _execute(self, context):
|
def _execute(self, context):
|
||||||
props = context.scene.BIMProfileProperties
|
|
||||||
ifc_file = tool.Ifc.get()
|
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)
|
tool.Profile.duplicate_profile(profile)
|
||||||
bpy.ops.bim.load_profiles()
|
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.",
|
f"Profile '{profile.Name or 'Unnamed'}' is selected in Profiles UI.",
|
||||||
)
|
)
|
||||||
return {"FINISHED"}
|
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"}
|
||||||
|
|||||||
@@ -81,6 +81,7 @@ class BIM_PT_profiles(Panel):
|
|||||||
row.prop(self.props, "profile_classes", text="")
|
row.prop(self.props, "profile_classes", text="")
|
||||||
row.operator("bim.add_profile_def", text="", icon="ADD")
|
row.operator("bim.add_profile_def", text="", icon="ADD")
|
||||||
row.operator("bim.duplicate_profile_def", icon="DUPLICATE", text="")
|
row.operator("bim.duplicate_profile_def", icon="DUPLICATE", text="")
|
||||||
|
row.operator("bim.select_by_profile", icon="RESTRICT_SELECT_OFF", text="")
|
||||||
|
|
||||||
self.layout.template_list(
|
self.layout.template_list(
|
||||||
"BIM_UL_profiles",
|
"BIM_UL_profiles",
|
||||||
|
|||||||
Reference in New Issue
Block a user