From 37fe04ffd2ded8ef07793c2327ed7e34e2ef3184 Mon Sep 17 00:00:00 2001 From: Dion Moult Date: Tue, 13 Jul 2021 19:32:12 +1000 Subject: [PATCH] New recipe to downgrade indexed poly curves, often used to allow IFC4 grids to show up in viewers like Revizto / XBim Xplorer / etc. --- .../recipes/DowngradeIndexedPolyCurve.py | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 src/ifcpatch/ifcpatch/recipes/DowngradeIndexedPolyCurve.py diff --git a/src/ifcpatch/ifcpatch/recipes/DowngradeIndexedPolyCurve.py b/src/ifcpatch/ifcpatch/recipes/DowngradeIndexedPolyCurve.py new file mode 100644 index 0000000000..05d1c9b645 --- /dev/null +++ b/src/ifcpatch/ifcpatch/recipes/DowngradeIndexedPolyCurve.py @@ -0,0 +1,31 @@ +import ifcopenshell +import ifcopenshell.util.element + + +class Patcher: + def __init__(self, src, file, logger, args=None): + self.src = src + self.file = file + self.logger = logger + self.args = args + + def patch(self): + curve_map = {} + + for curve in self.file.by_type("IfcIndexedPolyCurve"): + if "IfcArcIndex" in [s.is_a() for s in curve.Segments]: + print("Could not convert curve due to arcs", curve) + continue + coordinates = curve.Points.CoordList + points = [] + for i, segment in enumerate(curve.Segments): + segment = segment.wrappedValue + if i == 0: + points.append(self.file.createIfcCartesianPoint(coordinates[segment[0] - 1])) + points.append(self.file.createIfcCartesianPoint(coordinates[segment[1] - 1])) + polyline = self.file.create_entity("IfcPolyline", points) + curve_map[curve] = polyline + + for curve, polyline in curve_map.items(): + for inverse in self.file.get_inverse(curve): + ifcopenshell.util.element.replace_attribute(inverse, curve, polyline)