From 944cbeea1a0261f6f6d846a26a400e81cc5cab2f Mon Sep 17 00:00:00 2001 From: Dion Moult Date: Sat, 1 Oct 2022 23:25:34 +1000 Subject: [PATCH] Handle both 2D and 3D placement matrixes in IfcOpenShell utils --- .../ifcopenshell/util/placement.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/ifcopenshell-python/ifcopenshell/util/placement.py b/src/ifcopenshell-python/ifcopenshell/util/placement.py index bcce72d3a1..5e161d4f55 100644 --- a/src/ifcopenshell-python/ifcopenshell/util/placement.py +++ b/src/ifcopenshell-python/ifcopenshell/util/placement.py @@ -28,9 +28,18 @@ def a2p(o, z, x): def get_axis2placement(plc): - z = np.array(plc.Axis.DirectionRatios if getattr(plc, "Axis", None) else (0, 0, 1)) - x = np.array(plc.RefDirection.DirectionRatios if plc.RefDirection else (1, 0, 0)) - o = plc.Location.Coordinates + if plc.is_a("IfcAxis2Placement3D"): + z = np.array(plc.Axis.DirectionRatios if plc.Axis else (0, 0, 1)) + x = np.array(plc.RefDirection.DirectionRatios if plc.RefDirection else (1, 0, 0)) + o = plc.Location.Coordinates + elif plc.is_a("IfcAxis2Placement2D"): + z = np.array((0, 0, 1)) + if plc.RefDirection: + x = np.array(plc.RefDirection.DirectionRatios) + x.resize(3) + else: + x = np.array((1, 0, 0)) + o = (*plc.Location.Coordinates, 0.0) return a2p(o, z, x)