mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-10 01:41:57 +00:00
Add the option to create IfcArbitraryClosedProfileDef from an object.
Reference: https://imgur.com/a/E5YhgqV
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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():
|
||||
|
||||
@@ -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",
|
||||
|
||||
Reference in New Issue
Block a user