mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-10 09:48:32 +00:00
Add api.structural.assign_product, assign_to_building, and api.geometry.add_topology_representation
assign_product creates IfcRelAssignsToProduct linking a structural member to a physical building element. assign_to_building creates IfcRelServicesBuildings linking a structural analysis model to a building. add_topology_representation creates IfcTopologyRepresentation for structural elements, inferring the representation type from the item class. Generated with the assistance of an AI coding tool.
This commit is contained in:
@@ -25,6 +25,7 @@ geometry extrusions).
|
||||
|
||||
from .. import wrap_usecases
|
||||
from .add_axis_representation import add_axis_representation
|
||||
from .add_topology_representation import add_topology_representation
|
||||
from .add_boolean import add_boolean
|
||||
from .clip_solid import clip_solid
|
||||
from .clip_solid_bounded import clip_solid_bounded
|
||||
@@ -63,6 +64,7 @@ wrap_usecases(__path__, __name__)
|
||||
|
||||
__all__ = [
|
||||
"add_axis_representation",
|
||||
"add_topology_representation",
|
||||
"add_boolean",
|
||||
"clip_solid",
|
||||
"clip_solid_bounded",
|
||||
|
||||
@@ -0,0 +1,98 @@
|
||||
# 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.
|
||||
|
||||
from typing import Optional
|
||||
|
||||
import ifcopenshell
|
||||
|
||||
|
||||
_ITEM_TYPE_TO_REP_TYPE = {
|
||||
"IfcVertex": "Vertex",
|
||||
"IfcVertexPoint": "Vertex",
|
||||
"IfcEdge": "Edge",
|
||||
"IfcOrientedEdge": "Edge",
|
||||
"IfcEdgeCurve": "Edge",
|
||||
"IfcEdgeLoop": "Edge",
|
||||
"IfcPath": "Edge",
|
||||
"IfcFace": "Face",
|
||||
"IfcFaceSurface": "Face",
|
||||
"IfcAdvancedFace": "Face",
|
||||
"IfcClosedShell": "Face",
|
||||
"IfcOpenShell": "Face",
|
||||
"IfcConnectedFaceSet": "Face",
|
||||
}
|
||||
|
||||
|
||||
def add_topology_representation(
|
||||
file: ifcopenshell.file,
|
||||
context: ifcopenshell.entity_instance,
|
||||
item: ifcopenshell.entity_instance,
|
||||
representation_identifier: Optional[str] = None,
|
||||
representation_type: Optional[str] = None,
|
||||
) -> ifcopenshell.entity_instance:
|
||||
"""Adds an IfcTopologyRepresentation for a structural element
|
||||
|
||||
Structural analysis elements (IfcStructuralSurfaceMember,
|
||||
IfcStructuralCurveMember) use topology representations rather than solid
|
||||
geometry. This is analogous to :func:`add_axis_representation` and
|
||||
:func:`add_profile_representation` but produces an
|
||||
IfcTopologyRepresentation instead of an IfcShapeRepresentation.
|
||||
|
||||
The representation type ("Face", "Edge", "Vertex") is inferred from the
|
||||
item's IFC class if not provided explicitly.
|
||||
|
||||
:param context: The IfcGeometricRepresentationContext for the
|
||||
representation, typically a Reference context.
|
||||
:param item: The IfcTopologicalRepresentationItem (e.g. IfcFaceSurface,
|
||||
IfcEdge) to include in the representation.
|
||||
:param representation_identifier: The RepresentationIdentifier string.
|
||||
Defaults to the context's ContextIdentifier.
|
||||
:param representation_type: The RepresentationType string ("Face",
|
||||
"Edge", "Vertex"). Inferred from item class if not given.
|
||||
:return: The newly created IfcTopologyRepresentation entity.
|
||||
|
||||
Example:
|
||||
|
||||
.. code:: python
|
||||
|
||||
context = ifcopenshell.util.representation.get_context(
|
||||
model, "Model", "Reference", "GRAPH_VIEW")
|
||||
face = model.createIfcFaceSurface(bounds, surface, True)
|
||||
rep = ifcopenshell.api.geometry.add_topology_representation(
|
||||
model, context=context, item=face)
|
||||
ifcopenshell.api.geometry.assign_representation(
|
||||
model, product=member, representation=rep)
|
||||
"""
|
||||
if representation_identifier is None:
|
||||
representation_identifier = context.ContextIdentifier
|
||||
|
||||
if representation_type is None:
|
||||
for ifc_class, rep_type in _ITEM_TYPE_TO_REP_TYPE.items():
|
||||
if item.is_a(ifc_class):
|
||||
representation_type = rep_type
|
||||
break
|
||||
else:
|
||||
representation_type = "Undefined"
|
||||
|
||||
return file.createIfcTopologyRepresentation(
|
||||
context,
|
||||
representation_identifier,
|
||||
representation_type,
|
||||
[item],
|
||||
)
|
||||
@@ -30,7 +30,9 @@ from .add_structural_load import add_structural_load
|
||||
from .add_structural_load_case import add_structural_load_case
|
||||
from .add_structural_load_group import add_structural_load_group
|
||||
from .add_structural_member_connection import add_structural_member_connection
|
||||
from .assign_product import assign_product
|
||||
from .assign_structural_analysis_model import assign_structural_analysis_model
|
||||
from .assign_to_building import assign_to_building
|
||||
from .edit_structural_analysis_model import edit_structural_analysis_model
|
||||
from .edit_structural_boundary_condition import edit_structural_boundary_condition
|
||||
from .edit_structural_connection_cs import edit_structural_connection_cs
|
||||
@@ -57,7 +59,9 @@ __all__ = [
|
||||
"add_structural_load_case",
|
||||
"add_structural_load_group",
|
||||
"add_structural_member_connection",
|
||||
"assign_product",
|
||||
"assign_structural_analysis_model",
|
||||
"assign_to_building",
|
||||
"edit_structural_analysis_model",
|
||||
"edit_structural_boundary_condition",
|
||||
"edit_structural_connection_cs",
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
# 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
|
||||
import ifcopenshell.api.root
|
||||
|
||||
|
||||
def assign_product(
|
||||
file: ifcopenshell.file,
|
||||
relating_product: ifcopenshell.entity_instance,
|
||||
related_object: ifcopenshell.entity_instance,
|
||||
) -> ifcopenshell.entity_instance:
|
||||
"""Links an object to a product via IfcRelAssignsToProduct
|
||||
|
||||
Typically used to associate a physical building element with a structural
|
||||
analysis member (IfcStructuralSurfaceMember, IfcStructuralCurveMember) so
|
||||
that analysis results can be traced back to the physical model.
|
||||
|
||||
:param relating_product: The IfcProduct that the object is assigned to,
|
||||
typically an IfcStructuralMember.
|
||||
:param related_object: The IfcObjectDefinition being assigned, typically
|
||||
a physical building element such as an IfcWall or IfcSlab.
|
||||
:return: The IfcRelAssignsToProduct relationship.
|
||||
|
||||
Example:
|
||||
|
||||
.. code:: python
|
||||
|
||||
wall = ifcopenshell.api.root.create_entity(model, ifc_class="IfcWall")
|
||||
member = ifcopenshell.api.root.create_entity(
|
||||
model, ifc_class="IfcStructuralSurfaceMember")
|
||||
ifcopenshell.api.structural.assign_product(model,
|
||||
relating_product=member, related_object=wall)
|
||||
"""
|
||||
for rel in relating_product.ReferencedBy or []:
|
||||
if not rel.is_a("IfcRelAssignsToProduct"):
|
||||
continue
|
||||
if related_object in rel.RelatedObjects:
|
||||
return rel
|
||||
related_objects = list(rel.RelatedObjects)
|
||||
related_objects.append(related_object)
|
||||
rel.RelatedObjects = related_objects
|
||||
return rel
|
||||
|
||||
rel = ifcopenshell.api.root.create_entity(file, ifc_class="IfcRelAssignsToProduct")
|
||||
rel.RelatingProduct = relating_product
|
||||
rel.RelatedObjects = [related_object]
|
||||
return rel
|
||||
@@ -0,0 +1,64 @@
|
||||
# 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
|
||||
import ifcopenshell.api.owner
|
||||
import ifcopenshell.guid
|
||||
|
||||
|
||||
def assign_to_building(
|
||||
file: ifcopenshell.file,
|
||||
structural_analysis_model: ifcopenshell.entity_instance,
|
||||
building: ifcopenshell.entity_instance,
|
||||
) -> ifcopenshell.entity_instance:
|
||||
"""Associates a structural analysis model with a building via IfcRelServicesBuildings
|
||||
|
||||
The existing :func:`assign_structural_analysis_model` handles
|
||||
IfcRelAssignsToGroup (linking structural members to the analysis model).
|
||||
This function handles the separate model-to-building relationship, which
|
||||
records which building the structural analysis model serves.
|
||||
|
||||
:param structural_analysis_model: The IfcStructuralAnalysisModel to
|
||||
associate with the building.
|
||||
:param building: The IfcBuilding (or other IfcSpatialStructureElement)
|
||||
that the structural analysis model serves.
|
||||
:return: The IfcRelServicesBuildings relationship.
|
||||
|
||||
Example:
|
||||
|
||||
.. code:: python
|
||||
|
||||
building = ifcopenshell.util.selector.filter_elements(model, "IfcBuilding")[0]
|
||||
model_ = ifcopenshell.api.structural.add_structural_analysis_model(model)
|
||||
ifcopenshell.api.structural.assign_to_building(model,
|
||||
structural_analysis_model=model_, building=building)
|
||||
"""
|
||||
for rel in structural_analysis_model.ServicesBuildings or []:
|
||||
if building in rel.RelatedBuildings:
|
||||
return rel
|
||||
rel.RelatedBuildings = list(rel.RelatedBuildings) + [building]
|
||||
return rel
|
||||
|
||||
return file.create_entity(
|
||||
"IfcRelServicesBuildings",
|
||||
ifcopenshell.guid.new(),
|
||||
OwnerHistory=ifcopenshell.api.owner.create_owner_history(file),
|
||||
RelatingSystem=structural_analysis_model,
|
||||
RelatedBuildings=[building],
|
||||
)
|
||||
Reference in New Issue
Block a user