From 45209be0ff27beadd8f3acbc47215ad06e5adce7 Mon Sep 17 00:00:00 2001 From: Dion Moult Date: Tue, 21 Mar 2023 17:15:59 +1100 Subject: [PATCH] You can now easily get a list of FMHEM classes and subtypes to list explicitly in IDS requirements --- .../ifcopenshell/util/fm.py | 38 ++++++++++++++++++- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/src/ifcopenshell-python/ifcopenshell/util/fm.py b/src/ifcopenshell-python/ifcopenshell/util/fm.py index e260fe963f..d1b2e43329 100644 --- a/src/ifcopenshell-python/ifcopenshell/util/fm.py +++ b/src/ifcopenshell-python/ifcopenshell/util/fm.py @@ -16,6 +16,9 @@ # You should have received a copy of the GNU Lesser General Public License # along with IfcOpenShell. If not, see . +import ifcopenshell +import ifcopenshell.util.attribute + cobie_type_classes = [ "IfcDoorStyle", "IfcBuildingElementProxyType", @@ -138,10 +141,41 @@ def get_fmhem_types(ifc_file): fmhem_classes = fmhem_classes_ifc4 for ifc_class in fmhem_classes: try: - if ifc_class == "IfcEnergyConversionDeviceType": - elements += [e for e in ifc_file.by_type(ifc_class) if not e.is_a("IfcCooledBeamType")] + if ifc_class in ("IfcEnergyConversionDeviceType", "IfcFlowTerminalType"): + elements += [e for e in ifc_file.by_type(ifc_class) if not e.is_a() not in fmhem_excluded_classes] else: elements += ifc_file.by_type(ifc_class) except: pass return elements + + +def get_fmhem_classes(schema="IFC4"): + results = {} + + def get_fmhem_class(declaration): + if declaration.name() in fmhem_excluded_classes: + pass + elif declaration.is_abstract(): + pass + else: + types = [] + for attribute in declaration.all_attributes(): + if attribute.name() == "PredefinedType": + types = list(ifcopenshell.util.attribute.get_enum_items(attribute)) + if "NOTDEFINED" in types: + types.remove("NOTDEFINED") + results[declaration.name()] = types + + for subtype in declaration.subtypes(): + get_fmhem_class(subtype) + + if schema == "IFC4": + classes = fmhem_classes_ifc4 + elif schema == "IFC2X3": + classes = fmhem_classes_ifc2x3 + schema = ifcopenshell.ifcopenshell_wrapper.schema_by_name(schema) + for ifc_class in classes: + declaration = schema.declaration_by_name(ifc_class) + get_fmhem_class(declaration) + return results