From f4cbd13748c2344137b5c0914bac6211cda40f11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bruno=20Perdig=C3=A3o?= Date: Tue, 12 Nov 2024 16:50:57 -0300 Subject: [PATCH] Add the option to create `IfcArbitraryClosedProfileDef` from an object. Reference: https://imgur.com/a/E5YhgqV --- .../bonsai/bim/module/profile/operator.py | 18 +++++++++++++++++- src/bonsai/bonsai/bim/module/profile/prop.py | 1 + src/bonsai/bonsai/bim/module/profile/ui.py | 3 +++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/bonsai/bonsai/bim/module/profile/operator.py b/src/bonsai/bonsai/bim/module/profile/operator.py index b976c16b7e..264779c8f0 100644 --- a/src/bonsai/bonsai/bim/module/profile/operator.py +++ b/src/bonsai/bonsai/bim/module/profile/operator.py @@ -151,10 +151,26 @@ class AddProfileDef(bpy.types.Operator, tool.Ifc.Operator): bl_options = {"REGISTER", "UNDO"} def _execute(self, context): + obj_points = [] + obj = context.scene.BIMProfileProperties.object_to_profile + if obj: + if len(obj.data.polygongs > 1): + self.report({"WARNING"}, "This mesh is invalid to create a profile. Select a flat mesh with no more then one face.") + return + for v in obj.data.polygons[0].vertices: + vert = obj.data.vertices[v] + if vert.co.z > 0: + self.report({"WARNING"}, "This mesh is invalid to create a profile. Select a flat mesh with all its vertices at z=0") + return + obj_points.append((vert.co.x, vert.co.y)) + if obj_points: + obj_points.append(obj_points[0]) + obj_points = [(v[0] - obj_points[0][0], v[1] - obj_points[0][1]) for v in obj_points] # Make sure the first point is (0, 0) + props = context.scene.BIMProfileProperties profile_class = props.profile_classes if profile_class == "IfcArbitraryClosedProfileDef": - points = [(0, 0), (0.1, 0), (0.1, 0.1), (0, 0.1), (0, 0)] + points = [(0, 0), (0.1, 0), (0.1, 0.1), (0, 0.1), (0, 0)] if not obj_points else obj_points profile = ifcopenshell.api.run("profile.add_arbitrary_profile", tool.Ifc.get(), profile=points) else: profile = ifcopenshell.api.run("profile.add_parameterized_profile", tool.Ifc.get(), ifc_class=profile_class) diff --git a/src/bonsai/bonsai/bim/module/profile/prop.py b/src/bonsai/bonsai/bim/module/profile/prop.py index d539fe27b3..ab385b8f29 100644 --- a/src/bonsai/bonsai/bim/module/profile/prop.py +++ b/src/bonsai/bonsai/bim/module/profile/prop.py @@ -72,6 +72,7 @@ class BIMProfileProperties(PropertyGroup): description="Check to only show IfcProfileDefs attached to IfcMaterialProfiles", update=lambda self, context: bpy.ops.bim.load_profiles(), ) + object_to_profile: PointerProperty(name="Object to profile", type=bpy.types.Object, description="Object to copy the mesh to a profile") def generate_thumbnail_for_active_profile(): diff --git a/src/bonsai/bonsai/bim/module/profile/ui.py b/src/bonsai/bonsai/bim/module/profile/ui.py index f78f3c3255..410bf625b6 100644 --- a/src/bonsai/bonsai/bim/module/profile/ui.py +++ b/src/bonsai/bonsai/bim/module/profile/ui.py @@ -74,6 +74,9 @@ class BIM_PT_profiles(Panel): row.prop(self.props, "profile_classes", text="") row.operator("bim.add_profile_def", text="", icon="ADD") row.operator("bim.duplicate_profile_def", icon="DUPLICATE", text="") + if self.props.profile_classes == "IfcArbitraryClosedProfileDef": + row = self.layout.row(align=True) + row.prop(self.props, "object_to_profile", text="Create From") self.layout.template_list( "BIM_UL_profiles",