From 686e9c946bee3123a668bc170d13abafe986a167 Mon Sep 17 00:00:00 2001 From: Richard Brice <37087370+RickBrice@users.noreply.github.com> Date: Mon, 12 May 2025 16:14:53 -0700 Subject: [PATCH] Adds object placement to stationing referent. --- .../alignment/add_stationing_to_alignment.py | 32 +++++++++---------- .../test_add_stationing_to_alignment.py | 2 ++ 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/src/ifcopenshell-python/ifcopenshell/api/alignment/add_stationing_to_alignment.py b/src/ifcopenshell-python/ifcopenshell/api/alignment/add_stationing_to_alignment.py index ffc42c70d8..fe99018c45 100644 --- a/src/ifcopenshell-python/ifcopenshell/api/alignment/add_stationing_to_alignment.py +++ b/src/ifcopenshell-python/ifcopenshell/api/alignment/add_stationing_to_alignment.py @@ -23,7 +23,7 @@ import ifcopenshell.guid from ifcopenshell import entity_instance -def add_stationing_to_alignment(file: ifcopenshell.file, alignment: entity_instance, start_station: float) -> None: +def add_stationing_to_alignment(file: ifcopenshell.file, alignment: entity_instance, start_station: float, plus_seperator=3,accuracy=3) -> None: """ Adds stationing to an alignment by creating an IfcReferent with the Pset_Stationing property set to establish the stationing at the start of the alignment. Note - this function assumes the stationing has not been previously defined @@ -43,20 +43,20 @@ def add_stationing_to_alignment(file: ifcopenshell.file, alignment: entity_insta # the example is a circle. a better way would be to pass a representation into the function object_placement = None representation = None - # basis_curve = ifcopenshell.api.alignment.get_basis_curve(alignment) - # if basis_curve: - # object_placement = file.createIfcLinearPlacement( - # RelativePlacement=file.createIfcAxis2PlacementLinear( - # Location=file.createIfcPointByDistanceExpression( - # DistanceAlong=file.createIfcLengthMeasure(0.0), - # OffsetLateral=None, - # OffsetVertical=None, - # OffsetLongitudinal=None, - # BasisCurve=basis_curve, - # ) - # ), - # CartesianPosition=None, - # ) + basis_curve = ifcopenshell.api.alignment.get_basis_curve(alignment) + if basis_curve: + object_placement = file.createIfcLinearPlacement( + RelativePlacement=file.createIfcAxis2PlacementLinear( + Location=file.createIfcPointByDistanceExpression( + DistanceAlong=file.createIfcLengthMeasure(0.0), + OffsetLateral=None, + OffsetVertical=None, + OffsetLongitudinal=None, + BasisCurve=basis_curve, + ) + ), + CartesianPosition=None, + ) # representation = file.create_entity( # name="IfcCircle", # position=file.createIfcAxis2Placement2D(Location=file.createIfcCartesianPoint(Coordinates=(0.0, 0.0)), @@ -67,7 +67,7 @@ def add_stationing_to_alignment(file: ifcopenshell.file, alignment: entity_insta start_referent = file.createIfcReferent( GlobalId=ifcopenshell.guid.new(), OwnerHistory=None, - Name=ifcopenshell.util.stationing.station_as_string(start_station), + Name=ifcopenshell.util.stationing.station_as_string(start_station,plus_seperator,accuracy), Description=None, ObjectType=None, ObjectPlacement=object_placement, diff --git a/src/ifcopenshell-python/test/api/alignment/test_add_stationing_to_alignment.py b/src/ifcopenshell-python/test/api/alignment/test_add_stationing_to_alignment.py index e559653618..cab9a16699 100644 --- a/src/ifcopenshell-python/test/api/alignment/test_add_stationing_to_alignment.py +++ b/src/ifcopenshell-python/test/api/alignment/test_add_stationing_to_alignment.py @@ -41,6 +41,7 @@ def test_add_stationing_to_alignment(): alignment = ifcopenshell.api.alignment.create_alignment_by_pi_method( file, "TestAlignment", coordinates, radii, vpoints, lengths ) + ifcopenshell.api.alignment.create_geometric_representation(file, alignment) ifcopenshell.api.alignment.add_stationing_to_alignment(file, alignment, 2000.0) @@ -54,3 +55,4 @@ def test_add_stationing_to_alignment(): ifcopenshell.util.element.get_pset(element=referent, name="Pset_Stationing", prop="Station") == 2000.0 ) + assert(referent.ObjectPlacement != None)