From d2ee4f2f9773ed5b71b790221dc90bcdf3552398 Mon Sep 17 00:00:00 2001 From: DesertSpringsCivil Date: Thu, 12 Mar 2026 16:56:33 -0600 Subject: [PATCH] fix: Correct vertical/cant segment handling in alignment API MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Two bugs prevented IfcAlignmentVertical segments from being added when a geometric representation exists. Bug 1 — _add_segment_to_curve.py: Removed an unconditional `if not curve.is_a("IfcCompositeCurve")` guard that was left over from when the function only supported horizontal segments. The preceding if/elif/elif chain already validates the correct curve type for each segment type; the redundant check always raised TypeError for vertical (IfcGradientCurve) and cant (IfcSegmentedReferenceCurve) segments. Bug 2 — add_zero_length_segment.py: Added a None guard before the recursive `add_zero_length_segment(file, layout.BaseCurve)` call for IfcGradientCurve. When an IfcGradientCurve is created without a BaseCurve (e.g. before a horizontal representation exists), the recursive call previously crashed with AttributeError. Co-Authored-By: Claude Sonnet 4.6 --- .../ifcopenshell/api/alignment/_add_segment_to_curve.py | 4 ---- .../ifcopenshell/api/alignment/add_zero_length_segment.py | 3 ++- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/src/ifcopenshell-python/ifcopenshell/api/alignment/_add_segment_to_curve.py b/src/ifcopenshell-python/ifcopenshell/api/alignment/_add_segment_to_curve.py index db493a3311..feebdf2601 100644 --- a/src/ifcopenshell-python/ifcopenshell/api/alignment/_add_segment_to_curve.py +++ b/src/ifcopenshell-python/ifcopenshell/api/alignment/_add_segment_to_curve.py @@ -128,10 +128,6 @@ def _add_segment_to_curve(file: ifcopenshell.file, segment: entity_instance, cur elif segment.DesignParameters.is_a("IfcAlignmentCantSegment") and not curve.is_a("IfcSegmentedReferenceCurve"): raise TypeError(f"Expected to see IfcSegmentedReferenceCurve, instead received '{curve.is_a()}'.") - expected_type = "IfcCompositeCurve" - if not curve.is_a(expected_type): - raise TypeError(f"Expected to see {expected_type}, instead received {curve.is_a()}.") - # map the IfcAlignmentSegment to an IfcCurveSegment (or two in the case of helmert curves) if segment.DesignParameters.is_a("IfcAlignmentHorizontalSegment"): mapped_segments = _map_alignment_horizontal_segment(file, segment) diff --git a/src/ifcopenshell-python/ifcopenshell/api/alignment/add_zero_length_segment.py b/src/ifcopenshell-python/ifcopenshell/api/alignment/add_zero_length_segment.py index 96c3a9c1f2..a64eee9437 100644 --- a/src/ifcopenshell-python/ifcopenshell/api/alignment/add_zero_length_segment.py +++ b/src/ifcopenshell-python/ifcopenshell/api/alignment/add_zero_length_segment.py @@ -123,7 +123,8 @@ def add_zero_length_segment(file: ifcopenshell.file, layout: entity_instance, in if layout.is_a("IfcSegmentedReferenceCurve"): ifcopenshell.api.alignment.add_zero_length_segment(file, layout.BaseCurve) elif layout.is_a("IfcGradientCurve"): - ifcopenshell.api.alignment.add_zero_length_segment(file, layout.BaseCurve) + if layout.BaseCurve is not None: + ifcopenshell.api.alignment.add_zero_length_segment(file, layout.BaseCurve) else: zero_length_curve_segment = None