mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-26 02:07:36 +00:00
Select profile for profile type objects #5814
Demo - https://imgchest.com/p/9rydjxwanyk
This commit is contained in:
@@ -51,6 +51,7 @@ class IfcClassData:
|
|||||||
cls.data["ifc_class"] = cls.ifc_class()
|
cls.data["ifc_class"] = cls.ifc_class()
|
||||||
cls.data["ifc_predefined_types"] = cls.ifc_predefined_types()
|
cls.data["ifc_predefined_types"] = cls.ifc_predefined_types()
|
||||||
cls.data["can_reassign_class"] = cls.can_reassign_class()
|
cls.data["can_reassign_class"] = cls.can_reassign_class()
|
||||||
|
cls.data["profile"] = cls.profile()
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def ifc_products(cls):
|
def ifc_products(cls):
|
||||||
@@ -289,3 +290,13 @@ class IfcClassData:
|
|||||||
if element.is_a(product[0]):
|
if element.is_a(product[0]):
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def profile(cls) -> list[tuple[str, str, str]]:
|
||||||
|
items = [("-", "-", "")]
|
||||||
|
ifc_file = tool.Ifc.get()
|
||||||
|
for profile in ifc_file.by_type("IfcProfileDef"):
|
||||||
|
if not (profile_name := profile.ProfileName):
|
||||||
|
continue
|
||||||
|
items.append((str(profile.id()), profile_name, profile.is_a()))
|
||||||
|
return items
|
||||||
|
|||||||
@@ -344,6 +344,7 @@ class AddElement(bpy.types.Operator, tool.Ifc.Operator):
|
|||||||
props.userdefined_type if props.ifc_predefined_type == "USERDEFINED" else props.ifc_predefined_type
|
props.userdefined_type if props.ifc_predefined_type == "USERDEFINED" else props.ifc_predefined_type
|
||||||
)
|
)
|
||||||
representation_template = props.representation_template
|
representation_template = props.representation_template
|
||||||
|
ifc_file = tool.Ifc.get()
|
||||||
|
|
||||||
ifc_context = None
|
ifc_context = None
|
||||||
if get_enum_items(props, "contexts", context):
|
if get_enum_items(props, "contexts", context):
|
||||||
@@ -456,14 +457,20 @@ class AddElement(bpy.types.Operator, tool.Ifc.Operator):
|
|||||||
else:
|
else:
|
||||||
material = ifcopenshell.api.run("material.add_material", tool.Ifc.get(), name="Unknown")
|
material = ifcopenshell.api.run("material.add_material", tool.Ifc.get(), name="Unknown")
|
||||||
if representation_template == "PROFILESET":
|
if representation_template == "PROFILESET":
|
||||||
named_profiles = [p for p in tool.Ifc.get().by_type("IfcProfileDef") if p.ProfileName]
|
profile_id = tool.Blender.get_enum_safe(context.scene.BIMRootProperties, "profile")
|
||||||
if named_profiles:
|
if profile_id in ("-", None):
|
||||||
profile = named_profiles[0]
|
profile = next((p for p in ifc_file.by_type("IfcProfileDef") if p.ProfileName), None)
|
||||||
|
if profile is None:
|
||||||
|
size = 0.5 / unit_scale
|
||||||
|
profile = ifc_file.create_entity(
|
||||||
|
"IfcRectangleProfileDef",
|
||||||
|
ProfileName="New Profile",
|
||||||
|
ProfileType="AREA",
|
||||||
|
XDim=size,
|
||||||
|
YDim=size,
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
size = 0.5 / unit_scale
|
profile = ifc_file.by_id(int(profile_id))
|
||||||
profile = tool.Ifc.get().create_entity(
|
|
||||||
"IfcRectangleProfileDef", ProfileName="New Profile", ProfileType="AREA", XDim=size, YDim=size
|
|
||||||
)
|
|
||||||
else:
|
else:
|
||||||
# NOTE: defaults dims are in meters / mm
|
# NOTE: defaults dims are in meters / mm
|
||||||
# for now default names are hardcoded to mm
|
# for now default names are hardcoded to mm
|
||||||
@@ -541,6 +548,9 @@ class AddElement(bpy.types.Operator, tool.Ifc.Operator):
|
|||||||
if props.representation_template == "OBJ":
|
if props.representation_template == "OBJ":
|
||||||
row = self.layout.row()
|
row = self.layout.row()
|
||||||
row.prop(props, "representation_obj", text="Object")
|
row.prop(props, "representation_obj", text="Object")
|
||||||
|
elif props.representation_template == "PROFILESET":
|
||||||
|
row = self.layout.row()
|
||||||
|
row.prop(props, "profile", text="Profile")
|
||||||
if props.representation_template != "EMPTY":
|
if props.representation_template != "EMPTY":
|
||||||
prop_with_search(self.layout, props, "contexts")
|
prop_with_search(self.layout, props, "contexts")
|
||||||
|
|
||||||
|
|||||||
@@ -88,6 +88,12 @@ def get_contexts(self, context):
|
|||||||
return IfcClassData.data["contexts"]
|
return IfcClassData.data["contexts"]
|
||||||
|
|
||||||
|
|
||||||
|
def get_profile(self, context):
|
||||||
|
if not IfcClassData.is_loaded:
|
||||||
|
IfcClassData.load()
|
||||||
|
return IfcClassData.data["profile"]
|
||||||
|
|
||||||
|
|
||||||
def update_relating_class_from_object(self, context):
|
def update_relating_class_from_object(self, context):
|
||||||
if self.relating_class_object is None:
|
if self.relating_class_object is None:
|
||||||
return
|
return
|
||||||
@@ -134,6 +140,7 @@ class BIMRootProperties(PropertyGroup):
|
|||||||
poll=poll_representation_obj,
|
poll=poll_representation_obj,
|
||||||
description="The representation will be a tessellation of the selected object",
|
description="The representation will be a tessellation of the selected object",
|
||||||
)
|
)
|
||||||
|
profile: EnumProperty(name="Profile for profile type object", items=get_profile)
|
||||||
relating_class_object: PointerProperty(
|
relating_class_object: PointerProperty(
|
||||||
type=bpy.types.Object,
|
type=bpy.types.Object,
|
||||||
name="Copy Class",
|
name="Copy Class",
|
||||||
|
|||||||
Reference in New Issue
Block a user