Helps with #7853: Switch representation in bulk on selected objects

For non-active objects, match both ContextOfItems and
RepresentationIdentifier (e.g. 'Body', 'Axis') against
the active object's target representation. Previously only
ContextOfItems was compared, causing all objects sharing
the same parent context to be skipped incorrectly.

Also pass disable_opening_subtractions to core, which was
previously declared but never forwarded.

Generated with the assistance of an AI coding tool.
This commit is contained in:
Ryan Schultz
2026-04-07 09:39:19 -05:00
parent ab7d9fdf4a
commit 72813d3f41
@@ -445,22 +445,35 @@ class SwitchRepresentation(bpy.types.Operator, tool.Ifc.Operator):
def _execute(self, context): def _execute(self, context):
provided_representation = tool.Ifc.get().by_id(self.ifc_definition_id) provided_representation = tool.Ifc.get().by_id(self.ifc_definition_id)
ifc_context = provided_representation.ContextOfItems ifc_context = provided_representation.ContextOfItems
provided_identifier = provided_representation.RepresentationIdentifier
for obj in tool.Blender.get_selected_objects(): for obj in tool.Blender.get_selected_objects():
if not (element := tool.Ifc.get_entity(obj)) or obj.mode != "OBJECT": if not (element := tool.Ifc.get_entity(obj)) or obj.mode != "OBJECT":
continue continue
# Find representation to switch to. active_representation = tool.Geometry.get_active_representation(obj)
if (active_representation := tool.Geometry.get_active_representation(obj)) is None:
if obj == context.active_object:
representation = provided_representation
elif active_representation is None:
# No active representation => probably has no representations. # No active representation => probably has no representations.
continue continue
elif obj == context.active_object: elif (
# Prioritize provided representation. active_representation.ContextOfItems == ifc_context
representation = provided_representation and active_representation.RepresentationIdentifier == provided_identifier
elif active_representation.ContextOfItems == ifc_context: ):
# Prioritize already active representation if context matches. # Already showing the correct representation — no geometry update needed.
representation = active_representation continue
else: else:
representation = ifcopenshell.util.representation.get_representation(element, ifc_context) # Find a representation matching both the context and identifier.
representation = next(
(
r
for r in ifcopenshell.util.representation.get_representations_iter(element)
if r.ContextOfItems == ifc_context
and r.RepresentationIdentifier == provided_identifier
),
None,
)
if not representation: if not representation:
continue continue
@@ -469,6 +482,7 @@ class SwitchRepresentation(bpy.types.Operator, tool.Ifc.Operator):
tool.Geometry, tool.Geometry,
obj=obj, obj=obj,
representation=representation, representation=representation,
apply_openings=not self.disable_opening_subtractions,
) )