Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/bonsai/bonsai/bim/module/geometry/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
operator.RemoveRepresentation,
operator.RemoveRepresentationItem,
operator.RemoveRepresentationItemFromShapeAspect,
operator.SelectByRepresentationType,
operator.SelectConnection,
operator.SelectRepresentationItem,
operator.SwitchRepresentation,
Expand Down
49 changes: 49 additions & 0 deletions src/bonsai/bonsai/bim/module/geometry/operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,55 @@
core.select_connection(tool.Geometry, connection=tool.Ifc.get().by_id(self.connection))


class SelectByRepresentationType(bpy.types.Operator):
bl_idname = "bim.select_by_representation_type"
bl_label = "Select By Representation Type"
bl_description = (
"Select objects whose active representation matches this type. "
"Ctrl+Click to also include objects that have this type in any representation (active or not)"
)
bl_options = {"REGISTER", "UNDO"}
representation_type: bpy.props.StringProperty()
select_inactive: bpy.props.BoolProperty(default=False, options={"SKIP_SAVE"})

def invoke(self, context, event):
self.select_inactive = event.ctrl
return self.execute(context)

def execute(self, context):
ifc = tool.Ifc.get()
if not ifc:
return {"CANCELLED"}
# Strip the "*" suffix used for mapped/resolved representations.
target_type = self.representation_type.rstrip("*")
matched = 0
for obj in context.visible_objects:
element = tool.Ifc.get_entity(obj)
if not element:
obj.select_set(False)
continue
if self.select_inactive:
# Ctrl: match any representation on the element, active or not.
has_type = any(
(ifcopenshell.util.representation.resolve_representation(rep).RepresentationType or "") == target_type

Check failure on line 450 in src/bonsai/bonsai/bim/module/geometry/operator.py

View workflow job for this annotation

GitHub Actions / lint-formatting

Black Format Issue

Black formatting issue in /home/runner/work/IfcOpenShell/IfcOpenShell/src/bonsai/bonsai/bim/module/geometry/operator.py

Check failure on line 450 in src/bonsai/bonsai/bim/module/geometry/operator.py

View workflow job for this annotation

GitHub Actions / lint-formatting

Black Format Issue

Black formatting issue in /home/runner/work/IfcOpenShell/IfcOpenShell/src/bonsai/bonsai/bim/module/geometry/operator.py
for rep in ifcopenshell.util.representation.get_representations_iter(element)
)
else:
# Default: match only the currently active (displayed) representation.
active_rep = tool.Geometry.get_active_representation(obj)
if active_rep is None:
obj.select_set(False)
continue
resolved = ifcopenshell.util.representation.resolve_representation(active_rep)
has_type = (resolved.RepresentationType or "") == target_type
obj.select_set(has_type)
if has_type:
matched += 1
mode = "any representation" if self.select_inactive else "active representation"
self.report({"INFO"}, f"Selected {matched} object(s) with RepresentationType '{target_type}' ({mode})")
return {"FINISHED"}


class RemoveConnection(bpy.types.Operator, tool.Ifc.Operator):
bl_idname = "bim.remove_connection"
bl_label = "Remove Connection"
Expand Down
7 changes: 6 additions & 1 deletion src/bonsai/bonsai/bim/module/geometry/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,12 @@ def draw(self, context):
row.label(text=representation["ContextType"])
row.label(text=representation["ContextIdentifier"])
row.label(text=representation["TargetView"])
row.label(text=representation["RepresentationType"])
op = row.operator(
"bim.select_by_representation_type",
text=representation["RepresentationType"],
emboss=False,
)
op.representation_type = representation["RepresentationType"]
op = row.operator(
"bim.switch_representation",
icon="FILE_REFRESH" if representation["is_active"] else "OUTLINER_DATA_MESH",
Expand Down
Loading