From ca502cc2934d77d6d207c1fbe3f9c02ef0689b5f Mon Sep 17 00:00:00 2001 From: Dion Moult Date: Mon, 18 Apr 2022 10:26:03 +1000 Subject: [PATCH] #1153 Fix bugs with importing existing annotations --- src/blenderbim/blenderbim/bim/import_ifc.py | 31 +++++-------------- .../blenderbim/bim/module/drawing/operator.py | 10 +++--- 2 files changed, 14 insertions(+), 27 deletions(-) diff --git a/src/blenderbim/blenderbim/bim/import_ifc.py b/src/blenderbim/blenderbim/bim/import_ifc.py index cb41036dd8..e5e35d110a 100644 --- a/src/blenderbim/blenderbim/bim/import_ifc.py +++ b/src/blenderbim/blenderbim/bim/import_ifc.py @@ -1509,9 +1509,10 @@ class IfcImporter: return self.structural_member_collection.objects.link(obj) elif element.is_a("IfcStructuralConnection"): return self.structural_connection_collection.objects.link(obj) - elif element.is_a("IfcAnnotation") and self.is_drawing_annotation(element): - group = [r for r in element.HasAssignments if r.is_a("IfcRelAssignsToGroup")][0].RelatingGroup - return self.collections[group.GlobalId].objects.link(obj) + elif element.is_a("IfcAnnotation"): + group = self.get_drawing_group(element) + if group: + return self.collections[group.GlobalId].objects.link(obj) container = ifcopenshell.util.element.get_container(element) if container: @@ -1531,32 +1532,16 @@ class IfcImporter: return element.ObjectType in [ "DIMENSION", "EQUAL_DIMENSION", - "MISC", "PLAN_LEVEL", "SECTION_LEVEL", "STAIR_ARROW", "TEXT_LEADER", ] - def is_drawing_annotation(self, element): - return element.ObjectType in [ - "BREAKLINE", - "DIMENSION", - "DRAWING", - "EQUAL_DIMENSION", - "GRID", - "HIDDEN_LINE", - "MISC", - "PLAN_LEVEL", - "SECTION_LEVEL", - "STAIR_ARROW", - "TEXT", - "TEXT_LEADER", - "LEADER", - "HATCH", - "LINEWORK", - "AREA", - ] + def get_drawing_group(self, element): + for rel in element.HasAssignments or []: + if rel.is_a("IfcRelAssignsToGroup"): + return rel.RelatingGroup def get_element_matrix(self, element): result = ifcopenshell.util.placement.get_local_placement(element.ObjectPlacement) diff --git a/src/blenderbim/blenderbim/bim/module/drawing/operator.py b/src/blenderbim/blenderbim/bim/module/drawing/operator.py index 940afb575f..dd498fd9f0 100644 --- a/src/blenderbim/blenderbim/bim/module/drawing/operator.py +++ b/src/blenderbim/blenderbim/bim/module/drawing/operator.py @@ -442,13 +442,15 @@ class CreateDrawing(bpy.types.Operator): svg_writer.camera_height = height svg_writer.camera_projection = tuple(camera.matrix_world.to_quaternion() @ Vector((0, 0, -1))) - for obj in camera.users_collection[0].objects: - if "IfcAnnotation/" not in obj.name: + for element in tool.Drawing.get_group_elements(tool.Drawing.get_drawing_group(self.camera_element)): + if not element.is_a("IfcAnnotation"): + continue + obj = tool.Ifc.get_object(element) + if not obj: continue - element = tool.Ifc.get_entity(obj) if element.ObjectType == "GRID": svg_writer.annotations.setdefault("grid_objs", []).append(obj) - elif obj.type == "CAMERA": + elif element.ObjectType == "DRAWING": continue elif element.ObjectType == "TEXT_LEADER": svg_writer.annotations.setdefault("leader_objs", []).append(obj)