From 57d6e9b544ac89f743b7e740667e7396bd6227e3 Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Mon, 24 Feb 2025 15:10:10 +0500 Subject: [PATCH] Fix error reassigning class for structural items --- src/bonsai/bonsai/bim/module/root/data.py | 21 +-------------- src/bonsai/bonsai/bim/module/root/operator.py | 12 +-------- src/bonsai/bonsai/tool/root.py | 26 +++++++++++++++++++ 3 files changed, 28 insertions(+), 31 deletions(-) diff --git a/src/bonsai/bonsai/bim/module/root/data.py b/src/bonsai/bonsai/bim/module/root/data.py index 10c50839ec..8a0376eb64 100644 --- a/src/bonsai/bonsai/bim/module/root/data.py +++ b/src/bonsai/bonsai/bim/module/root/data.py @@ -54,27 +54,8 @@ class IfcClassData: @classmethod def ifc_products(cls): - products = [ - "IfcElementType", - "IfcElement", - "IfcFeatureElement", - "IfcSpatialElement", - "IfcSpatialElementType", - "IfcStructuralItem", - "IfcAnnotation", - "IfcRelSpaceBoundary", - ] + products = tool.Root.get_ifc_products() version = tool.Ifc.get_schema() - if version == "IFC2X3": - products = [ - "IfcElementType", - "IfcElement", - "IfcFeatureElement", - "IfcSpatialStructureElement", - "IfcStructuralItem", - "IfcAnnotation", - "IfcRelSpaceBoundary", - ] return [(e, e, (get_entity_doc(version, e) or {}).get("description", "")) for e in products] @classmethod diff --git a/src/bonsai/bonsai/bim/module/root/operator.py b/src/bonsai/bonsai/bim/module/root/operator.py index f04cde36f1..77fc3eebb9 100644 --- a/src/bonsai/bonsai/bim/module/root/operator.py +++ b/src/bonsai/bonsai/bim/module/root/operator.py @@ -48,17 +48,7 @@ class EnableReassignClass(bpy.types.Operator): assert element ifc_class = element.is_a() context.active_object.BIMObjectProperties.is_reassigning_class = True - ifc_products = [ - "IfcElement", - "IfcElementType", - "IfcSpatialElement", - "IfcGroup", - "IfcStructural", - "IfcPositioningElement", - "IfcContext", - "IfcAnnotation", - "IfcRelSpaceBoundary", - ] + ifc_products = tool.Root.get_ifc_products() schema = tool.Ifc.schema() declaration = schema.declaration_by_name(ifc_class) for ifc_product in ifc_products: diff --git a/src/bonsai/bonsai/tool/root.py b/src/bonsai/bonsai/tool/root.py index ac763cdbf4..c665e1226c 100644 --- a/src/bonsai/bonsai/tool/root.py +++ b/src/bonsai/bonsai/tool/root.py @@ -429,3 +429,29 @@ class Root(bonsai.core.tool.Root): tool.Ifc.unlink(obj=material) if "Ifc" in obj.name and "/" in obj.name: obj.name = obj.name.split("/", 1)[1] + + @classmethod + def get_ifc_products(cls) -> tuple[str, ...]: + version = tool.Ifc.get_schema() + if version == "IFC2X3": + products = ( + "IfcElementType", + "IfcElement", + "IfcFeatureElement", + "IfcSpatialStructureElement", + "IfcStructuralItem", + "IfcAnnotation", + "IfcRelSpaceBoundary", + ) + else: + products = ( + "IfcElementType", + "IfcElement", + "IfcFeatureElement", + "IfcSpatialElement", + "IfcSpatialElementType", + "IfcStructuralItem", + "IfcAnnotation", + "IfcRelSpaceBoundary", + ) + return products