From 82f73c29ea363822a0dc5a69ab66a1e5e8424ebb Mon Sep 17 00:00:00 2001 From: Petru Conduraru Date: Mon, 6 Jul 2026 10:29:16 +0300 Subject: [PATCH] style.assign_representation_styles: fix crash on IfcPresentationStyleAssignment #7883 When replacing a style on an item whose previous IfcStyledItem wraps its styles in the deprecated IfcPresentationStyleAssignment, and the assignment is not being reused (use_style_assignment is False, e.g. an IFC4 file authored by AVEVA E3D), the else branch called remove_same_type_styles(style_assignment) with style_assignment still None, raising AttributeError: 'NoneType' object has no attribute 'Styles'. Operate on style_, the assignment found in the current iteration, instead of the accumulator. Verified red-green with a minimal IFC4 file using IfcPresentationStyleAssignment. Co-Authored-By: Claude Fable 5 --- .../ifcopenshell/api/style/assign_representation_styles.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/ifcopenshell-python/ifcopenshell/api/style/assign_representation_styles.py b/src/ifcopenshell-python/ifcopenshell/api/style/assign_representation_styles.py index b26d106017..412a373b99 100644 --- a/src/ifcopenshell-python/ifcopenshell/api/style/assign_representation_styles.py +++ b/src/ifcopenshell-python/ifcopenshell/api/style/assign_representation_styles.py @@ -162,7 +162,11 @@ class Usecase: style_assignment = style_ self.remove_same_type_styles(style_assignment, current_style_type, remove_item=False) else: - self.remove_same_type_styles(style_assignment, current_style_type, remove_item=True) + # Operate on the assignment found in this iteration, not the + # style_assignment accumulator, which is still None when the + # file uses IfcPresentationStyleAssignment but we are not + # reusing it (e.g. an IFC4 file authored by AVEVA E3D). See #7883. + self.remove_same_type_styles(style_, current_style_type, remove_item=True) if use_style_assignment: if style_assignment: