From 5a766e79bd0a9ff2b1b7b8bddce3135328e7c42d Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Tue, 21 Jan 2025 16:22:42 +0500 Subject: [PATCH] Show error message trying to edit not supported type of profile E.g. previously if you would tab into editing IfcExtrudedAreaSolid that was using not supported profile type (e.g. IFCCSHAPEPROFILEDEF) it would import it as empty geometry and tabbing out then would save it corrupting the original profile. Now there is an error message that it's not yet supported - https://i.imgur.com/NzksYVP.png --- src/bonsai/bonsai/bim/module/geometry/operator.py | 8 +++++++- src/bonsai/bonsai/tool/model.py | 5 ++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/bonsai/bonsai/bim/module/geometry/operator.py b/src/bonsai/bonsai/bim/module/geometry/operator.py index f83bb863b4..b2b79e6670 100644 --- a/src/bonsai/bonsai/bim/module/geometry/operator.py +++ b/src/bonsai/bonsai/bim/module/geometry/operator.py @@ -1984,7 +1984,13 @@ class OverrideModeSetEdit(bpy.types.Operator, tool.Ifc.Operator): self.enable_edit_mode(context) elif item.is_a("IfcSweptAreaSolid"): tool.Geometry.sync_item_positions() - tool.Model.import_profile(item.SweptArea, obj=obj) + res = tool.Model.import_profile((profile := item.SweptArea), obj=obj) + if res is None: + self.report( + {"INFO"}, + f"Couldn't import profile, editing it directly is not yet supported. Failing profile: {profile}.", + ) + return obj.data.BIMMeshProperties.ifc_definition_id = item.id() self.enable_edit_mode(context) ProfileDecorator.install(context) diff --git a/src/bonsai/bonsai/tool/model.py b/src/bonsai/bonsai/tool/model.py index 0902741da9..4b348fc31b 100644 --- a/src/bonsai/bonsai/tool/model.py +++ b/src/bonsai/bonsai/tool/model.py @@ -286,7 +286,7 @@ class Model(bonsai.core.tool.Model): profile: ifcopenshell.entity_instance, obj: Optional[bpy.types.Object] = None, position: Optional[Matrix] = None, - ) -> bpy.types.Object: + ) -> Union[bpy.types.Object, None]: """Creates new profile mesh and assigns it to `obj`, if `obj` is `None` then new "Profile" object will be created. @@ -316,6 +316,9 @@ class Model(bonsai.core.tool.Model): for inner_boundary in profile.InnerBoundaries or []: cls.convert_curve_to_mesh(obj, position, inner_boundary) + if not cls.vertices or not cls.edges: + return None + mesh = bpy.data.meshes.new("Profile") mesh.from_pydata(cls.vertices, cls.edges, []) mesh.BIMMeshProperties.subshape_type = "PROFILE"