diff --git a/src/bonsai/bonsai/bim/import_ifc.py b/src/bonsai/bonsai/bim/import_ifc.py index 256bd8ff85..318f4834e2 100644 --- a/src/bonsai/bonsai/bim/import_ifc.py +++ b/src/bonsai/bonsai/bim/import_ifc.py @@ -967,7 +967,7 @@ class IfcImporter: tool.Collector.assign(obj, should_clean_users_collection=False) def is_curve_annotation(self, element: ifcopenshell.entity_instance) -> bool: - object_type = element.ObjectType + object_type = ifcopenshell.util.element.get_predefined_type(element) return ( object_type in tool.Drawing.ANNOTATION_TYPES_DATA and tool.Drawing.ANNOTATION_TYPES_DATA[object_type].data_type == "curve" diff --git a/src/bonsai/bonsai/bim/module/drawing/annotation.py b/src/bonsai/bonsai/bim/module/drawing/annotation.py index 6acf5a03f7..50d987f30c 100644 --- a/src/bonsai/bonsai/bim/module/drawing/annotation.py +++ b/src/bonsai/bonsai/bim/module/drawing/annotation.py @@ -153,7 +153,11 @@ class Annotator: if object_type != "ANGLE": for obj in collection.objects: element = tool.Ifc.get_entity(obj) - if element and element.ObjectType == object_type and obj.type == object_type.upper(): + if ( + element + and ifcopenshell.util.element.get_predefined_type(element) == object_type + and obj.type == object_type.upper() + ): return obj if data_type == "mesh": diff --git a/src/bonsai/bonsai/bim/module/drawing/data.py b/src/bonsai/bonsai/bim/module/drawing/data.py index d781b8bd30..30fda54828 100644 --- a/src/bonsai/bonsai/bim/module/drawing/data.py +++ b/src/bonsai/bonsai/bim/module/drawing/data.py @@ -364,7 +364,11 @@ class DecoratorData: element = tool.Ifc.get_entity(obj) supported_object_types = ("DIMENSION", "DIAMETER", "SECTION_LEVEL", "PLAN_LEVEL", "RADIUS") - if not element or not element.is_a("IfcAnnotation") or element.ObjectType not in supported_object_types: + if ( + not element + or not element.is_a("IfcAnnotation") + or ifcopenshell.util.element.get_predefined_type(element) not in supported_object_types + ): return None dimension_style = "arrow" diff --git a/src/bonsai/bonsai/bim/module/drawing/decoration.py b/src/bonsai/bonsai/bim/module/drawing/decoration.py index 0bf8ab00b8..9c26c2b1c5 100644 --- a/src/bonsai/bonsai/bim/module/drawing/decoration.py +++ b/src/bonsai/bonsai/bim/module/drawing/decoration.py @@ -977,6 +977,7 @@ class FallDecorator(BaseDecorator): # same function as in svgwriter.py def get_label_text(): element = tool.Ifc.get_entity(obj) + assert element B, A = [v.co.xyz for v in spline_points[:2]] rise = abs(A.z - B.z) O = A.copy() @@ -989,13 +990,14 @@ class FallDecorator(BaseDecorator): angle = 90 # ues SLOPE_ANGLE as default - if element.ObjectType in ("FALL", "SLOPE_ANGLE"): + object_type = ifcopenshell.util.element.get_predefined_type(element) + if object_type in ("FALL", "SLOPE_ANGLE"): return f"{angle}°" - elif element.ObjectType == "SLOPE_FRACTION": + elif object_type == "SLOPE_FRACTION": if angle == 90: return "-" return f"{self.format_value(context, rise)} / {self.format_value(context, run)}" - elif element.ObjectType == "SLOPE_PERCENT": + elif object_type == "SLOPE_PERCENT": if angle == 90: return "-" return f"{round(angle_tg * 100)} %" @@ -2047,7 +2049,7 @@ class DecorationsHandler: if not element.is_a("IfcAnnotation"): continue - object_type: Union[str, None] = element.ObjectType + object_type: Union[str, None] = ifcopenshell.util.element.get_predefined_type(element) if object_type == "DRAWING": continue diff --git a/src/bonsai/bonsai/bim/module/drawing/operator.py b/src/bonsai/bonsai/bim/module/drawing/operator.py index 6014015995..3528e4dc36 100644 --- a/src/bonsai/bonsai/bim/module/drawing/operator.py +++ b/src/bonsai/bonsai/bim/module/drawing/operator.py @@ -1370,7 +1370,11 @@ class CreateDrawing(bpy.types.Operator): elements = list(elements | filtered_drawing_annotations) annotations = sorted( - elements, key=lambda a: (tool.Drawing.get_annotation_z_index(a), 1 if a.ObjectType == "TEXT" else 0) + elements, + key=lambda a: ( + tool.Drawing.get_annotation_z_index(a), + 1 if ifcopenshell.util.element.get_predefined_type(a) == "TEXT" else 0, + ), ) precision = ifcopenshell.util.element.get_pset(self.camera_element, "EPset_Drawing", "MetricPrecision") diff --git a/src/bonsai/bonsai/bim/module/drawing/svgwriter.py b/src/bonsai/bonsai/bim/module/drawing/svgwriter.py index e6dd66150a..9a249450f7 100644 --- a/src/bonsai/bonsai/bim/module/drawing/svgwriter.py +++ b/src/bonsai/bonsai/bim/module/drawing/svgwriter.py @@ -181,35 +181,35 @@ class SvgWriter: self.decimal_places = decimal_places for element in annotations: obj = tool.Ifc.get_object(element) - if not obj or element.ObjectType == "DRAWING": + if not obj or (object_type := ifcopenshell.util.element.get_predefined_type(element)) == "DRAWING": continue - elif element.ObjectType == "GRID": + elif object_type == "GRID": self.draw_grid_annotation(obj) - elif element.ObjectType == "TEXT_LEADER": + elif object_type == "TEXT_LEADER": self.draw_leader_annotation(obj) - elif element.ObjectType == "STAIR_ARROW": + elif object_type == "STAIR_ARROW": self.draw_stair_annotation(obj) - elif element.ObjectType == "DIMENSION": + elif object_type == "DIMENSION": self.draw_dimension_annotations(obj) - elif element.ObjectType == "ANGLE": + elif object_type == "ANGLE": self.draw_angle_annotations(obj) - elif element.ObjectType == "RADIUS": + elif object_type == "RADIUS": self.draw_radius_annotations(obj) - elif element.ObjectType == "DIAMETER": + elif object_type == "DIAMETER": self.draw_diameter_annotations(obj) - elif element.ObjectType == "ELEVATION": + elif object_type == "ELEVATION": self.draw_elevation_annotation(obj) - elif element.ObjectType == "SECTION": + elif object_type == "SECTION": self.draw_section_annotation(obj) - elif element.ObjectType == "BREAKLINE": + elif object_type == "BREAKLINE": self.draw_break_annotations(obj) - elif element.ObjectType == "PLAN_LEVEL": + elif object_type == "PLAN_LEVEL": self.draw_plan_level_annotation(obj) - elif element.ObjectType == "SECTION_LEVEL": + elif object_type == "SECTION_LEVEL": self.draw_section_level_annotation(obj) - elif element.ObjectType == "TEXT": + elif object_type == "TEXT": self.draw_text_annotation(obj, obj.location) - elif element.ObjectType in ("FALL", "SLOPE_ANGLE", "SLOPE_FRACTION", "SLOPE_PERCENT"): + elif object_type in ("FALL", "SLOPE_ANGLE", "SLOPE_FRACTION", "SLOPE_PERCENT"): self.draw_fall_annotations(obj) else: self.draw_misc_annotation(obj) @@ -1207,13 +1207,14 @@ class SvgWriter: angle = 90 # ues SLOPE_ANGLE as default - if element.ObjectType in ("FALL", "SLOPE_ANGLE"): + object_type = ifcopenshell.util.element.get_predefined_type(element) + if object_type in ("FALL", "SLOPE_ANGLE"): return f"{angle}°" - elif element.ObjectType == "SLOPE_FRACTION": + elif object_type == "SLOPE_FRACTION": if angle == 90: return "-" return f"{helper.format_distance(rise, precision=self.precision, decimal_places=self.decimal_places)} / {helper.format_distance(run, precision=self.precision, decimal_places=self.decimal_places)}" - elif element.ObjectType == "SLOPE_PERCENT": + elif object_type == "SLOPE_PERCENT": if angle == 90: return "-" return f"{round(angle_tg * 100)} %" diff --git a/src/bonsai/bonsai/bim/module/drawing/workspace.py b/src/bonsai/bonsai/bim/module/drawing/workspace.py index bd679cb065..16d26ea7e0 100644 --- a/src/bonsai/bonsai/bim/module/drawing/workspace.py +++ b/src/bonsai/bonsai/bim/module/drawing/workspace.py @@ -19,6 +19,7 @@ import os import bpy +import ifcopenshell.util.element import bonsai.core.type import bonsai.core.drawing as core import bonsai.tool as tool @@ -333,7 +334,7 @@ class Hotkey(bpy.types.Operator, tool.Ifc.Operator): if not element or not element.is_a("IfcAnnotation"): continue - annotation_type = element.ObjectType + annotation_type = ifcopenshell.util.element.get_predefined_type(element) if annotation_type not in tool.Drawing.ANNOTATION_TYPES_SUPPORT_SETUP: self.report({"ERROR"}, f"Annotation type {annotation_type} is not supported for readjustment.") continue diff --git a/src/bonsai/bonsai/tool/drawing.py b/src/bonsai/bonsai/tool/drawing.py index 07e274b011..0dd090c617 100644 --- a/src/bonsai/bonsai/tool/drawing.py +++ b/src/bonsai/bonsai/tool/drawing.py @@ -245,7 +245,7 @@ class Drawing(bonsai.core.tool.Drawing): element_type = element.is_a() - if element_type == "IfcAnnotation" and element.ObjectType in object_types: + if element_type == "IfcAnnotation" and ifcopenshell.util.element.get_predefined_type(element) in object_types: return True if element_type == "IfcTypeProduct" and (