From 4a59b30f1bc41206ae04e97a1c2db00e3431cafb Mon Sep 17 00:00:00 2001 From: Dion Moult Date: Thu, 29 Aug 2024 18:42:37 +1000 Subject: [PATCH] Fix #5244. Prioritise collection of drawing groups over containment groups --- .../bonsai/bim/module/drawing/operator.py | 5 +++- src/bonsai/bonsai/tool/collector.py | 29 ++++++++++--------- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/src/bonsai/bonsai/bim/module/drawing/operator.py b/src/bonsai/bonsai/bim/module/drawing/operator.py index 966177a56c..37e8a67837 100644 --- a/src/bonsai/bonsai/bim/module/drawing/operator.py +++ b/src/bonsai/bonsai/bim/module/drawing/operator.py @@ -1770,7 +1770,10 @@ class ReloadDrawingStyles(bpy.types.Operator): drawing_style.raster_style = json.dumps(style_data["raster_style"]) if current_style is not None: - camera_props.active_drawing_style_index = styles.index(current_style) + try: + camera_props.active_drawing_style_index = styles.index(current_style) + except ValueError: + self.report({"INFO"}, f"Could not find style {current_style} in EPset_Drawing.ShadingStyles.") return {"FINISHED"} diff --git a/src/bonsai/bonsai/tool/collector.py b/src/bonsai/bonsai/tool/collector.py index b5b163d967..c442df6a04 100644 --- a/src/bonsai/bonsai/tool/collector.py +++ b/src/bonsai/bonsai/tool/collector.py @@ -79,26 +79,19 @@ class Collector(bonsai.core.tool.Collector): cls.link_to_collection_safe(obj, collection) project_obj = tool.Ifc.get_object(tool.Ifc.get().by_type("IfcProject")[0]) cls.link_to_collection_safe(collection, project_obj.BIMObjectProperties.collection) + elif element.is_a("IfcAnnotation") and element.ObjectType == "DRAWING": + if collection := cls._create_own_collection(obj): + cls.link_to_collection_safe(obj, collection) + project_obj = tool.Ifc.get_object(tool.Ifc.get().by_type("IfcProject")[0]) + cls.link_to_collection_safe(collection, project_obj.BIMObjectProperties.collection) + elif element.is_a("IfcAnnotation") and (drawing_obj := cls.get_annotation_drawing_obj(element)): + cls.link_to_collection_safe(obj, drawing_obj.BIMObjectProperties.collection) elif container := ifcopenshell.util.element.get_container(element): container_obj = tool.Ifc.get_object(container) if not (collection := container_obj.BIMObjectProperties.collection): cls.assign(container_obj) collection = container_obj.BIMObjectProperties.collection cls.link_to_collection_safe(obj, collection) - elif element.is_a("IfcAnnotation"): - if element.ObjectType == "DRAWING": - if collection := cls._create_own_collection(obj): - cls.link_to_collection_safe(obj, collection) - project_obj = tool.Ifc.get_object(tool.Ifc.get().by_type("IfcProject")[0]) - cls.link_to_collection_safe(collection, project_obj.BIMObjectProperties.collection) - else: - for rel in element.HasAssignments or []: - if rel.is_a("IfcRelAssignsToGroup") and rel.RelatingGroup.ObjectType == "DRAWING": - for related_object in rel.RelatedObjects: - if related_object.is_a("IfcAnnotation") and related_object.ObjectType == "DRAWING": - drawing_obj = tool.Ifc.get_object(related_object) - if drawing_obj: - cls.link_to_collection_safe(obj, drawing_obj.BIMObjectProperties.collection) else: collection = cls._create_project_child_collection("Unsorted") collection.hide_viewport = False @@ -126,6 +119,14 @@ class Collector(bonsai.core.tool.Collector): collection.BIMCollectionProperties.obj = obj return collection + @classmethod + def get_annotation_drawing_obj(cls, element: ifcopenshell.entity_instance) -> bpy.types.Object | None: + for rel in element.HasAssignments or []: + if rel.is_a("IfcRelAssignsToGroup") and rel.RelatingGroup.ObjectType == "DRAWING": + for related_object in rel.RelatedObjects: + if related_object.is_a("IfcAnnotation") and related_object.ObjectType == "DRAWING": + return tool.Ifc.get_object(related_object) + @classmethod def link_to_collection_safe( cls, obj_or_col: Union[bpy.types.Object, bpy.types.Collection], collection: bpy.types.Collection