From 260eb31a695731dabcd729db2510d75e24905a28 Mon Sep 17 00:00:00 2001 From: Dion Moult Date: Sun, 7 May 2023 17:32:46 +1000 Subject: [PATCH] Add shape utility to easily get profiles and extrusions --- .../ifcopenshell/util/shape.py | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/ifcopenshell-python/ifcopenshell/util/shape.py b/src/ifcopenshell-python/ifcopenshell/util/shape.py index af73c67cd0..3e12c482f5 100644 --- a/src/ifcopenshell-python/ifcopenshell/util/shape.py +++ b/src/ifcopenshell-python/ifcopenshell/util/shape.py @@ -17,7 +17,9 @@ # along with IfcOpenShell. If not, see . import numpy as np +import ifcopenshell.util.element import ifcopenshell.util.placement +import ifcopenshell.util.representation tol = 1e-6 @@ -278,3 +280,28 @@ def get_footprint_perimeter(geometry): all_edges.add(edge) return sum([np.linalg.norm(vertices[e[0]] - vertices[e[1]]) for e in (all_edges - shared_edges)]) + + +def get_profiles(element): + material = ifcopenshell.util.element.get_material(element, should_skip_usage=True) + if material and material.is_a("IfcMaterialProfileSet"): + return [mp.Profile for mp in material.MaterialProfiles] + return [] + + +def get_extrusions(element): + representation = ifcopenshell.util.representation.get_representation(element, "Model", "Body", "MODEL_VIEW") + if not representation: + return + representation = ifcopenshell.util.representation.resolve_representation(representation) + extrusions = [] + for item in representation.Items: + while True: + if item.is_a("IfcExtrudedAreaSolid"): + extrusion.append(item) + break + elif item.is_a("IfcBooleanResult"): + item = item.FirstOperand + else: + break + return extrusions