From 7e93a73c6af114b378697b8d049bb67d472efd17 Mon Sep 17 00:00:00 2001 From: Richard Brice <37087370+RickBrice@users.noreply.github.com> Date: Mon, 23 Feb 2026 16:21:46 -0800 Subject: [PATCH] Updates alignment API function for creating a layout segment to include the segment geometric representation --- .../api/alignment/_add_segment_to_curve.py | 22 ++++++++++++++++++ .../ifcopenshell/api/alignment/create.py | 23 +++++++++++++++---- .../api/alignment/create_layout_segment.py | 2 ++ 3 files changed, 43 insertions(+), 4 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 e24a946ae7..90c44fef46 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 @@ -109,6 +109,8 @@ def _add_segment_to_curve(file: ifcopenshell.file, segment: entity_instance, cur at the end of the curve, but before the manditory zero length segment. The IfcCurveSegment.Transition for the segment that preceeds the new segment is updated. + The geometric representation is also added to the IfcCurveSegment based on CT 4.1.7.1.1.4 Alignment Geometry - Segments + :param segment: The segment to be added to the curve :param curve: The representation curve receiving the segment :return: None @@ -141,6 +143,26 @@ def _add_segment_to_curve(file: ifcopenshell.file, segment: entity_instance, cur else: assert False + items = [] for mapped_segment in mapped_segments: if mapped_segment: _add_curve_segment_to_composite_curve(file, mapped_segment, curve) + items.append(mapped_segment) + + axis_geom_subcontext = ifcopenshell.api.alignment.get_axis_subcontext(file) + + axis_representation = file.createIfcShapeRepresentation( + ContextOfItems=axis_geom_subcontext, + RepresentationIdentifier="Axis", + RepresentationType="Segment", + Items = items + ) + + product = file.createIfcProductDefinitionShape(Representations=(axis_representation,)) + + layout = ifcopenshell.api.alignment.get_alignment_layout(segment) + alignment = ifcopenshell.api.alignment.get_alignment(layout) + + if alignment != None: + segment.ObjectPlacement = alignment.ObjectPlacement + segment.Representation = product diff --git a/src/ifcopenshell-python/ifcopenshell/api/alignment/create.py b/src/ifcopenshell-python/ifcopenshell/api/alignment/create.py index d2682aaad1..b09f8d3322 100644 --- a/src/ifcopenshell-python/ifcopenshell/api/alignment/create.py +++ b/src/ifcopenshell-python/ifcopenshell/api/alignment/create.py @@ -80,14 +80,29 @@ def create( if include_geometry: _create_geometric_representation(file, alignment) - name = ifcopenshell.util.alignment.station_as_string(file, start_station) - referent = ifcopenshell.api.alignment.add_stationing_referent( - file, alignment, 0.0, start_station, name, alignment - ) + name = ifcopenshell.util.alignment.station_as_string(file, start_station) + referent = ifcopenshell.api.alignment.add_stationing_referent(file, alignment, 0.0, start_station, name, alignment) for layout in alignment_layouts: _add_zero_length_segment(file, layout) + if include_geometry: + # add the representation to the zero length segment + curve = ifcopenshell.api.alignment.get_layout_curve(layout) + + axis_geom_subcontext = ifcopenshell.api.alignment.get_axis_subcontext(file) + + axis_representation = file.createIfcShapeRepresentation( + ContextOfItems=axis_geom_subcontext, + RepresentationIdentifier="Axis", + RepresentationType="Segment", + Items=(curve.Segments[-1],), + ) + + product = file.createIfcProductDefinitionShape(Representations=(axis_representation,)) + layout.IsNestedBy[0].RelatedObjects[-1].ObjectPlacement = alignment.ObjectPlacement + layout.IsNestedBy[0].RelatedObjects[-1].Representation = product + # IFC 4.1.4.1.1 Alignment Aggregation To Project project = file.by_type("IfcProject")[0] if project: diff --git a/src/ifcopenshell-python/ifcopenshell/api/alignment/create_layout_segment.py b/src/ifcopenshell-python/ifcopenshell/api/alignment/create_layout_segment.py index 52f329694b..d5ab1c96e9 100644 --- a/src/ifcopenshell-python/ifcopenshell/api/alignment/create_layout_segment.py +++ b/src/ifcopenshell-python/ifcopenshell/api/alignment/create_layout_segment.py @@ -34,6 +34,8 @@ def create_layout_segment( Creates a new IfcAlignmentSegment using the IfcAlignmentParameterSegment design parameters. The new segment is appended to the layout alignment and the corresponding IfcCurveSegment is created in the geometric representation if it exists. + Additionally, if the geometric representation of the alignment exists, the segment's geometric representation is added to the IfcCurveSegment based on CT 4.1.7.1.1.4 Alignment Geometry - Segments + :param layout: The layout to receive the new layout segment. This parameter is expected to be IfcAlignmentHorizontal, IfcAlignmentVertical or IfcAlignmentCant :param design_parameters: The parameters defining the segment. Expected to be the appropreate subclass of IfcAlignmentParameterSegment :return: 4x4 matrix at end of segment as np.array intended to be used as the start point geometry for the next segment or None if there is the geometric representation is not defined.