api.boundary.edit_attributes: add PhysicalOrVirtualBoundary and InternalOrExternalBoundary params

Both attributes are required by the IFC schema but were not settable via
the API function. Add physical_or_virtual and internal_or_external parameters
with "NOTDEFINED" defaults for backward compatibility. Update Bonsai boundary
panel to expose both fields in the editor.

Generated with the assistance of an AI coding tool.
This commit is contained in:
Bruno Postle
2026-03-30 07:25:22 +01:00
parent c214d255c9
commit be05d771a2
5 changed files with 175 additions and 9 deletions
@@ -27,12 +27,11 @@ def edit_attributes(
related_building_element: ifcopenshell.entity_instance,
parent_boundary: Optional[ifcopenshell.entity_instance] = None,
corresponding_boundary: Optional[ifcopenshell.entity_instance] = None,
physical_or_virtual: str = "NOTDEFINED",
internal_or_external: str = "NOTDEFINED",
) -> None:
"""Modify the relationships of a space boundary relationship
Currently this function is quite minimal and offers no advantage to
manual assignment of the space boundary attributes.
:param entity: The IfcRelSpaceBoundary to modify
:param relating_space: The IfcSpace or IfcExternalSpatialElement that
the space boundary is related to.
@@ -44,17 +43,18 @@ def edit_attributes(
:param corresponding_boundary: The other IfcRelSpaceBoundary on the
other side of the related element. The pair together represents a
thermal boundary. This only applies to 2nd level boundaries.
:param physical_or_virtual: IfcPhysicalOrVirtualEnum value: "PHYSICAL",
"VIRTUAL", or "NOTDEFINED".
:param internal_or_external: IfcInternalOrExternalEnum value:
"INTERNAL", "EXTERNAL", "EXTERNAL_EARTH", "EXTERNAL_WATER",
"EXTERNAL_FIRE", or "NOTDEFINED".
:return: None
"""
entity = entity
relating_space = relating_space
related_building_element = related_building_element
parent_boundary = parent_boundary
corresponding_boundary = corresponding_boundary
entity.RelatingSpace = relating_space
entity.RelatedBuildingElement = related_building_element
if hasattr(entity, "ParentBoundary"):
entity.ParentBoundary = parent_boundary
if hasattr(entity, "CorrespondingBoundary"):
entity.CorrespondingBoundary = corresponding_boundary
entity.PhysicalOrVirtualBoundary = physical_or_virtual
entity.InternalOrExternalBoundary = internal_or_external
@@ -0,0 +1,115 @@
# IfcOpenShell - IFC toolkit and geometry engine
# Copyright (C) 2026 Dion Moult <dion@thinkmoult.com>
#
# This file is part of IfcOpenShell.
#
# IfcOpenShell is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# IfcOpenShell is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
# This file was generated with the assistance of an AI coding tool.
import ifcopenshell.api.boundary
import ifcopenshell.api.root
import test.bootstrap
class TestEditAttributes(test.bootstrap.IFC4):
def setup_boundary(self):
space = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcSpace")
wall = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
boundary = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcRelSpaceBoundary")
return boundary, space, wall
def test_sets_relating_space_and_building_element(self):
boundary, space, wall = self.setup_boundary()
ifcopenshell.api.boundary.edit_attributes(
self.file, entity=boundary, relating_space=space, related_building_element=wall
)
assert boundary.RelatingSpace == space
assert boundary.RelatedBuildingElement == wall
def test_defaults_enums_to_notdefined(self):
boundary, space, wall = self.setup_boundary()
ifcopenshell.api.boundary.edit_attributes(
self.file, entity=boundary, relating_space=space, related_building_element=wall
)
assert boundary.PhysicalOrVirtualBoundary == "NOTDEFINED"
assert boundary.InternalOrExternalBoundary == "NOTDEFINED"
def test_sets_physical_or_virtual(self):
boundary, space, wall = self.setup_boundary()
ifcopenshell.api.boundary.edit_attributes(
self.file,
entity=boundary,
relating_space=space,
related_building_element=wall,
physical_or_virtual="PHYSICAL",
)
assert boundary.PhysicalOrVirtualBoundary == "PHYSICAL"
def test_sets_internal_or_external(self):
boundary, space, wall = self.setup_boundary()
ifcopenshell.api.boundary.edit_attributes(
self.file,
entity=boundary,
relating_space=space,
related_building_element=wall,
internal_or_external="EXTERNAL",
)
assert boundary.InternalOrExternalBoundary == "EXTERNAL"
def test_sets_all_enum_variants(self):
boundary, space, wall = self.setup_boundary()
for value in ("PHYSICAL", "VIRTUAL", "NOTDEFINED"):
ifcopenshell.api.boundary.edit_attributes(
self.file,
entity=boundary,
relating_space=space,
related_building_element=wall,
physical_or_virtual=value,
)
assert boundary.PhysicalOrVirtualBoundary == value
for value in ("INTERNAL", "EXTERNAL", "EXTERNAL_EARTH", "EXTERNAL_WATER", "EXTERNAL_FIRE", "NOTDEFINED"):
ifcopenshell.api.boundary.edit_attributes(
self.file,
entity=boundary,
relating_space=space,
related_building_element=wall,
internal_or_external=value,
)
assert boundary.InternalOrExternalBoundary == value
class TestEditAttributesIFC2X3(test.bootstrap.IFC2X3, TestEditAttributes):
def test_sets_all_enum_variants(self):
boundary, space, wall = self.setup_boundary()
for value in ("PHYSICAL", "VIRTUAL", "NOTDEFINED"):
ifcopenshell.api.boundary.edit_attributes(
self.file,
entity=boundary,
relating_space=space,
related_building_element=wall,
physical_or_virtual=value,
)
assert boundary.PhysicalOrVirtualBoundary == value
# IFC2X3 only has INTERNAL, EXTERNAL, NOTDEFINED
for value in ("INTERNAL", "EXTERNAL", "NOTDEFINED"):
ifcopenshell.api.boundary.edit_attributes(
self.file,
entity=boundary,
relating_space=space,
related_building_element=wall,
internal_or_external=value,
)
assert boundary.InternalOrExternalBoundary == value