Adds alignment API function to get the alignment layout from one of its segments

This commit is contained in:
Richard Brice
2026-02-23 16:21:05 -08:00
parent 798ed0d502
commit 99640912c1
3 changed files with 92 additions and 0 deletions
@@ -63,6 +63,7 @@ from .create_segment_representations import create_segment_representations
from .distance_along_from_station import distance_along_from_station
from .get_alignment import get_alignment
from .get_alignment_layout_nest import get_alignment_layout_nest
from .get_alignment_layout import get_alignment_layout
from .get_alignment_layouts import get_alignment_layouts
from .get_alignment_segment_nest import get_alignment_segment_nest
from .get_alignment_start_station import get_alignment_start_station
@@ -107,6 +108,7 @@ __all__ = [
"distance_along_from_station",
"get_alignment",
"get_alignment_layout_nest",
"get_alignment_layout",
"get_alignment_layouts",
"get_alignment_segment_nest",
"get_alignment_start_station",
@@ -0,0 +1,41 @@
# IfcOpenShell - IFC toolkit and geometry engine
# Copyright (C) 2025 Thomas Krijnen <thomas@aecgeeks.com>
#
# This file is part of IfcOpenShell.
#
# IfcOpenShell is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# IfcOpenShell is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
from collections.abc import Sequence
from ifcopenshell import entity_instance
def get_alignment_layout(segment: entity_instance) -> entity_instance:
"""
Returns the layout alignment that the segment is nested into
"""
expected_types = ["IfcAlignmentSegment"]
if not segment.is_a() in expected_types:
raise TypeError(
f"Expected entity type to be one of {[_ for _ in expected_types]}, instead received '{segment.is_a()}"
)
layout = None
layouts=["IfcAlignmentHorizontal","IfcAlignmentVertical","IfcAlignmentCant"]
for nest in segment.Nests:
if nest.RelatingObject.is_a() in layouts:
layout = nest.RelatingObject
break
return layout