Consolidate adding alignments into Add Element interface

This commit is contained in:
Dion Moult
2026-02-25 10:24:18 +11:00
parent 160348df1f
commit fff653b882
3 changed files with 31 additions and 16 deletions
+5 -1
View File
@@ -82,6 +82,8 @@ class IfcClassData:
feature_elements = ifcopenshell.util.schema.get_subtypes(entity)
for feature_element in feature_elements:
names.remove(feature_element.name())
if ifc_product == "IfcAlignment":
names.extend(("IfcAlignmentHorizontal", "IfcAlignmentHorizontal", "IfcAlignmentCant"))
version = tool.Ifc.get_schema()
return [(c, c, (get_entity_doc(version, c) or {}).get("description", "")) for c in sorted(names)]
@@ -136,7 +138,9 @@ class IfcClassData:
("EMPTY", "No Geometry", "Start with an empty object"),
]
if ifc_class in ("IfcWindowType", "IfcWindowStyle", "IfcWindow"):
if ifc_class == "IfcAlignment":
return templates
elif ifc_class in ("IfcWindowType", "IfcWindowStyle", "IfcWindow"):
templates.extend([None, ("WINDOW", "Window", "Parametric window")])
elif ifc_class in ("IfcDoorType", "IfcDoorStyle", "IfcDoor"):
templates.extend([None, ("DOOR", "Door", "Parametric door")])
+11 -1
View File
@@ -531,6 +531,9 @@ class AddElement(bpy.types.Operator, tool.Ifc.Operator):
if props.ifc_product == "IfcFeatureElement" and not props.featured_obj:
return self.report({"WARNING"}, "A featured element must be nominated.")
if "Alignment" in props.ifc_product and props.ifc_product != "IfcAlignment" and not props.featured_obj:
return self.report({"WARNING"}, "A parent alignment element must be nominated.")
ifc_context = None
if get_enum_items(props, "contexts", context):
ifc_context = int(props.contexts or "0") or None
@@ -821,6 +824,13 @@ class AddElement(bpy.types.Operator, tool.Ifc.Operator):
tool.Model.purge_scene_openings()
tool.Collector.assign(obj)
if props.featured_obj:
alignment = tool.Ifc.get_entity(props.featured_obj)
if props.ifc_class == "IfcAlignment":
ifcopenshell.api.aggregate.assign_object(tool.Ifc.get(), products=[element], relating_object=alignment)
elif props.ifc_class in ("IfcAlignmentHorizontal", "IfcAlignmentVertical", "IfcAlignmentCant"):
ifcopenshell.api.nest.assign_object(tool.Ifc.get(), related_objects=[element], relating_object=alignment)
bonsai.core.geometry.edit_object_placement(tool.Ifc, tool.Geometry, tool.Surveyor, obj=obj)
tool.Blender.set_active_object(obj)
@@ -842,7 +852,7 @@ class AddElement(bpy.types.Operator, tool.Ifc.Operator):
if props.ifc_predefined_type == "USERDEFINED":
row = self.layout.row()
row.prop(props, "ifc_userdefined_type")
if props.ifc_product == "IfcFeatureElement":
if props.ifc_product in ("IfcFeatureElement", "IfcAlignment"):
row = self.layout.row()
row.prop(props, "featured_obj", text="Featured Object")
prop_with_search(self.layout, props, "representation_template", text="Representation", should_click_ok=True)
+15 -14
View File
@@ -474,10 +474,10 @@ class Root(bonsai.core.tool.Root):
obj.name = obj.name.split("/", 1)[1]
@classmethod
def get_ifc_products(cls) -> tuple[str, ...]:
def get_ifc_products(cls) -> list[str]:
version = tool.Ifc.get_schema()
if version == "IFC2X3":
products = (
return [
"IfcElementType",
"IfcElement",
"IfcFeatureElement",
@@ -485,16 +485,17 @@ class Root(bonsai.core.tool.Root):
"IfcStructuralItem",
"IfcAnnotation",
"IfcRelSpaceBoundary",
)
else:
products = (
"IfcElementType",
"IfcElement",
"IfcFeatureElement",
"IfcSpatialElement",
"IfcSpatialElementType",
"IfcStructuralItem",
"IfcAnnotation",
"IfcRelSpaceBoundary",
)
]
products = [
"IfcElementType",
"IfcElement",
"IfcFeatureElement",
"IfcSpatialElement",
"IfcSpatialElementType",
"IfcStructuralItem",
"IfcAnnotation",
"IfcRelSpaceBoundary",
]
if version != "IFC4":
products.append("IfcAlignment")
return products