Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/context/__init__.py +39 -0
- data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/context/add_context.py +239 -0
- data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/context/edit_context.py +48 -0
- data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/context/remove_context.py +65 -0
- data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/library/__init__.py +47 -0
- data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/library/add_library.py +61 -0
- data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/library/add_reference.py +57 -0
- data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/library/assign_reference.py +89 -0
- data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/library/edit_library.py +55 -0
- data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/library/edit_reference.py +45 -0
- data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/library/remove_library.py +58 -0
- data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/library/remove_reference.py +51 -0
- data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/library/unassign_reference.py +78 -0
- data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/material/__init__.py +89 -0
- data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/material/add_constituent.py +91 -0
- data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/material/add_material.py +85 -0
- data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/material/copy_material.py +103 -0
- data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/material/edit_constituent.py +66 -0
- data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/material/edit_layer.py +65 -0
- data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/material/edit_layer_usage.py +76 -0
- data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/material/remove_profile.py +80 -0
- data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/material/reorder_set_item.py +69 -0
- data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/resource/__init__.py +55 -0
- data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/resource/add_resource.py +88 -0
- data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/resource/add_resource_quantity.py +83 -0
- data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/resource/add_resource_time.py +59 -0
- data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/resource/assign_resource.py +106 -0
- data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/resource/calculate_resource_usage.py +55 -0
- data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/resource/calculate_resource_work.py +63 -0
- data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/resource/edit_resource.py +43 -0
- data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/resource/edit_resource_quantity.py +54 -0
- data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/resource/edit_resource_time.py +98 -0
- data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/resource/remove_resource.py +78 -0
- data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/resource/remove_resource_quantity.py +50 -0
- data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/resource/unassign_resource.py +72 -0
- data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/root/__init__.py +42 -0
- data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/root/copy_class.py +194 -0
- data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/root/create_entity.py +139 -0
- data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/root/reassign_class.py +236 -0
- data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/root/remove_product.py +223 -0
- data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/sequence/assign_recurrence_pattern.py +118 -0
- data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/sequence/remove_work_time.py +48 -0
- data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/unit/__init__.py +53 -0
- data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/unit/add_context_dependent_unit.py +61 -0
- data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/unit/add_conversion_based_unit.py +81 -0
- data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/unit/add_derived_unit.py +77 -0
- data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/unit/add_monetary_unit.py +42 -0
- data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/unit/add_si_unit.py +59 -0
- data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/unit/assign_unit.py +162 -0
- data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/unit/edit_derived_unit.py +33 -0
data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/context/__init__.py
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# IfcOpenShell - IFC toolkit and geometry engine
|
| 2 |
+
# Copyright (C) 2022 Dion Moult <dion@thinkmoult.com>
|
| 3 |
+
#
|
| 4 |
+
# This file is part of IfcOpenShell.
|
| 5 |
+
#
|
| 6 |
+
# IfcOpenShell is free software: you can redistribute it and/or modify
|
| 7 |
+
# it under the terms of the GNU Lesser General Public License as published by
|
| 8 |
+
# the Free Software Foundation, either version 3 of the License, or
|
| 9 |
+
# (at your option) any later version.
|
| 10 |
+
#
|
| 11 |
+
# IfcOpenShell is distributed in the hope that it will be useful,
|
| 12 |
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 13 |
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 14 |
+
# GNU Lesser General Public License for more details.
|
| 15 |
+
#
|
| 16 |
+
# You should have received a copy of the GNU Lesser General Public License
|
| 17 |
+
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
|
| 18 |
+
|
| 19 |
+
"""Contexts allow you to classify when geometry should be used in different
|
| 20 |
+
purposes
|
| 21 |
+
|
| 22 |
+
For example, a door may have many geometries assigned to it: a 3D body
|
| 23 |
+
geometry, a clearance zone for disabled access and egress, and a 2D top down
|
| 24 |
+
plan view representation annotating swing extents. Each geometry is assigned to
|
| 25 |
+
a context to distinguish its purpose and level of detail.
|
| 26 |
+
"""
|
| 27 |
+
|
| 28 |
+
from .. import wrap_usecases
|
| 29 |
+
from .add_context import add_context
|
| 30 |
+
from .edit_context import edit_context
|
| 31 |
+
from .remove_context import remove_context
|
| 32 |
+
|
| 33 |
+
wrap_usecases(__path__, __name__)
|
| 34 |
+
|
| 35 |
+
__all__ = [
|
| 36 |
+
"add_context",
|
| 37 |
+
"edit_context",
|
| 38 |
+
"remove_context",
|
| 39 |
+
]
|
data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/context/add_context.py
ADDED
|
@@ -0,0 +1,239 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# IfcOpenShell - IFC toolkit and geometry engine
|
| 2 |
+
# Copyright (C) 2021 Dion Moult <dion@thinkmoult.com>
|
| 3 |
+
#
|
| 4 |
+
# This file is part of IfcOpenShell.
|
| 5 |
+
#
|
| 6 |
+
# IfcOpenShell is free software: you can redistribute it and/or modify
|
| 7 |
+
# it under the terms of the GNU Lesser General Public License as published by
|
| 8 |
+
# the Free Software Foundation, either version 3 of the License, or
|
| 9 |
+
# (at your option) any later version.
|
| 10 |
+
#
|
| 11 |
+
# IfcOpenShell is distributed in the hope that it will be useful,
|
| 12 |
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 13 |
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 14 |
+
# GNU Lesser General Public License for more details.
|
| 15 |
+
#
|
| 16 |
+
# You should have received a copy of the GNU Lesser General Public License
|
| 17 |
+
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
|
| 18 |
+
|
| 19 |
+
import ifcopenshell
|
| 20 |
+
import ifcopenshell.util.representation
|
| 21 |
+
from typing import Optional, Any
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
def add_context(
|
| 25 |
+
file: ifcopenshell.file,
|
| 26 |
+
context_type: Optional[ifcopenshell.util.representation.CONTEXT_TYPE] = None,
|
| 27 |
+
context_identifier: Optional[ifcopenshell.util.representation.REPRESENTATION_IDENTIFIER] = None,
|
| 28 |
+
target_view: Optional[ifcopenshell.util.representation.TARGET_VIEW] = None,
|
| 29 |
+
target_scale: Optional[float] = None,
|
| 30 |
+
parent: Optional[ifcopenshell.entity_instance] = None,
|
| 31 |
+
) -> ifcopenshell.entity_instance:
|
| 32 |
+
"""Adds a new geometric representation context
|
| 33 |
+
|
| 34 |
+
In IFC, physical objects may have zero, one, or multiple geometric
|
| 35 |
+
representations associated with it. For example, a building storey might
|
| 36 |
+
not have any geometry, but simply be a coordinate in space.
|
| 37 |
+
Alternatively, a wall might have a 3D body representation in the form of
|
| 38 |
+
a cuboid. As a final example, a door might also have a 3D body
|
| 39 |
+
representation of a 3D door panel and door frame, but may additionally
|
| 40 |
+
have a 2D door plan view representation of the door swing, and even a 2D
|
| 41 |
+
elevation view of the door, a 3D box representing the disabled clearance
|
| 42 |
+
zone of the door, a 2D profile representing the profile of the door to
|
| 43 |
+
cut out in a wall, and so on. In this situation, a door will have
|
| 44 |
+
multiple geometric representations.
|
| 45 |
+
|
| 46 |
+
To distinguish between the different purposes of multiple geometric
|
| 47 |
+
representations, each geometric representation must belong to a
|
| 48 |
+
geometric representation "context". There are typically always 2
|
| 49 |
+
contexts, one for 3D representations and one for 2D representations.
|
| 50 |
+
These 2 contexts then have subcontexts for things like the 3D body
|
| 51 |
+
representation, clearance representations, annotation representations,
|
| 52 |
+
and so on. Each representation of a physical IFC product (e.g. a door)
|
| 53 |
+
must be assigned to one of these subcontexts. Therefore setting up
|
| 54 |
+
appropriate contexts is critical prior to authoring any IFC model which
|
| 55 |
+
contains geometry.
|
| 56 |
+
|
| 57 |
+
There are two steps to setting up appropriate subcontexts. First, a 2D
|
| 58 |
+
and/or 3D context must be added. These must be always called the "Model"
|
| 59 |
+
context for 3D and the "Plan" context for 2D (even if the 2D geometry is
|
| 60 |
+
not a plan view). Then, one or more subcontexts are added using either
|
| 61 |
+
the "Model" or "Plan" as their parent. These subcontexts are further
|
| 62 |
+
distinguished using an "identifier" and "target view". The "identifier"
|
| 63 |
+
describes the purpose of the representation, and the "target view"
|
| 64 |
+
describes the typical diagrammatic presentation that context's geometry
|
| 65 |
+
should be viewed in. The most common identifiers you might use are:
|
| 66 |
+
|
| 67 |
+
- Body: for the actual shape of the object
|
| 68 |
+
- Box: the bounding box of the object (useful for shape analytics)
|
| 69 |
+
- Axis: the parametric line determining the shape of the object
|
| 70 |
+
- Profile: the elevation silhouette of the object, useful for cutting
|
| 71 |
+
out holes for the object to fit into host elements
|
| 72 |
+
- Footprint: the plan view silhouette of the object, useful for certain
|
| 73 |
+
quantity take-off rules
|
| 74 |
+
- Clearance: the clearance zone of the object
|
| 75 |
+
- Annotation: symbolic annotations typically used in diagrams or
|
| 76 |
+
drawings
|
| 77 |
+
|
| 78 |
+
The most common "target views" you might use are:
|
| 79 |
+
|
| 80 |
+
- MODEL_VIEW: for 3D geometry you might see in a BIM viewer
|
| 81 |
+
- PLAN_VIEW: for 2D geometry you might see in a plan representation
|
| 82 |
+
- ELEVATION_VIEW: for 2D geometry you might see in an elevation representation
|
| 83 |
+
- SECTION_VIEW: for 2D geometry you might see in a section representation
|
| 84 |
+
- GRAPH_VIEW: for 2D or 3D line or frame or path connectivity diagrams
|
| 85 |
+
you might use for structural frame analysis, axis-based parametric
|
| 86 |
+
modeling
|
| 87 |
+
- SKETCH_VIEW: for viewing abstract high-level representations such as
|
| 88 |
+
in bubble diagrams of spatial topology
|
| 89 |
+
|
| 90 |
+
This may sound like a lot, but after a few typical contexts are set up
|
| 91 |
+
at the beginning, it becomes easy to navigate and isolate geometry for
|
| 92 |
+
different purposes. There is also the concept of a target scale, which
|
| 93 |
+
represents the zoom level detail of geometry, but this is not currently
|
| 94 |
+
supported by this API. Setting up all these contexts are also optional,
|
| 95 |
+
and you may only use a single Model context and Body subcontext for
|
| 96 |
+
simple models, but this simplification sacrifices the ability of more
|
| 97 |
+
parametric or analytical usecases.
|
| 98 |
+
|
| 99 |
+
:param context_type: The type of the context, must be one of "Model" or
|
| 100 |
+
"Plan" only.
|
| 101 |
+
:param context_identifier: The identifier of the context, chosen from
|
| 102 |
+
one of the common identifiers above or consult the IFC documentation
|
| 103 |
+
(under the IfcShapeRepresentation page) for more details. Optional
|
| 104 |
+
for contexts, but mandatory for subcontexts.
|
| 105 |
+
:param target_view: the target view of the context, chosen from one of
|
| 106 |
+
the common target views above or consult the IFC documentation
|
| 107 |
+
(under the IfcShapeRepresentation page) for more details. Optional
|
| 108 |
+
for contexts, but mandatory for subcontexts.
|
| 109 |
+
:param target_scale: It defines the intended scale at which the representation
|
| 110 |
+
is designed to be viewed or printed
|
| 111 |
+
:param parent: the parent context. Must be left as None (the default)
|
| 112 |
+
for contexts, and only set for subcontexts. Note that there are only
|
| 113 |
+
contexts and subcontexts, a subcontext cannot have any children.
|
| 114 |
+
:return: the newly created IfcGeometricRepresentationContext or
|
| 115 |
+
IfcGeometricRepresentationSubContext entity
|
| 116 |
+
|
| 117 |
+
Example:
|
| 118 |
+
|
| 119 |
+
.. code:: python
|
| 120 |
+
|
| 121 |
+
# If we plan to store 3D geometry in our IFC model, we have to setup
|
| 122 |
+
# a "Model" context.
|
| 123 |
+
model3d = ifcopenshell.api.context.add_context(model, context_type="Model")
|
| 124 |
+
|
| 125 |
+
# And/Or, if we plan to store 2D geometry, we need a "Plan" context
|
| 126 |
+
plan = ifcopenshell.api.context.add_context(model, context_type="Plan")
|
| 127 |
+
|
| 128 |
+
# Now we setup the subcontexts with each of the geometric "purposes"
|
| 129 |
+
# we plan to store in our model. "Body" is by far the most important
|
| 130 |
+
# and common context, as most IFC models are assumed to be viewable
|
| 131 |
+
# in 3D.
|
| 132 |
+
body = ifcopenshell.api.context.add_context(model,
|
| 133 |
+
context_type="Model", context_identifier="Body", target_view="MODEL_VIEW", parent=model3d)
|
| 134 |
+
|
| 135 |
+
# The 3D Axis subcontext is important if any "axis-based" parametric
|
| 136 |
+
# geometry is going to be created. For example, a beam, or column
|
| 137 |
+
# may be drawn using a single 3D axis line, and for this we need an
|
| 138 |
+
# Axis subcontext.
|
| 139 |
+
ifcopenshell.api.context.add_context(model,
|
| 140 |
+
context_type="Model", context_identifier="Axis", target_view="GRAPH_VIEW", parent=model3d)
|
| 141 |
+
|
| 142 |
+
# The 3D Box subcontext is useful for clash detection or shape
|
| 143 |
+
# analysis, or even lazy-loading of large models.
|
| 144 |
+
ifcopenshell.api.context.add_context(model,
|
| 145 |
+
context_type="Model", context_identifier="Box", target_view="MODEL_VIEW", parent=model3d)
|
| 146 |
+
|
| 147 |
+
# It's also important to have a 2D Axis subcontext for things like
|
| 148 |
+
# walls and claddings which can be drawn using a 2D axis line.
|
| 149 |
+
ifcopenshell.api.context.add_context(model,
|
| 150 |
+
context_type="Plan", context_identifier="Axis", target_view="GRAPH_VIEW", parent=plan)
|
| 151 |
+
|
| 152 |
+
# A 2D annotation subcontext for plan views are important for door
|
| 153 |
+
# swings, window cuts, and symbols for equipment like GPOs, fire
|
| 154 |
+
# extinguishers, and so on.
|
| 155 |
+
ifcopenshell.api.context.add_context(model,
|
| 156 |
+
context_type="Plan", context_identifier="Annotation", target_view="PLAN_VIEW", parent=plan)
|
| 157 |
+
|
| 158 |
+
# You may also create 2D annotation subcontexts for sections and
|
| 159 |
+
# elevation views.
|
| 160 |
+
ifcopenshell.api.context.add_context(model,
|
| 161 |
+
context_type="Plan", context_identifier="Annotation", target_view="SECTION_VIEW", parent=plan)
|
| 162 |
+
ifcopenshell.api.context.add_context(model,
|
| 163 |
+
context_type="Plan", context_identifier="Annotation", target_view="ELEVATION_VIEW", parent=plan)
|
| 164 |
+
|
| 165 |
+
# Let's create a new wall. The wall does not have any geometry yet.
|
| 166 |
+
wall = ifcopenshell.api.root.create_entity(model, ifc_class="IfcWall")
|
| 167 |
+
|
| 168 |
+
# Let's use the "3D Body" representation we created earlier to add a
|
| 169 |
+
# new wall-like body geometry, 5 meters long, 3 meters high, and
|
| 170 |
+
# 200mm thick
|
| 171 |
+
representation = ifcopenshell.api.geometry.add_wall_representation(model,
|
| 172 |
+
context=body, length=5, height=3, thickness=0.2)
|
| 173 |
+
|
| 174 |
+
# Assign our new body geometry back to our wall
|
| 175 |
+
ifcopenshell.api.geometry.assign_representation(model,
|
| 176 |
+
product=wall, representation=representation)
|
| 177 |
+
|
| 178 |
+
# Place our wall at the origin
|
| 179 |
+
ifcopenshell.api.geometry.edit_object_placement(model, product=wall)
|
| 180 |
+
"""
|
| 181 |
+
usecase = Usecase()
|
| 182 |
+
usecase.file = file
|
| 183 |
+
usecase.settings = {
|
| 184 |
+
"context_type": context_type,
|
| 185 |
+
"parent": parent,
|
| 186 |
+
"context_identifier": context_identifier,
|
| 187 |
+
"target_view": target_view,
|
| 188 |
+
"target_scale": target_scale,
|
| 189 |
+
}
|
| 190 |
+
return usecase.execute()
|
| 191 |
+
|
| 192 |
+
|
| 193 |
+
class Usecase:
|
| 194 |
+
file: ifcopenshell.file
|
| 195 |
+
settings: dict[str, Any]
|
| 196 |
+
|
| 197 |
+
def execute(self):
|
| 198 |
+
if not self.settings["parent"]:
|
| 199 |
+
if self.settings["context_type"] == "Plan":
|
| 200 |
+
self.create_2d_origin()
|
| 201 |
+
context = self.file.createIfcGeometricRepresentationContext(None, "Plan", 2, 1.0e-05, self.origin)
|
| 202 |
+
else:
|
| 203 |
+
self.create_3d_origin()
|
| 204 |
+
context = self.file.createIfcGeometricRepresentationContext(
|
| 205 |
+
None, self.settings["context_type"], 3, 1.0e-05, self.origin
|
| 206 |
+
)
|
| 207 |
+
|
| 208 |
+
project = self.file.by_type("IfcProject")[0]
|
| 209 |
+
|
| 210 |
+
if project.RepresentationContexts:
|
| 211 |
+
contexts = list(project.RepresentationContexts)
|
| 212 |
+
else:
|
| 213 |
+
contexts = []
|
| 214 |
+
contexts.append(context)
|
| 215 |
+
project.RepresentationContexts = contexts
|
| 216 |
+
return context
|
| 217 |
+
return self.file.create_entity(
|
| 218 |
+
"IfcGeometricRepresentationSubContext",
|
| 219 |
+
**{
|
| 220 |
+
"ContextIdentifier": self.settings["context_identifier"],
|
| 221 |
+
"ContextType": self.settings["context_type"],
|
| 222 |
+
"ParentContext": self.settings["parent"],
|
| 223 |
+
"TargetView": self.settings["target_view"],
|
| 224 |
+
"TargetScale": self.settings["target_scale"],
|
| 225 |
+
}
|
| 226 |
+
)
|
| 227 |
+
|
| 228 |
+
def create_3d_origin(self):
|
| 229 |
+
self.origin = self.file.createIfcAxis2Placement3D(
|
| 230 |
+
self.file.createIfcCartesianPoint((0.0, 0.0, 0.0)),
|
| 231 |
+
self.file.createIfcDirection((0.0, 0.0, 1.0)),
|
| 232 |
+
self.file.createIfcDirection((1.0, 0.0, 0.0)),
|
| 233 |
+
)
|
| 234 |
+
|
| 235 |
+
def create_2d_origin(self):
|
| 236 |
+
self.origin = self.file.createIfcAxis2Placement2D(
|
| 237 |
+
self.file.createIfcCartesianPoint((0.0, 0.0)),
|
| 238 |
+
self.file.createIfcDirection((1.0, 0.0)),
|
| 239 |
+
)
|
data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/context/edit_context.py
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# IfcOpenShell - IFC toolkit and geometry engine
|
| 2 |
+
# Copyright (C) 2021 Dion Moult <dion@thinkmoult.com>
|
| 3 |
+
#
|
| 4 |
+
# This file is part of IfcOpenShell.
|
| 5 |
+
#
|
| 6 |
+
# IfcOpenShell is free software: you can redistribute it and/or modify
|
| 7 |
+
# it under the terms of the GNU Lesser General Public License as published by
|
| 8 |
+
# the Free Software Foundation, either version 3 of the License, or
|
| 9 |
+
# (at your option) any later version.
|
| 10 |
+
#
|
| 11 |
+
# IfcOpenShell is distributed in the hope that it will be useful,
|
| 12 |
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 13 |
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 14 |
+
# GNU Lesser General Public License for more details.
|
| 15 |
+
#
|
| 16 |
+
# You should have received a copy of the GNU Lesser General Public License
|
| 17 |
+
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
|
| 18 |
+
|
| 19 |
+
import ifcopenshell
|
| 20 |
+
from typing import Any
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
def edit_context(file: ifcopenshell.file, context: ifcopenshell.entity_instance, attributes: dict[str, Any]) -> None:
|
| 24 |
+
"""Edits the attributes of an IfcGeometricRepresentationContext
|
| 25 |
+
|
| 26 |
+
For more information about the attributes and data types of an
|
| 27 |
+
IfcGeometricRepresentationContext, consult the IFC documentation.
|
| 28 |
+
|
| 29 |
+
:param context: The IfcGeometricRepresentationContext entity you want to edit
|
| 30 |
+
:param attributes: a dictionary of attribute names and values.
|
| 31 |
+
:return: None
|
| 32 |
+
|
| 33 |
+
Example:
|
| 34 |
+
|
| 35 |
+
.. code:: python
|
| 36 |
+
|
| 37 |
+
model = ifcopenshell.api.context.add_context(model, context_type="Model")
|
| 38 |
+
# Revit had a bug where they incorrectly called the body representation a "Facetation"
|
| 39 |
+
body = ifcopenshell.api.context.add_context(model,
|
| 40 |
+
context_type="Model", context_identifier="Facetation", target_view="MODEL_VIEW", parent=model
|
| 41 |
+
)
|
| 42 |
+
|
| 43 |
+
# Let's fix it!
|
| 44 |
+
ifcopenshell.api.context.edit_context(model,
|
| 45 |
+
context=body, attributes={"ContextIdentifier": "Body"})
|
| 46 |
+
"""
|
| 47 |
+
for name, value in attributes.items():
|
| 48 |
+
setattr(context, name, value)
|
data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/context/remove_context.py
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# IfcOpenShell - IFC toolkit and geometry engine
|
| 2 |
+
# Copyright (C) 2021 Dion Moult <dion@thinkmoult.com>
|
| 3 |
+
#
|
| 4 |
+
# This file is part of IfcOpenShell.
|
| 5 |
+
#
|
| 6 |
+
# IfcOpenShell is free software: you can redistribute it and/or modify
|
| 7 |
+
# it under the terms of the GNU Lesser General Public License as published by
|
| 8 |
+
# the Free Software Foundation, either version 3 of the License, or
|
| 9 |
+
# (at your option) any later version.
|
| 10 |
+
#
|
| 11 |
+
# IfcOpenShell is distributed in the hope that it will be useful,
|
| 12 |
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 13 |
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 14 |
+
# GNU Lesser General Public License for more details.
|
| 15 |
+
#
|
| 16 |
+
# You should have received a copy of the GNU Lesser General Public License
|
| 17 |
+
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
|
| 18 |
+
|
| 19 |
+
import ifcopenshell
|
| 20 |
+
import ifcopenshell.api.context
|
| 21 |
+
import ifcopenshell.api.geometry
|
| 22 |
+
import ifcopenshell.util.element
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
def remove_context(file: ifcopenshell.file, context: ifcopenshell.entity_instance) -> None:
|
| 26 |
+
"""Removes an IfcGeometricRepresentationContext
|
| 27 |
+
|
| 28 |
+
Any representation geometry that is assigned to the context is also
|
| 29 |
+
removed. If a context is removed, then any subcontexts are also removed.
|
| 30 |
+
|
| 31 |
+
:param context: The IfcGeometricRepresentationContext entity to remove
|
| 32 |
+
:return: None
|
| 33 |
+
|
| 34 |
+
Example:
|
| 35 |
+
|
| 36 |
+
.. code:: python
|
| 37 |
+
|
| 38 |
+
model = ifcopenshell.api.context.add_context(model, context_type="Model")
|
| 39 |
+
# Revit had a bug where they incorrectly called the body representation a "Facetation"
|
| 40 |
+
body = ifcopenshell.api.context.add_context(model,
|
| 41 |
+
context_type="Model", context_identifier="Facetation", target_view="MODEL_VIEW", parent=model
|
| 42 |
+
)
|
| 43 |
+
|
| 44 |
+
# Let's just get rid of it completely
|
| 45 |
+
ifcopenshell.api.context.remove_context(model, context=body)
|
| 46 |
+
"""
|
| 47 |
+
for subcontext in context.HasSubContexts:
|
| 48 |
+
ifcopenshell.api.context.remove_context(file, context=subcontext)
|
| 49 |
+
|
| 50 |
+
if getattr(context, "ParentContext", None):
|
| 51 |
+
new = context.ParentContext
|
| 52 |
+
for inverse in file.get_inverse(context):
|
| 53 |
+
if inverse.is_a("IfcCoordinateOperation"):
|
| 54 |
+
inverse.SourceCRS = inverse.TargetCRS
|
| 55 |
+
ifcopenshell.util.element.remove_deep(file, inverse)
|
| 56 |
+
else:
|
| 57 |
+
ifcopenshell.util.element.replace_attribute(inverse, context, new)
|
| 58 |
+
file.remove(context)
|
| 59 |
+
else:
|
| 60 |
+
representations_in_context = context.RepresentationsInContext
|
| 61 |
+
file.remove(context)
|
| 62 |
+
for rep in representations_in_context:
|
| 63 |
+
for element in ifcopenshell.util.element.get_elements_by_representation(file, rep):
|
| 64 |
+
ifcopenshell.api.geometry.unassign_representation(file, product=element, representation=rep)
|
| 65 |
+
ifcopenshell.api.geometry.remove_representation(file, representation=rep)
|
data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/library/__init__.py
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# IfcOpenShell - IFC toolkit and geometry engine
|
| 2 |
+
# Copyright (C) 2022 Dion Moult <dion@thinkmoult.com>
|
| 3 |
+
#
|
| 4 |
+
# This file is part of IfcOpenShell.
|
| 5 |
+
#
|
| 6 |
+
# IfcOpenShell is free software: you can redistribute it and/or modify
|
| 7 |
+
# it under the terms of the GNU Lesser General Public License as published by
|
| 8 |
+
# the Free Software Foundation, either version 3 of the License, or
|
| 9 |
+
# (at your option) any later version.
|
| 10 |
+
#
|
| 11 |
+
# IfcOpenShell is distributed in the hope that it will be useful,
|
| 12 |
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 13 |
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 14 |
+
# GNU Lesser General Public License for more details.
|
| 15 |
+
#
|
| 16 |
+
# You should have received a copy of the GNU Lesser General Public License
|
| 17 |
+
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
|
| 18 |
+
|
| 19 |
+
"""Manage references to external libraries
|
| 20 |
+
|
| 21 |
+
An external library is any system which uses a key to store information. This
|
| 22 |
+
allows you to associate IFC entities with any arbitrary external database, API,
|
| 23 |
+
system, and so on. This is typically useful in smart building systems.
|
| 24 |
+
"""
|
| 25 |
+
|
| 26 |
+
from .. import wrap_usecases
|
| 27 |
+
from .add_library import add_library
|
| 28 |
+
from .add_reference import add_reference
|
| 29 |
+
from .assign_reference import assign_reference
|
| 30 |
+
from .edit_library import edit_library
|
| 31 |
+
from .edit_reference import edit_reference
|
| 32 |
+
from .remove_library import remove_library
|
| 33 |
+
from .remove_reference import remove_reference
|
| 34 |
+
from .unassign_reference import unassign_reference
|
| 35 |
+
|
| 36 |
+
wrap_usecases(__path__, __name__)
|
| 37 |
+
|
| 38 |
+
__all__ = [
|
| 39 |
+
"add_library",
|
| 40 |
+
"add_reference",
|
| 41 |
+
"assign_reference",
|
| 42 |
+
"edit_library",
|
| 43 |
+
"edit_reference",
|
| 44 |
+
"remove_library",
|
| 45 |
+
"remove_reference",
|
| 46 |
+
"unassign_reference",
|
| 47 |
+
]
|
data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/library/add_library.py
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# IfcOpenShell - IFC toolkit and geometry engine
|
| 2 |
+
# Copyright (C) 2021 Dion Moult <dion@thinkmoult.com>
|
| 3 |
+
#
|
| 4 |
+
# This file is part of IfcOpenShell.
|
| 5 |
+
#
|
| 6 |
+
# IfcOpenShell is free software: you can redistribute it and/or modify
|
| 7 |
+
# it under the terms of the GNU Lesser General Public License as published by
|
| 8 |
+
# the Free Software Foundation, either version 3 of the License, or
|
| 9 |
+
# (at your option) any later version.
|
| 10 |
+
#
|
| 11 |
+
# IfcOpenShell is distributed in the hope that it will be useful,
|
| 12 |
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 13 |
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 14 |
+
# GNU Lesser General Public License for more details.
|
| 15 |
+
#
|
| 16 |
+
# You should have received a copy of the GNU Lesser General Public License
|
| 17 |
+
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
|
| 18 |
+
|
| 19 |
+
import ifcopenshell
|
| 20 |
+
import ifcopenshell.util.schema
|
| 21 |
+
import ifcopenshell.util.date
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
def add_library(file: ifcopenshell.file, name: str) -> ifcopenshell.entity_instance:
|
| 25 |
+
"""Adds a new library to the project
|
| 26 |
+
|
| 27 |
+
A library is an external data source that is related to the project. It
|
| 28 |
+
may be a database, a spreadsheet, an API, or even a stack of papers in a
|
| 29 |
+
filing cabinet. This allows IFC data to store relationships to these
|
| 30 |
+
external data sources.
|
| 31 |
+
|
| 32 |
+
For example, you may have a list of laser scans of a site stored in an
|
| 33 |
+
online platform, which can be queried using an API. Or, you might have a
|
| 34 |
+
database of live building sensor data. So long as there is a clear
|
| 35 |
+
identifier you can use to link the two datasets together, you can create
|
| 36 |
+
a relationship.
|
| 37 |
+
|
| 38 |
+
Note that IFC does not store any instructions on how to access the
|
| 39 |
+
library. It does not specify whether a HTTP request or database
|
| 40 |
+
connection needs to be made or what protocol the library operates with.
|
| 41 |
+
Until this is fleshed out further, it is the users responsibility to
|
| 42 |
+
name the libraries consistently and use appropriate identifiers. For
|
| 43 |
+
example, if you are linking IFC data and Brickschema data, use a full
|
| 44 |
+
URI for the identifier with no abbreviation (e.g.
|
| 45 |
+
'http://example.org/digitaltwin#AHU01', not 'digitaltwin:AHU01').
|
| 46 |
+
|
| 47 |
+
A library will then contain a list of references within that library.
|
| 48 |
+
These references will then be related to IFC elements. For example, a
|
| 49 |
+
library will represent an external database, and a reference will point
|
| 50 |
+
to a particular table and row within that database.
|
| 51 |
+
|
| 52 |
+
:param name: The name of the library
|
| 53 |
+
:return: The newly created IfcLibraryInformation
|
| 54 |
+
|
| 55 |
+
Example:
|
| 56 |
+
|
| 57 |
+
.. code:: python
|
| 58 |
+
|
| 59 |
+
ifcopenshell.api.library.add_library(model, name="Brickschema")
|
| 60 |
+
"""
|
| 61 |
+
return file.create_entity("IfcLibraryInformation", Name=name)
|
data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/library/add_reference.py
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# IfcOpenShell - IFC toolkit and geometry engine
|
| 2 |
+
# Copyright (C) 2021 Dion Moult <dion@thinkmoult.com>
|
| 3 |
+
#
|
| 4 |
+
# This file is part of IfcOpenShell.
|
| 5 |
+
#
|
| 6 |
+
# IfcOpenShell is free software: you can redistribute it and/or modify
|
| 7 |
+
# it under the terms of the GNU Lesser General Public License as published by
|
| 8 |
+
# the Free Software Foundation, either version 3 of the License, or
|
| 9 |
+
# (at your option) any later version.
|
| 10 |
+
#
|
| 11 |
+
# IfcOpenShell is distributed in the hope that it will be useful,
|
| 12 |
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 13 |
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 14 |
+
# GNU Lesser General Public License for more details.
|
| 15 |
+
#
|
| 16 |
+
# You should have received a copy of the GNU Lesser General Public License
|
| 17 |
+
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
|
| 18 |
+
|
| 19 |
+
import ifcopenshell
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
def add_reference(file: ifcopenshell.file, library: ifcopenshell.entity_instance) -> ifcopenshell.entity_instance:
|
| 23 |
+
"""Adds a new reference to a library
|
| 24 |
+
|
| 25 |
+
A library represents an external data source, such as a database,
|
| 26 |
+
spreadsheet, API, or something else that contains information related to
|
| 27 |
+
the IFC project. Within a library, there will be one or more references,
|
| 28 |
+
such as reference to a particular table or row in a database, or a sheet
|
| 29 |
+
and row or column in a spreadsheet, a URI in a linked data Brickschema
|
| 30 |
+
file, 32-bit decimal BACnetObjectIdentifier in a BACnet system, IP
|
| 31 |
+
address in a network, and so on.
|
| 32 |
+
|
| 33 |
+
These references can then be related to IFC elements. You cannot relate
|
| 34 |
+
an IFC element directly to a library, it must be related to one of the
|
| 35 |
+
library's references.
|
| 36 |
+
|
| 37 |
+
:param library: The IfcLibraryInformation element to add a reference to
|
| 38 |
+
:return: The newly created IfcLibraryReference element
|
| 39 |
+
|
| 40 |
+
Example:
|
| 41 |
+
|
| 42 |
+
.. code:: python
|
| 43 |
+
|
| 44 |
+
library = ifcopenshell.api.library.add_library(model, name="Brickschema")
|
| 45 |
+
|
| 46 |
+
# Let's create a reference to a single AHU in our Brickschema dataset
|
| 47 |
+
reference = ifcopenshell.api.library.add_reference(model, library=library)
|
| 48 |
+
ifcopenshell.api.library.edit_reference(model,
|
| 49 |
+
reference=reference, attributes={"Identification": "http://example.org/digitaltwin#AHU01"})
|
| 50 |
+
"""
|
| 51 |
+
if file.schema == "IFC2X3":
|
| 52 |
+
reference = file.createIfcLibraryReference()
|
| 53 |
+
references = list(library.LibraryReference or [])
|
| 54 |
+
references.append(reference)
|
| 55 |
+
library.LibraryReference = references
|
| 56 |
+
return reference
|
| 57 |
+
return file.createIfcLibraryReference(ReferencedLibrary=library)
|
data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/library/assign_reference.py
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# IfcOpenShell - IFC toolkit and geometry engine
|
| 2 |
+
# Copyright (C) 2021 Dion Moult <dion@thinkmoult.com>
|
| 3 |
+
#
|
| 4 |
+
# This file is part of IfcOpenShell.
|
| 5 |
+
#
|
| 6 |
+
# IfcOpenShell is free software: you can redistribute it and/or modify
|
| 7 |
+
# it under the terms of the GNU Lesser General Public License as published by
|
| 8 |
+
# the Free Software Foundation, either version 3 of the License, or
|
| 9 |
+
# (at your option) any later version.
|
| 10 |
+
#
|
| 11 |
+
# IfcOpenShell is distributed in the hope that it will be useful,
|
| 12 |
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 13 |
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 14 |
+
# GNU Lesser General Public License for more details.
|
| 15 |
+
#
|
| 16 |
+
# You should have received a copy of the GNU Lesser General Public License
|
| 17 |
+
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
|
| 18 |
+
|
| 19 |
+
import ifcopenshell
|
| 20 |
+
import ifcopenshell.api.owner
|
| 21 |
+
import ifcopenshell.guid
|
| 22 |
+
import ifcopenshell.util.element
|
| 23 |
+
from typing import Union
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
def assign_reference(
|
| 27 |
+
file: ifcopenshell.file, products: ifcopenshell.entity_instance, reference: ifcopenshell.entity_instance
|
| 28 |
+
) -> Union[ifcopenshell.entity_instance, None]:
|
| 29 |
+
"""Associates a list products with a library reference
|
| 30 |
+
|
| 31 |
+
A product may be associated with zero, one, or many references across
|
| 32 |
+
multiple libraries. See ifcopenshell.api.library.add_reference for more
|
| 33 |
+
detail about how references work.
|
| 34 |
+
|
| 35 |
+
:param products: The list of IfcProducts you want to associate with the reference
|
| 36 |
+
:param reference: The IfcLibraryReference you want the product to be
|
| 37 |
+
associated with.
|
| 38 |
+
:return: The IfcRelAssociatesLibrary relationship entity
|
| 39 |
+
or `None` if `products` was an empty list or all products were
|
| 40 |
+
already assigned to the `reference`.
|
| 41 |
+
|
| 42 |
+
Example:
|
| 43 |
+
|
| 44 |
+
.. code:: python
|
| 45 |
+
|
| 46 |
+
library = ifcopenshell.api.library.add_library(model, name="Brickschema")
|
| 47 |
+
|
| 48 |
+
# Let's create a reference to a single AHU in our Brickschema dataset
|
| 49 |
+
reference = ifcopenshell.api.library.add_reference(model, library=library)
|
| 50 |
+
ifcopenshell.api.library.edit_reference(model,
|
| 51 |
+
reference=reference, attributes={"Identification": "http://example.org/digitaltwin#AHU01"})
|
| 52 |
+
|
| 53 |
+
# Let's assume we have an AHU in our model.
|
| 54 |
+
ahu = ifcopenshell.api.root.create_entity(model,
|
| 55 |
+
ifc_class="IfcUnitaryEquipment", predefined_type="AIRHANDLER")
|
| 56 |
+
|
| 57 |
+
# And now assign the IFC model's AHU with its Brickschema counterpart
|
| 58 |
+
ifcopenshell.api.library.assign_reference(model, reference=reference, products=[ahu])
|
| 59 |
+
"""
|
| 60 |
+
# TODO: do we need to support non-ifcroot elements like we do in classification.add_reference?
|
| 61 |
+
|
| 62 |
+
referenced_elements = ifcopenshell.util.element.get_referenced_elements(reference)
|
| 63 |
+
products_set: set[ifcopenshell.entity_instance] = set(products)
|
| 64 |
+
products_set = products_set - referenced_elements
|
| 65 |
+
|
| 66 |
+
if not products_set:
|
| 67 |
+
return
|
| 68 |
+
|
| 69 |
+
if file.schema == "IFC2X3":
|
| 70 |
+
rel = next(
|
| 71 |
+
(r for r in file.by_type("IfcRelAssociatesLibrary") if r.RelatingLibrary == reference),
|
| 72 |
+
None,
|
| 73 |
+
)
|
| 74 |
+
else:
|
| 75 |
+
rel = next(iter(reference.LibraryRefForObjects), None)
|
| 76 |
+
|
| 77 |
+
if not rel:
|
| 78 |
+
return file.create_entity(
|
| 79 |
+
"IfcRelAssociatesLibrary",
|
| 80 |
+
GlobalId=ifcopenshell.guid.new(),
|
| 81 |
+
OwnerHistory=ifcopenshell.api.owner.create_owner_history(file),
|
| 82 |
+
RelatedObjects=list(products_set),
|
| 83 |
+
RelatingLibrary=reference,
|
| 84 |
+
)
|
| 85 |
+
|
| 86 |
+
related_objects = set(rel.RelatedObjects) | products_set
|
| 87 |
+
rel.RelatedObjects = list(related_objects)
|
| 88 |
+
ifcopenshell.api.owner.update_owner_history(file, element=rel)
|
| 89 |
+
return rel
|
data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/library/edit_library.py
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# IfcOpenShell - IFC toolkit and geometry engine
|
| 2 |
+
# Copyright (C) 2021 Dion Moult <dion@thinkmoult.com>
|
| 3 |
+
#
|
| 4 |
+
# This file is part of IfcOpenShell.
|
| 5 |
+
#
|
| 6 |
+
# IfcOpenShell is free software: you can redistribute it and/or modify
|
| 7 |
+
# it under the terms of the GNU Lesser General Public License as published by
|
| 8 |
+
# the Free Software Foundation, either version 3 of the License, or
|
| 9 |
+
# (at your option) any later version.
|
| 10 |
+
#
|
| 11 |
+
# IfcOpenShell is distributed in the hope that it will be useful,
|
| 12 |
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 13 |
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 14 |
+
# GNU Lesser General Public License for more details.
|
| 15 |
+
#
|
| 16 |
+
# You should have received a copy of the GNU Lesser General Public License
|
| 17 |
+
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
|
| 18 |
+
import ifcopenshell
|
| 19 |
+
import ifcopenshell.util.date
|
| 20 |
+
import datetime
|
| 21 |
+
from typing import Any
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
def edit_library(file: ifcopenshell.file, library: ifcopenshell.entity_instance, attributes: dict[str, Any]) -> None:
|
| 25 |
+
"""Edits the attributes of an IfcLibraryInformation
|
| 26 |
+
|
| 27 |
+
For more information about the attributes and data types of an
|
| 28 |
+
IfcLibraryInformation, consult the IFC documentation.
|
| 29 |
+
|
| 30 |
+
:param library: The IfcLibraryInformation entity you want to edit
|
| 31 |
+
:param attributes: a dictionary of attribute names and values.
|
| 32 |
+
:return: None
|
| 33 |
+
|
| 34 |
+
Example:
|
| 35 |
+
|
| 36 |
+
.. code:: python
|
| 37 |
+
|
| 38 |
+
library = ifcopenshell.api.library.add_library(model, name="Brickschema")
|
| 39 |
+
ifcopenshell.api.library.edit_library(model, library=library,
|
| 40 |
+
attributes={"Description": "A Brickschema TTL including only mechanical distribution systems."})
|
| 41 |
+
"""
|
| 42 |
+
|
| 43 |
+
if "VersionDate" in attributes:
|
| 44 |
+
dt = attributes["VersionDate"]
|
| 45 |
+
if isinstance(dt, datetime.datetime):
|
| 46 |
+
if file.schema != "IFC2X3":
|
| 47 |
+
dt = ifcopenshell.util.date.datetime2ifc(dt, "IfcDateTime")
|
| 48 |
+
else:
|
| 49 |
+
calendar_date = ifcopenshell.util.date.datetime2ifc(dt, "IfcCalendarDate")
|
| 50 |
+
dt = file.create_entity("IfcCalendarDate", **calendar_date)
|
| 51 |
+
attributes = attributes.copy()
|
| 52 |
+
attributes["VersionDate"] = dt
|
| 53 |
+
|
| 54 |
+
for name, value in attributes.items():
|
| 55 |
+
setattr(library, name, value)
|
data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/library/edit_reference.py
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# IfcOpenShell - IFC toolkit and geometry engine
|
| 2 |
+
# Copyright (C) 2021 Dion Moult <dion@thinkmoult.com>
|
| 3 |
+
#
|
| 4 |
+
# This file is part of IfcOpenShell.
|
| 5 |
+
#
|
| 6 |
+
# IfcOpenShell is free software: you can redistribute it and/or modify
|
| 7 |
+
# it under the terms of the GNU Lesser General Public License as published by
|
| 8 |
+
# the Free Software Foundation, either version 3 of the License, or
|
| 9 |
+
# (at your option) any later version.
|
| 10 |
+
#
|
| 11 |
+
# IfcOpenShell is distributed in the hope that it will be useful,
|
| 12 |
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 13 |
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 14 |
+
# GNU Lesser General Public License for more details.
|
| 15 |
+
#
|
| 16 |
+
# You should have received a copy of the GNU Lesser General Public License
|
| 17 |
+
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
|
| 18 |
+
import ifcopenshell
|
| 19 |
+
from typing import Any
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
def edit_reference(
|
| 23 |
+
file: ifcopenshell.file, reference: ifcopenshell.entity_instance, attributes: dict[str, Any]
|
| 24 |
+
) -> None:
|
| 25 |
+
"""Edits the attributes of an IfcLibraryReference
|
| 26 |
+
|
| 27 |
+
For more information about the attributes and data types of an
|
| 28 |
+
IfcLibraryReference, consult the IFC documentation.
|
| 29 |
+
|
| 30 |
+
:param reference: The IfcLibraryReference entity you want to edit
|
| 31 |
+
:param attributes: a dictionary of attribute names and values.
|
| 32 |
+
:return: None
|
| 33 |
+
|
| 34 |
+
Example:
|
| 35 |
+
|
| 36 |
+
.. code:: python
|
| 37 |
+
|
| 38 |
+
library = ifcopenshell.api.library.add_library(model, name="Brickschema")
|
| 39 |
+
# Let's create a reference to a single AHU in our Brickschema dataset
|
| 40 |
+
reference = ifcopenshell.api.library.add_reference(model, library=library)
|
| 41 |
+
ifcopenshell.api.library.edit_reference(model,
|
| 42 |
+
reference=reference, attributes={"Identification": "http://example.org/digitaltwin#AHU01"})
|
| 43 |
+
"""
|
| 44 |
+
for name, value in attributes.items():
|
| 45 |
+
setattr(reference, name, value)
|
data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/library/remove_library.py
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# IfcOpenShell - IFC toolkit and geometry engine
|
| 2 |
+
# Copyright (C) 2021 Dion Moult <dion@thinkmoult.com>
|
| 3 |
+
#
|
| 4 |
+
# This file is part of IfcOpenShell.
|
| 5 |
+
#
|
| 6 |
+
# IfcOpenShell is free software: you can redistribute it and/or modify
|
| 7 |
+
# it under the terms of the GNU Lesser General Public License as published by
|
| 8 |
+
# the Free Software Foundation, either version 3 of the License, or
|
| 9 |
+
# (at your option) any later version.
|
| 10 |
+
#
|
| 11 |
+
# IfcOpenShell is distributed in the hope that it will be useful,
|
| 12 |
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 13 |
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 14 |
+
# GNU Lesser General Public License for more details.
|
| 15 |
+
#
|
| 16 |
+
# You should have received a copy of the GNU Lesser General Public License
|
| 17 |
+
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
|
| 18 |
+
|
| 19 |
+
import ifcopenshell
|
| 20 |
+
import ifcopenshell.util.element
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
def remove_library(file: ifcopenshell.file, library: ifcopenshell.entity_instance) -> None:
|
| 24 |
+
"""Removes a library
|
| 25 |
+
|
| 26 |
+
All references along with their relationships will also be removed. Any
|
| 27 |
+
products which have relationships to this library will not be removed.
|
| 28 |
+
|
| 29 |
+
:param library: The IfcLibraryInformation entity you want to remove
|
| 30 |
+
:return: None
|
| 31 |
+
|
| 32 |
+
Example:
|
| 33 |
+
|
| 34 |
+
.. code:: python
|
| 35 |
+
|
| 36 |
+
library = ifcopenshell.api.library.add_library(model, name="Brickschema")
|
| 37 |
+
ifcopenshell.api.library.remove_library(model, library=library)
|
| 38 |
+
"""
|
| 39 |
+
|
| 40 |
+
if file.schema != "IFC2X3":
|
| 41 |
+
rels = []
|
| 42 |
+
for reference in set(library.HasLibraryReferences):
|
| 43 |
+
rels.extend(reference.LibraryRefForObjects)
|
| 44 |
+
file.remove(reference)
|
| 45 |
+
rels.extend(library.LibraryInfoForObjects)
|
| 46 |
+
file.remove(library)
|
| 47 |
+
else:
|
| 48 |
+
for reference in set(library.LibraryReference or []):
|
| 49 |
+
file.remove(reference)
|
| 50 |
+
file.remove(library)
|
| 51 |
+
# RelatingLibrary could either be library itself or library reference we removed
|
| 52 |
+
rels = [rel for rel in file.by_type("IfcRelAssociatesLibrary") if rel.RelatingLibrary is None]
|
| 53 |
+
|
| 54 |
+
for rel in rels:
|
| 55 |
+
history = rel.OwnerHistory
|
| 56 |
+
file.remove(rel)
|
| 57 |
+
if history:
|
| 58 |
+
ifcopenshell.util.element.remove_deep2(file, history)
|
data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/library/remove_reference.py
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# IfcOpenShell - IFC toolkit and geometry engine
|
| 2 |
+
# Copyright (C) 2021 Dion Moult <dion@thinkmoult.com>
|
| 3 |
+
#
|
| 4 |
+
# This file is part of IfcOpenShell.
|
| 5 |
+
#
|
| 6 |
+
# IfcOpenShell is free software: you can redistribute it and/or modify
|
| 7 |
+
# it under the terms of the GNU Lesser General Public License as published by
|
| 8 |
+
# the Free Software Foundation, either version 3 of the License, or
|
| 9 |
+
# (at your option) any later version.
|
| 10 |
+
#
|
| 11 |
+
# IfcOpenShell is distributed in the hope that it will be useful,
|
| 12 |
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 13 |
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 14 |
+
# GNU Lesser General Public License for more details.
|
| 15 |
+
#
|
| 16 |
+
# You should have received a copy of the GNU Lesser General Public License
|
| 17 |
+
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
|
| 18 |
+
|
| 19 |
+
import ifcopenshell
|
| 20 |
+
import ifcopenshell.util.element
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
def remove_reference(file: ifcopenshell.file, reference: ifcopenshell.entity_instance) -> None:
|
| 24 |
+
"""Removes a library reference
|
| 25 |
+
|
| 26 |
+
Any products which have relationships to this reference will not be
|
| 27 |
+
removed.
|
| 28 |
+
|
| 29 |
+
:param reference: The IfcLibraryReference entity you want to remove
|
| 30 |
+
:return: None
|
| 31 |
+
|
| 32 |
+
Example:
|
| 33 |
+
|
| 34 |
+
.. code:: python
|
| 35 |
+
|
| 36 |
+
library = ifcopenshell.api.library.add_library(model, name="Brickschema")
|
| 37 |
+
reference = ifcopenshell.api.library.add_reference(model, library=library)
|
| 38 |
+
# Let's change our mind and remove it.
|
| 39 |
+
ifcopenshell.api.library.remove_reference(model, reference=reference)
|
| 40 |
+
"""
|
| 41 |
+
if file.schema != "IFC2X3":
|
| 42 |
+
rels = reference.LibraryRefForObjects
|
| 43 |
+
else:
|
| 44 |
+
rels = [rel for rel in file.by_type("IfcRelAssociatesLibrary") if rel.RelatingLibrary == reference]
|
| 45 |
+
|
| 46 |
+
for rel in rels:
|
| 47 |
+
history = rel.OwnerHistory
|
| 48 |
+
file.remove(rel)
|
| 49 |
+
if history:
|
| 50 |
+
ifcopenshell.util.element.remove_deep2(file, history)
|
| 51 |
+
file.remove(reference)
|
data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/library/unassign_reference.py
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# IfcOpenShell - IFC toolkit and geometry engine
|
| 2 |
+
# Copyright (C) 2021 Dion Moult <dion@thinkmoult.com>
|
| 3 |
+
#
|
| 4 |
+
# This file is part of IfcOpenShell.
|
| 5 |
+
#
|
| 6 |
+
# IfcOpenShell is free software: you can redistribute it and/or modify
|
| 7 |
+
# it under the terms of the GNU Lesser General Public License as published by
|
| 8 |
+
# the Free Software Foundation, either version 3 of the License, or
|
| 9 |
+
# (at your option) any later version.
|
| 10 |
+
#
|
| 11 |
+
# IfcOpenShell is distributed in the hope that it will be useful,
|
| 12 |
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 13 |
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 14 |
+
# GNU Lesser General Public License for more details.
|
| 15 |
+
#
|
| 16 |
+
# You should have received a copy of the GNU Lesser General Public License
|
| 17 |
+
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
|
| 18 |
+
|
| 19 |
+
import ifcopenshell
|
| 20 |
+
import ifcopenshell.util.element
|
| 21 |
+
import ifcopenshell.api.owner
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
def unassign_reference(
|
| 25 |
+
file: ifcopenshell.file,
|
| 26 |
+
reference: ifcopenshell.entity_instance,
|
| 27 |
+
products: list[ifcopenshell.entity_instance],
|
| 28 |
+
) -> None:
|
| 29 |
+
"""Unassigns a product of products from a reference
|
| 30 |
+
|
| 31 |
+
If the product isn't assigned to the reference, nothing will happen.
|
| 32 |
+
|
| 33 |
+
:param reference: The IfcLibraryReference to unassign from
|
| 34 |
+
:param products: A list of IfcProduct elements to unassign from the reference
|
| 35 |
+
:return: None
|
| 36 |
+
|
| 37 |
+
Example:
|
| 38 |
+
|
| 39 |
+
.. code:: python
|
| 40 |
+
|
| 41 |
+
library = ifcopenshell.api.library.add_library(model, name="Brickschema")
|
| 42 |
+
|
| 43 |
+
# Let's create a reference to a single AHU in our Brickschema dataset
|
| 44 |
+
reference = ifcopenshell.api.library.add_reference(model, library=library)
|
| 45 |
+
ifcopenshell.api.library.edit_reference(model,
|
| 46 |
+
reference=reference, attributes={"Identification": "http://example.org/digitaltwin#AHU01"})
|
| 47 |
+
|
| 48 |
+
# Let's assume we have an AHU in our model.
|
| 49 |
+
ahu = ifcopenshell.api.root.create_entity(model,
|
| 50 |
+
ifc_class="IfcUnitaryEquipment", predefined_type="AIRHANDLER")
|
| 51 |
+
|
| 52 |
+
# And now assign the IFC model's AHU with its Brickschema counterpart
|
| 53 |
+
ifcopenshell.api.library.assign_reference(model, reference=reference, products=[ahu])
|
| 54 |
+
|
| 55 |
+
# Let's change our mind and unassign it.
|
| 56 |
+
ifcopenshell.api.library.unassign_reference(model, reference=reference, products=[ahu])
|
| 57 |
+
"""
|
| 58 |
+
# TODO: do we need to support non-ifcroot elements like we do in classification.add_reference?
|
| 59 |
+
|
| 60 |
+
reference_rels: set[ifcopenshell.entity_instance] = set()
|
| 61 |
+
products_set = set(products)
|
| 62 |
+
for product in products_set:
|
| 63 |
+
reference_rels.update(product.HasAssociations)
|
| 64 |
+
|
| 65 |
+
reference_rels = {
|
| 66 |
+
rel for rel in reference_rels if rel.is_a("IfcRelAssociatesLibrary") and rel.RelatingLibrary == reference
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
for rel in reference_rels:
|
| 70 |
+
related_objects = set(rel.RelatedObjects) - products_set
|
| 71 |
+
if related_objects:
|
| 72 |
+
rel.RelatedObjects = list(related_objects)
|
| 73 |
+
ifcopenshell.api.owner.update_owner_history(file, element=rel)
|
| 74 |
+
else:
|
| 75 |
+
history = rel.OwnerHistory
|
| 76 |
+
file.remove(rel)
|
| 77 |
+
if history:
|
| 78 |
+
ifcopenshell.util.element.remove_deep2(file, history)
|
data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/material/__init__.py
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# IfcOpenShell - IFC toolkit and geometry engine
|
| 2 |
+
# Copyright (C) 2022 Dion Moult <dion@thinkmoult.com>
|
| 3 |
+
#
|
| 4 |
+
# This file is part of IfcOpenShell.
|
| 5 |
+
#
|
| 6 |
+
# IfcOpenShell is free software: you can redistribute it and/or modify
|
| 7 |
+
# it under the terms of the GNU Lesser General Public License as published by
|
| 8 |
+
# the Free Software Foundation, either version 3 of the License, or
|
| 9 |
+
# (at your option) any later version.
|
| 10 |
+
#
|
| 11 |
+
# IfcOpenShell is distributed in the hope that it will be useful,
|
| 12 |
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 13 |
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 14 |
+
# GNU Lesser General Public License for more details.
|
| 15 |
+
#
|
| 16 |
+
# You should have received a copy of the GNU Lesser General Public License
|
| 17 |
+
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
|
| 18 |
+
|
| 19 |
+
"""Manage physical materials (concrete, steel, etc) and their association to
|
| 20 |
+
elements
|
| 21 |
+
|
| 22 |
+
IFC supports both simple materials and parametric materials (materials that
|
| 23 |
+
have layered thicknesses or cross sectional profiles).
|
| 24 |
+
|
| 25 |
+
Parametric materials will include parametric constraints on the geometry of
|
| 26 |
+
the element. These API functions do not cover that responsibility. See
|
| 27 |
+
:mod:`ifcopenshell.api.geometry`.
|
| 28 |
+
|
| 29 |
+
Note that this API only covers physical materials, not visual styles. If you
|
| 30 |
+
want to look at visual styles such as colours, transparency, shading, or
|
| 31 |
+
rendering options, see :mod:`ifcopenshell.api.style`.
|
| 32 |
+
"""
|
| 33 |
+
|
| 34 |
+
from .. import wrap_usecases
|
| 35 |
+
from .add_constituent import add_constituent
|
| 36 |
+
from .add_layer import add_layer
|
| 37 |
+
from .add_list_item import add_list_item
|
| 38 |
+
from .add_material import add_material
|
| 39 |
+
from .add_material_set import add_material_set
|
| 40 |
+
from .add_profile import add_profile
|
| 41 |
+
from .assign_material import assign_material
|
| 42 |
+
from .assign_profile import assign_profile
|
| 43 |
+
from .copy_material import copy_material
|
| 44 |
+
from .edit_assigned_material import edit_assigned_material
|
| 45 |
+
from .edit_constituent import edit_constituent
|
| 46 |
+
from .edit_layer import edit_layer
|
| 47 |
+
from .edit_layer_usage import edit_layer_usage
|
| 48 |
+
from .edit_material import edit_material
|
| 49 |
+
from .edit_profile import edit_profile
|
| 50 |
+
from .edit_profile_usage import edit_profile_usage
|
| 51 |
+
from .remove_constituent import remove_constituent
|
| 52 |
+
from .remove_layer import remove_layer
|
| 53 |
+
from .remove_list_item import remove_list_item
|
| 54 |
+
from .remove_material import remove_material
|
| 55 |
+
from .remove_material_set import remove_material_set
|
| 56 |
+
from .remove_profile import remove_profile
|
| 57 |
+
from .reorder_set_item import reorder_set_item
|
| 58 |
+
from .set_shape_aspect_constituents import set_shape_aspect_constituents
|
| 59 |
+
from .unassign_material import unassign_material
|
| 60 |
+
|
| 61 |
+
wrap_usecases(__path__, __name__)
|
| 62 |
+
|
| 63 |
+
__all__ = [
|
| 64 |
+
"add_constituent",
|
| 65 |
+
"add_layer",
|
| 66 |
+
"add_list_item",
|
| 67 |
+
"add_material",
|
| 68 |
+
"add_material_set",
|
| 69 |
+
"add_profile",
|
| 70 |
+
"assign_material",
|
| 71 |
+
"assign_profile",
|
| 72 |
+
"copy_material",
|
| 73 |
+
"edit_assigned_material",
|
| 74 |
+
"edit_constituent",
|
| 75 |
+
"edit_layer",
|
| 76 |
+
"edit_layer_usage",
|
| 77 |
+
"edit_material",
|
| 78 |
+
"edit_profile",
|
| 79 |
+
"edit_profile_usage",
|
| 80 |
+
"remove_constituent",
|
| 81 |
+
"remove_layer",
|
| 82 |
+
"remove_list_item",
|
| 83 |
+
"remove_material",
|
| 84 |
+
"remove_material_set",
|
| 85 |
+
"remove_profile",
|
| 86 |
+
"reorder_set_item",
|
| 87 |
+
"set_shape_aspect_constituents",
|
| 88 |
+
"unassign_material",
|
| 89 |
+
]
|
data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/material/add_constituent.py
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# IfcOpenShell - IFC toolkit and geometry engine
|
| 2 |
+
# Copyright (C) 2021 Dion Moult <dion@thinkmoult.com>
|
| 3 |
+
#
|
| 4 |
+
# This file is part of IfcOpenShell.
|
| 5 |
+
#
|
| 6 |
+
# IfcOpenShell is free software: you can redistribute it and/or modify
|
| 7 |
+
# it under the terms of the GNU Lesser General Public License as published by
|
| 8 |
+
# the Free Software Foundation, either version 3 of the License, or
|
| 9 |
+
# (at your option) any later version.
|
| 10 |
+
#
|
| 11 |
+
# IfcOpenShell is distributed in the hope that it will be useful,
|
| 12 |
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 13 |
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 14 |
+
# GNU Lesser General Public License for more details.
|
| 15 |
+
#
|
| 16 |
+
# You should have received a copy of the GNU Lesser General Public License
|
| 17 |
+
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
|
| 18 |
+
import ifcopenshell
|
| 19 |
+
from typing import Optional
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
def add_constituent(
|
| 23 |
+
file: ifcopenshell.file,
|
| 24 |
+
constituent_set: ifcopenshell.entity_instance,
|
| 25 |
+
material: ifcopenshell.entity_instance,
|
| 26 |
+
name: Optional[str] = None,
|
| 27 |
+
) -> ifcopenshell.entity_instance:
|
| 28 |
+
"""Adds a new constituent to a constituent set
|
| 29 |
+
|
| 30 |
+
A constituent describes how a portion of an object is made out of a
|
| 31 |
+
material whereas other portions of the object is made out of other
|
| 32 |
+
materials. For example, a window might be made out of an aluminium frame
|
| 33 |
+
and a glass panel. The aluminium used for the frame is one constituent
|
| 34 |
+
of the material, and glass would be another constituent. Another example
|
| 35 |
+
might be concrete, where one constituent might be cement, and another
|
| 36 |
+
constituent might be binder. In the case of the window, the constituent
|
| 37 |
+
is represented explicitly by the geometry of the window frame and the
|
| 38 |
+
geometry of the window panel. In the case of a concrete slab, the
|
| 39 |
+
constituents might be represented in terms of percentages.
|
| 40 |
+
|
| 41 |
+
Constituents are not available in IFC2X3.
|
| 42 |
+
|
| 43 |
+
:param constituent_set: The IfcMaterialConstituentSet that the
|
| 44 |
+
constituent is part of. The constituent set represents a group of
|
| 45 |
+
constituents. See ifcopenshell.api.material.add_material_set for
|
| 46 |
+
information on how to add a constituent set.
|
| 47 |
+
:param material: The IfcMaterial that the constituent is made out of.
|
| 48 |
+
:param name: An optional name of the constituent.
|
| 49 |
+
:return: The newly created IfcMaterialConstituent
|
| 50 |
+
|
| 51 |
+
Example:
|
| 52 |
+
|
| 53 |
+
.. code:: python
|
| 54 |
+
|
| 55 |
+
# Let's imagine we have a window type that has an aluminium frame
|
| 56 |
+
# and a glass glazing panel. Notice we are assigning to the type
|
| 57 |
+
# only, as all occurrences of that type will automatically inherit
|
| 58 |
+
# the material.
|
| 59 |
+
window_type = ifcopenshell.api.root.create_entity(model, ifc_class="IfcWindowType")
|
| 60 |
+
|
| 61 |
+
# First, let's create a constituent set. This will later be assigned
|
| 62 |
+
# to our window element.
|
| 63 |
+
material_set = ifcopenshell.api.material.add_material_set(model,
|
| 64 |
+
name="Window", set_type="IfcMaterialConstituentSet")
|
| 65 |
+
|
| 66 |
+
# Let's create a few materials, it's important to also give them
|
| 67 |
+
# categories. This makes it easy for model recipients to do things
|
| 68 |
+
# like "show me everything made out of aluminium / concrete / steel
|
| 69 |
+
# / glass / etc". The IFC specification states a list of categories
|
| 70 |
+
# you can use.
|
| 71 |
+
aluminium = ifcopenshell.api.material.add_material(model, name="AL01", category="aluminium")
|
| 72 |
+
glass = ifcopenshell.api.material.add_material(model, name="GLZ01", category="glass")
|
| 73 |
+
|
| 74 |
+
# Now let's use those materials as two constituents in our set.
|
| 75 |
+
ifcopenshell.api.material.add_constituent(model,
|
| 76 |
+
constituent_set=material_set, material=aluminium, name="Framing")
|
| 77 |
+
ifcopenshell.api.material.add_constituent(model,
|
| 78 |
+
constituent_set=material_set, material=glass, name="Glazing")
|
| 79 |
+
|
| 80 |
+
# Great! Let's assign our material set to our window type.
|
| 81 |
+
# We're technically not done here, we might want to add geometry to
|
| 82 |
+
# our window too, but to keep this example simple, geometry is
|
| 83 |
+
# optional and it is enough to say that this window is made out of
|
| 84 |
+
# aluminium and glass.
|
| 85 |
+
ifcopenshell.api.material.assign_material(model, products=[window_type], material=material_set)
|
| 86 |
+
"""
|
| 87 |
+
constituents = list(constituent_set.MaterialConstituents or [])
|
| 88 |
+
constituent = file.create_entity("IfcMaterialConstituent", Material=material, Name=name)
|
| 89 |
+
constituents.append(constituent)
|
| 90 |
+
constituent_set.MaterialConstituents = constituents
|
| 91 |
+
return constituent
|
data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/material/add_material.py
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# IfcOpenShell - IFC toolkit and geometry engine
|
| 2 |
+
# Copyright (C) 2021 Dion Moult <dion@thinkmoult.com>
|
| 3 |
+
#
|
| 4 |
+
# This file is part of IfcOpenShell.
|
| 5 |
+
#
|
| 6 |
+
# IfcOpenShell is free software: you can redistribute it and/or modify
|
| 7 |
+
# it under the terms of the GNU Lesser General Public License as published by
|
| 8 |
+
# the Free Software Foundation, either version 3 of the License, or
|
| 9 |
+
# (at your option) any later version.
|
| 10 |
+
#
|
| 11 |
+
# IfcOpenShell is distributed in the hope that it will be useful,
|
| 12 |
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 13 |
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 14 |
+
# GNU Lesser General Public License for more details.
|
| 15 |
+
#
|
| 16 |
+
# You should have received a copy of the GNU Lesser General Public License
|
| 17 |
+
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
|
| 18 |
+
import ifcopenshell
|
| 19 |
+
from typing import Optional
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
def add_material(
|
| 23 |
+
file: ifcopenshell.file,
|
| 24 |
+
name: Optional[str] = None,
|
| 25 |
+
category: Optional[str] = None,
|
| 26 |
+
description: Optional[str] = None,
|
| 27 |
+
) -> ifcopenshell.entity_instance:
|
| 28 |
+
"""Adds a new material
|
| 29 |
+
|
| 30 |
+
A material in IFC represents a physical material, such as timber, steel,
|
| 31 |
+
concrete, aluminium, etc. It may also contain physical properties used
|
| 32 |
+
for structural or lighting simulation. Note that unlike the computer
|
| 33 |
+
graphics industry, a material by itself does not define any colour or
|
| 34 |
+
lighting information. Colours in IFC are known as "styles", and an IFC
|
| 35 |
+
material may or may not have any style information associated with it.
|
| 36 |
+
See ifcopenshell.api.style for more information.
|
| 37 |
+
|
| 38 |
+
A material is typically given a code name which is used by architects in
|
| 39 |
+
elevations and details when tagging finishes. Materials are also useful
|
| 40 |
+
to structural engineers in specifying the exact types of concrete and
|
| 41 |
+
steel to be used in structural simulations.
|
| 42 |
+
|
| 43 |
+
In addition, materials can belong to a category. Specifying this
|
| 44 |
+
category is critical to allow model recipients to make simple queries
|
| 45 |
+
like "show me all concrete / steel" elements in the model. Without
|
| 46 |
+
standardised category naming of all materials, this type of query
|
| 47 |
+
becomes a bespoke and inefficient task. A list of categories are:
|
| 48 |
+
'concrete', 'steel', 'aluminium', 'block', 'brick', 'stone', 'wood',
|
| 49 |
+
'glass', 'gypsum', 'plastic', and 'earth'. The user is allowed to
|
| 50 |
+
specify their own category instead if none of these categories are
|
| 51 |
+
appropriate.
|
| 52 |
+
|
| 53 |
+
Note that categories are not available in IFC2X3. This shortcoming is
|
| 54 |
+
one of the big reasons projects should upgrade to IFC4.
|
| 55 |
+
|
| 56 |
+
Additionally, a material's description provides more information beyond
|
| 57 |
+
its name or category.
|
| 58 |
+
|
| 59 |
+
:param name: The name of the material, typically tagged in a finishes
|
| 60 |
+
drawing or schedule.
|
| 61 |
+
:param category: The category of the material.
|
| 62 |
+
:param description: A description of the material.
|
| 63 |
+
:return: The newly created IfcMaterial
|
| 64 |
+
|
| 65 |
+
Example:
|
| 66 |
+
|
| 67 |
+
.. code:: python
|
| 68 |
+
|
| 69 |
+
# Let's create two materials with their respective categories
|
| 70 |
+
concrete = ifcopenshell.api.material.add_material(model, name="CON01", category="concrete", description="Garage Slab")
|
| 71 |
+
steel = ifcopenshell.api.material.add_material(model, name="ST01", category="steel", description="Corten Steel")
|
| 72 |
+
|
| 73 |
+
# Let's imagine an urban concrete bench which is purely made out of concrete
|
| 74 |
+
concrete_bench = ifcopenshell.api.root.create_entity(model, ifc_class="IfcFurnitureType")
|
| 75 |
+
|
| 76 |
+
# Assign the concrete material to that bench. Note that no colour
|
| 77 |
+
# "Style" has been specified.
|
| 78 |
+
ifcopenshell.api.material.assign_material(model, products=[concrete_bench], material=concrete)
|
| 79 |
+
"""
|
| 80 |
+
material = file.create_entity("IfcMaterial", **{"Name": name or "Unnamed"})
|
| 81 |
+
if category:
|
| 82 |
+
material.Category = category
|
| 83 |
+
if description:
|
| 84 |
+
material.Description = description
|
| 85 |
+
return material
|
data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/material/copy_material.py
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# IfcOpenShell - IFC toolkit and geometry engine
|
| 2 |
+
# Copyright (C) 2021 Dion Moult <dion@thinkmoult.com>
|
| 3 |
+
#
|
| 4 |
+
# This file is part of IfcOpenShell.
|
| 5 |
+
#
|
| 6 |
+
# IfcOpenShell is free software: you can redistribute it and/or modify
|
| 7 |
+
# it under the terms of the GNU Lesser General Public License as published by
|
| 8 |
+
# the Free Software Foundation, either version 3 of the License, or
|
| 9 |
+
# (at your option) any later version.
|
| 10 |
+
#
|
| 11 |
+
# IfcOpenShell is distributed in the hope that it will be useful,
|
| 12 |
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 13 |
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 14 |
+
# GNU Lesser General Public License for more details.
|
| 15 |
+
#
|
| 16 |
+
# You should have received a copy of the GNU Lesser General Public License
|
| 17 |
+
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
|
| 18 |
+
|
| 19 |
+
import ifcopenshell
|
| 20 |
+
import ifcopenshell.util.element
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
def copy_material(file: ifcopenshell.file, material: ifcopenshell.entity_instance) -> ifcopenshell.entity_instance:
|
| 24 |
+
"""Copies a material or material set
|
| 25 |
+
|
| 26 |
+
All material psets and styles are copied. The copied material is not
|
| 27 |
+
associated to any elements.
|
| 28 |
+
|
| 29 |
+
If a material set is copied, the set items are also copied. However the
|
| 30 |
+
underlying materials (and profiles) used within the set items are reused.
|
| 31 |
+
|
| 32 |
+
If a material is associated with a presentation style, that presentation
|
| 33 |
+
style is reused.
|
| 34 |
+
|
| 35 |
+
:param material: The IfcMaterialDefinition to copy
|
| 36 |
+
:return: The new copy of the material
|
| 37 |
+
|
| 38 |
+
Example:
|
| 39 |
+
|
| 40 |
+
.. code:: python
|
| 41 |
+
|
| 42 |
+
concrete = ifcopenshell.api.material.add_material(model, name="CON01", category="concrete")
|
| 43 |
+
|
| 44 |
+
# Let's duplicate the concrete material
|
| 45 |
+
concrete_copy = ifcopenshell.api.material.copy_material(model, material=concrete)
|
| 46 |
+
"""
|
| 47 |
+
if material.is_a("IfcMaterial"):
|
| 48 |
+
return _copy_material_with_inverses(file, material)
|
| 49 |
+
elif material.is_a("IfcMaterialConstituentSet"):
|
| 50 |
+
new = _copy_material_with_inverses(file, material)
|
| 51 |
+
new.MaterialConstituents = [copy_material(file, i) for i in material.MaterialConstituents]
|
| 52 |
+
return new
|
| 53 |
+
elif material.is_a("IfcMaterialConstituent"):
|
| 54 |
+
return _copy_material_with_inverses(file, material)
|
| 55 |
+
elif material.is_a("IfcMaterialLayerSet"):
|
| 56 |
+
new = _copy_material_with_inverses(file, material)
|
| 57 |
+
new.MaterialLayers = [copy_material(file, i) for i in material.MaterialLayers]
|
| 58 |
+
return new
|
| 59 |
+
elif material.is_a("IfcMaterialLayer"):
|
| 60 |
+
return _copy_material_with_inverses(file, material)
|
| 61 |
+
elif material.is_a("IfcMaterialProfileSet"):
|
| 62 |
+
new = _copy_material_with_inverses(file, material)
|
| 63 |
+
new.MaterialProfiles = [copy_material(file, i) for i in material.MaterialProfiles]
|
| 64 |
+
return new
|
| 65 |
+
elif material.is_a("IfcMaterialProfile"):
|
| 66 |
+
return _copy_material_with_inverses(file, material)
|
| 67 |
+
elif material.is_a("IfcMaterialList"):
|
| 68 |
+
return _copy_material_with_inverses(file, material)
|
| 69 |
+
else:
|
| 70 |
+
raise Exception(f"Unexpected material type: '{material.is_a()}' ({material}).")
|
| 71 |
+
|
| 72 |
+
|
| 73 |
+
def _copy_material_with_inverses(
|
| 74 |
+
file: ifcopenshell.file, material: ifcopenshell.entity_instance
|
| 75 |
+
) -> ifcopenshell.entity_instance:
|
| 76 |
+
new = ifcopenshell.util.element.copy(file, material)
|
| 77 |
+
for inverse in file.get_inverse(material):
|
| 78 |
+
if inverse.is_a("IfcMaterialProperties"):
|
| 79 |
+
# Properties must not be shared between objects for convenience of authoring
|
| 80 |
+
inverse = ifcopenshell.util.element.copy(file, inverse)
|
| 81 |
+
inverse.Material = new
|
| 82 |
+
|
| 83 |
+
props_attribute = "Properties"
|
| 84 |
+
if file.schema == "IFC2X3":
|
| 85 |
+
if not inverse.is_a("IfcExtendedMaterialProperties"):
|
| 86 |
+
continue
|
| 87 |
+
props_attribute = "ExtendedProperties"
|
| 88 |
+
|
| 89 |
+
props = getattr(inverse, props_attribute)
|
| 90 |
+
if not props:
|
| 91 |
+
continue
|
| 92 |
+
|
| 93 |
+
copied_props = []
|
| 94 |
+
for pset in props:
|
| 95 |
+
copied_props.append(ifcopenshell.util.element.copy_deep(file, pset))
|
| 96 |
+
setattr(inverse, props_attribute, copied_props)
|
| 97 |
+
|
| 98 |
+
elif inverse.is_a("IfcMaterialDefinitionRepresentation"):
|
| 99 |
+
inverse = ifcopenshell.util.element.copy_deep(
|
| 100 |
+
file, inverse, exclude=["IfcRepresentationContext", "IfcMaterial", "IfcPresentationStyle"]
|
| 101 |
+
)
|
| 102 |
+
inverse.RepresentedMaterial = new
|
| 103 |
+
return new
|
data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/material/edit_constituent.py
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# IfcOpenShell - IFC toolkit and geometry engine
|
| 2 |
+
# Copyright (C) 2021 Dion Moult <dion@thinkmoult.com>
|
| 3 |
+
#
|
| 4 |
+
# This file is part of IfcOpenShell.
|
| 5 |
+
#
|
| 6 |
+
# IfcOpenShell is free software: you can redistribute it and/or modify
|
| 7 |
+
# it under the terms of the GNU Lesser General Public License as published by
|
| 8 |
+
# the Free Software Foundation, either version 3 of the License, or
|
| 9 |
+
# (at your option) any later version.
|
| 10 |
+
#
|
| 11 |
+
# IfcOpenShell is distributed in the hope that it will be useful,
|
| 12 |
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 13 |
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 14 |
+
# GNU Lesser General Public License for more details.
|
| 15 |
+
#
|
| 16 |
+
# You should have received a copy of the GNU Lesser General Public License
|
| 17 |
+
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
|
| 18 |
+
import ifcopenshell
|
| 19 |
+
from typing import Optional, Any
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
def edit_constituent(
|
| 23 |
+
file: ifcopenshell.file,
|
| 24 |
+
constituent: ifcopenshell.entity_instance,
|
| 25 |
+
attributes: Optional[dict[str, Any]] = None,
|
| 26 |
+
material: Optional[ifcopenshell.entity_instance] = None,
|
| 27 |
+
) -> None:
|
| 28 |
+
"""Edits the attributes of an IfcMaterialConstituent
|
| 29 |
+
|
| 30 |
+
For more information about the attributes and data types of an
|
| 31 |
+
IfcMaterialConstituent, consult the IFC documentation.
|
| 32 |
+
|
| 33 |
+
:param constituent: The IfcMaterialConstituent entity you want to edit
|
| 34 |
+
:param attributes: a dictionary of attribute names and values.
|
| 35 |
+
:param material: The IfcMaterial entity you want to change the constituent to
|
| 36 |
+
:return: None
|
| 37 |
+
|
| 38 |
+
Example:
|
| 39 |
+
|
| 40 |
+
.. code:: python
|
| 41 |
+
|
| 42 |
+
# Let's add two materials
|
| 43 |
+
aluminium1 = ifcopenshell.api.material.add_material(model, name="AL01", category="aluminium")
|
| 44 |
+
aluminium2 = ifcopenshell.api.material.add_material(model, name="AL02", category="aluminium")
|
| 45 |
+
glass = ifcopenshell.api.material.add_material(model, name="GLZ01", category="glass")
|
| 46 |
+
|
| 47 |
+
material_set = ifcopenshell.api.material.add_material_set(model,
|
| 48 |
+
name="Window", set_type="IfcMaterialConstituentSet")
|
| 49 |
+
|
| 50 |
+
# Set up two constituents, one for the frame and the other for the glazing.
|
| 51 |
+
framing = ifcopenshell.api.material.add_constituent(model,
|
| 52 |
+
constituent_set=material_set, material=aluminium1)
|
| 53 |
+
glazing = ifcopenshell.api.material.add_constituent(model,
|
| 54 |
+
constituent_set=material_set, material=glass)
|
| 55 |
+
|
| 56 |
+
# Let's make sure this constituent refers to the framing of the
|
| 57 |
+
# window and uses the second aluminium material instead.
|
| 58 |
+
ifcopenshell.api.material.edit_constituent(model,
|
| 59 |
+
constituent=framing, attributes={"Name": "Framing"}, material=aluminium2)
|
| 60 |
+
|
| 61 |
+
ifcopenshell.api.material.edit_constituent(model,
|
| 62 |
+
constituent=constituent, attributes={"Name": "Glazing"})
|
| 63 |
+
"""
|
| 64 |
+
for name, value in (attributes or {}).items():
|
| 65 |
+
setattr(constituent, name, value)
|
| 66 |
+
constituent.Material = material
|
data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/material/edit_layer.py
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# IfcOpenShell - IFC toolkit and geometry engine
|
| 2 |
+
# Copyright (C) 2021 Dion Moult <dion@thinkmoult.com>
|
| 3 |
+
#
|
| 4 |
+
# This file is part of IfcOpenShell.
|
| 5 |
+
#
|
| 6 |
+
# IfcOpenShell is free software: you can redistribute it and/or modify
|
| 7 |
+
# it under the terms of the GNU Lesser General Public License as published by
|
| 8 |
+
# the Free Software Foundation, either version 3 of the License, or
|
| 9 |
+
# (at your option) any later version.
|
| 10 |
+
#
|
| 11 |
+
# IfcOpenShell is distributed in the hope that it will be useful,
|
| 12 |
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 13 |
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 14 |
+
# GNU Lesser General Public License for more details.
|
| 15 |
+
#
|
| 16 |
+
# You should have received a copy of the GNU Lesser General Public License
|
| 17 |
+
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
|
| 18 |
+
import ifcopenshell
|
| 19 |
+
from typing import Optional, Any
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
def edit_layer(
|
| 23 |
+
file: ifcopenshell.file,
|
| 24 |
+
layer: ifcopenshell.entity_instance,
|
| 25 |
+
attributes: Optional[dict[str, Any]] = None,
|
| 26 |
+
material: Optional[ifcopenshell.entity_instance] = None,
|
| 27 |
+
) -> None:
|
| 28 |
+
"""Edits the attributes of an IfcMaterialLayer
|
| 29 |
+
|
| 30 |
+
For more information about the attributes and data types of an
|
| 31 |
+
IfcMaterialLayer, consult the IFC documentation.
|
| 32 |
+
|
| 33 |
+
:param layer: The IfcMaterialLayer entity you want to edit
|
| 34 |
+
:param attributes: a dictionary of attribute names and values.
|
| 35 |
+
:param material: The IfcMaterial entity you want the layer to be made
|
| 36 |
+
from.
|
| 37 |
+
:return: None
|
| 38 |
+
|
| 39 |
+
Example:
|
| 40 |
+
|
| 41 |
+
.. code:: python
|
| 42 |
+
|
| 43 |
+
# Let's create two materials typically used for steel stud partition
|
| 44 |
+
# walls with gypsum lining.
|
| 45 |
+
gypsum = ifcopenshell.api.material.add_material(model, name="PB01", category="gypsum")
|
| 46 |
+
steel = ifcopenshell.api.material.add_material(model, name="ST01", category="steel")
|
| 47 |
+
|
| 48 |
+
# Create a material layer set to contain our layers.
|
| 49 |
+
material_set = ifcopenshell.api.material.add_material_set(model,
|
| 50 |
+
name="GYP-ST-GYP", set_type="IfcMaterialLayerSet")
|
| 51 |
+
|
| 52 |
+
# Now let's use those materials as three layers in our set, such
|
| 53 |
+
# that the steel studs are sandwiched by the gypsum. Let's imagine
|
| 54 |
+
# we're setting the layer thickness in millimeters.
|
| 55 |
+
layer = ifcopenshell.api.material.add_layer(model, layer_set=material_set, material=gypsum)
|
| 56 |
+
ifcopenshell.api.material.edit_layer(model, layer=layer, attributes={"LayerThickness": 13})
|
| 57 |
+
layer = ifcopenshell.api.material.add_layer(model, layer_set=material_set, material=steel)
|
| 58 |
+
ifcopenshell.api.material.edit_layer(model, layer=layer, attributes={"LayerThickness": 92})
|
| 59 |
+
layer = ifcopenshell.api.material.add_layer(model, layer_set=material_set, material=gypsum)
|
| 60 |
+
ifcopenshell.api.material.edit_layer(model, layer=layer, attributes={"LayerThickness": 13})
|
| 61 |
+
"""
|
| 62 |
+
for name, value in (attributes or {}).items():
|
| 63 |
+
setattr(layer, name, value)
|
| 64 |
+
if material:
|
| 65 |
+
layer.Material = material
|
data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/material/edit_layer_usage.py
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# IfcOpenShell - IFC toolkit and geometry engine
|
| 2 |
+
# Copyright (C) 2021 Dion Moult <dion@thinkmoult.com>
|
| 3 |
+
#
|
| 4 |
+
# This file is part of IfcOpenShell.
|
| 5 |
+
#
|
| 6 |
+
# IfcOpenShell is free software: you can redistribute it and/or modify
|
| 7 |
+
# it under the terms of the GNU Lesser General Public License as published by
|
| 8 |
+
# the Free Software Foundation, either version 3 of the License, or
|
| 9 |
+
# (at your option) any later version.
|
| 10 |
+
#
|
| 11 |
+
# IfcOpenShell is distributed in the hope that it will be useful,
|
| 12 |
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 13 |
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 14 |
+
# GNU Lesser General Public License for more details.
|
| 15 |
+
#
|
| 16 |
+
# You should have received a copy of the GNU Lesser General Public License
|
| 17 |
+
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
|
| 18 |
+
import ifcopenshell
|
| 19 |
+
from typing import Any
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
def edit_layer_usage(file: ifcopenshell.file, usage: ifcopenshell.entity_instance, attributes: dict[str, Any]) -> None:
|
| 23 |
+
"""Edits the attributes of an IfcMaterialLayerSetUsage
|
| 24 |
+
|
| 25 |
+
This is typically used to change the offset from the reference line to
|
| 26 |
+
the layers.
|
| 27 |
+
|
| 28 |
+
For more information about the attributes and data types of an
|
| 29 |
+
IfcMaterialLayerSetUsage, consult the IFC documentation.
|
| 30 |
+
|
| 31 |
+
:param usage: The IfcMaterialLayerSetUsage entity you want to edit
|
| 32 |
+
:param attributes: a dictionary of attribute names and values.
|
| 33 |
+
:return: None
|
| 34 |
+
|
| 35 |
+
Example:
|
| 36 |
+
|
| 37 |
+
.. code:: python
|
| 38 |
+
|
| 39 |
+
# Let's start with a simple concrete material
|
| 40 |
+
concrete = ifcopenshell.api.material.add_material(model, name="CON01", category="concrete")
|
| 41 |
+
|
| 42 |
+
# If we have a concrete wall, we should use a layer set. Again,
|
| 43 |
+
# let's start with a wall type, not occurrences.
|
| 44 |
+
wall_type = ifcopenshell.api.root.create_entity(model, ifc_class="IfcWallType", name="WAL01")
|
| 45 |
+
|
| 46 |
+
# Even though there is only one layer in our layer set, we still use
|
| 47 |
+
# a layer set because it makes it clear that this is a layered
|
| 48 |
+
# construction. Let's say it's a 200mm thick concrete layer.
|
| 49 |
+
material_set = ifcopenshell.api.material.add_material_set(model,
|
| 50 |
+
name="CON200", set_type="IfcMaterialLayerSet")
|
| 51 |
+
layer = ifcopenshell.api.material.add_layer(model, layer_set=material_set, material=steel)
|
| 52 |
+
ifcopenshell.api.material.edit_layer(model, layer=layer, attributes={"LayerThickness": 200})
|
| 53 |
+
|
| 54 |
+
# Our wall type now has the layer set assigned to it
|
| 55 |
+
ifcopenshell.api.material.assign_material(model,
|
| 56 |
+
products=[wall_type], type="IfcMaterialLayerSet", material=material_set)
|
| 57 |
+
|
| 58 |
+
# Let's imagine an occurrence of this wall type.
|
| 59 |
+
wall = ifcopenshell.api.root.create_entity(model, ifc_class="IfcWall")
|
| 60 |
+
ifcopenshell.api.type.assign_type(model, related_objects=[wall], relating_type=wall_type)
|
| 61 |
+
|
| 62 |
+
# Our wall occurrence needs to have a "set usage" which describes
|
| 63 |
+
# how the layers relate to a reference line (typically a 2D line
|
| 64 |
+
# representing the extents of the wall). Usages are special since
|
| 65 |
+
# they automatically detect the inherited material set from the
|
| 66 |
+
# type. You'd write similar code for a profile set.
|
| 67 |
+
rel = ifcopenshell.api.material.assign_material(model,
|
| 68 |
+
products=[wall], type="IfcMaterialLayerSetUsage")
|
| 69 |
+
|
| 70 |
+
# Let's change the offset from the reference line to be 200mm
|
| 71 |
+
# instead of the default of 0mm.
|
| 72 |
+
ifcopenshell.api.material.edit_layer_usage(model,
|
| 73 |
+
usage=rel.RelatingMaterial, attributes={"OffsetFromReferenceLine": 200})
|
| 74 |
+
"""
|
| 75 |
+
for name, value in attributes.items():
|
| 76 |
+
setattr(usage, name, value)
|
data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/material/remove_profile.py
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# IfcOpenShell - IFC toolkit and geometry engine
|
| 2 |
+
# Copyright (C) 2021 Dion Moult <dion@thinkmoult.com>
|
| 3 |
+
#
|
| 4 |
+
# This file is part of IfcOpenShell.
|
| 5 |
+
#
|
| 6 |
+
# IfcOpenShell is free software: you can redistribute it and/or modify
|
| 7 |
+
# it under the terms of the GNU Lesser General Public License as published by
|
| 8 |
+
# the Free Software Foundation, either version 3 of the License, or
|
| 9 |
+
# (at your option) any later version.
|
| 10 |
+
#
|
| 11 |
+
# IfcOpenShell is distributed in the hope that it will be useful,
|
| 12 |
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 13 |
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 14 |
+
# GNU Lesser General Public License for more details.
|
| 15 |
+
#
|
| 16 |
+
# You should have received a copy of the GNU Lesser General Public License
|
| 17 |
+
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
import ifcopenshell.util.element
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
def remove_profile(
|
| 24 |
+
file: ifcopenshell.file,
|
| 25 |
+
profile: ifcopenshell.entity_instance,
|
| 26 |
+
should_remove_profile_def: bool = False,
|
| 27 |
+
should_remove_material: bool = False,
|
| 28 |
+
) -> None:
|
| 29 |
+
"""Removes a profile item from a profile set
|
| 30 |
+
|
| 31 |
+
Note that it is invalid to have zero items in a set, so you should leave
|
| 32 |
+
at least one profile to ensure a valid IFC dataset.
|
| 33 |
+
|
| 34 |
+
:param profile: The IfcMaterialProfile entity you want to remove
|
| 35 |
+
:param should_remove_profile_def: If true, profile defs with no users will be removed
|
| 36 |
+
:param should_remove_material: If true, materials with no users will be removed
|
| 37 |
+
|
| 38 |
+
Example:
|
| 39 |
+
|
| 40 |
+
.. code:: python
|
| 41 |
+
|
| 42 |
+
# First, let's create a material set.
|
| 43 |
+
material_set = ifcopenshell.api.material.add_material_set(model,
|
| 44 |
+
name="B1", set_type="IfcMaterialProfileSet")
|
| 45 |
+
|
| 46 |
+
# Create a steel material.
|
| 47 |
+
steel = ifcopenshell.api.material.add_material(model, name="ST01", category="steel")
|
| 48 |
+
|
| 49 |
+
# Create an I-beam profile curve. Notice how we name our profiles
|
| 50 |
+
# based on standardised steel profile names.
|
| 51 |
+
hea100 = file.create_entity(
|
| 52 |
+
"IfcIShapeProfileDef", ProfileName="HEA100", ProfileType="AREA",
|
| 53 |
+
OverallWidth=100, OverallDepth=96, WebThickness=5, FlangeThickness=8, FilletRadius=12,
|
| 54 |
+
)
|
| 55 |
+
|
| 56 |
+
# Define that steel material and cross section as a single profile item.
|
| 57 |
+
ifcopenshell.api.material.add_profile(model,
|
| 58 |
+
profile_set=material_set, material=steel, profile=hea100)
|
| 59 |
+
|
| 60 |
+
# Imagine a welded square along the length of the profile.
|
| 61 |
+
welded_square = ifcopenshell.api.profile.add_arbitrary_profile(model,
|
| 62 |
+
profile=[(.0025, .0025), (.0325, .0025), (.0325, -.0025), (.0025, -.0025), (.0025, .0025)])
|
| 63 |
+
weld_profile = ifcopenshell.api.material.add_profile(model,
|
| 64 |
+
profile_set=material_set, material=steel, profile=welded_square)
|
| 65 |
+
|
| 66 |
+
# Let's remove our welded square.
|
| 67 |
+
ifcopenshell.api.material.remove_profile(model, profile=weld_profile)
|
| 68 |
+
"""
|
| 69 |
+
|
| 70 |
+
subelements = set()
|
| 71 |
+
for attribute in profile:
|
| 72 |
+
if isinstance(attribute, ifcopenshell.entity_instance):
|
| 73 |
+
subelements.add(attribute)
|
| 74 |
+
file.remove(profile)
|
| 75 |
+
for subelement in subelements:
|
| 76 |
+
if subelement.is_a("IfcMaterial") and not should_remove_material:
|
| 77 |
+
continue
|
| 78 |
+
elif subelement.is_a("IfcProfileDef") and not should_remove_profile_def:
|
| 79 |
+
continue
|
| 80 |
+
ifcopenshell.util.element.remove_deep2(file, subelement)
|
data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/material/reorder_set_item.py
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# IfcOpenShell - IFC toolkit and geometry engine
|
| 2 |
+
# Copyright (C) 2021 Dion Moult <dion@thinkmoult.com>
|
| 3 |
+
#
|
| 4 |
+
# This file is part of IfcOpenShell.
|
| 5 |
+
#
|
| 6 |
+
# IfcOpenShell is free software: you can redistribute it and/or modify
|
| 7 |
+
# it under the terms of the GNU Lesser General Public License as published by
|
| 8 |
+
# the Free Software Foundation, either version 3 of the License, or
|
| 9 |
+
# (at your option) any later version.
|
| 10 |
+
#
|
| 11 |
+
# IfcOpenShell is distributed in the hope that it will be useful,
|
| 12 |
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 13 |
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 14 |
+
# GNU Lesser General Public License for more details.
|
| 15 |
+
#
|
| 16 |
+
# You should have received a copy of the GNU Lesser General Public License
|
| 17 |
+
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
|
| 18 |
+
import ifcopenshell
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
def reorder_set_item(
|
| 22 |
+
file: ifcopenshell.file, material_set: ifcopenshell.entity_instance, old_index: int = 0, new_index: int = 0
|
| 23 |
+
) -> None:
|
| 24 |
+
"""Reorders an item in a material set
|
| 25 |
+
|
| 26 |
+
In some material sets, the order have meaning, like in a layer set. In
|
| 27 |
+
other cases, it is purely for human convenience.
|
| 28 |
+
|
| 29 |
+
:param material_set: The IfcMaterialSet which you want to reorder an
|
| 30 |
+
item in.
|
| 31 |
+
:param old_index: The index of the item you want to move. This starts
|
| 32 |
+
counting from 0.
|
| 33 |
+
:param new_index: The index of the new position the item will move to.
|
| 34 |
+
This starts counting from 0.
|
| 35 |
+
:return: None
|
| 36 |
+
|
| 37 |
+
Example:
|
| 38 |
+
|
| 39 |
+
.. code:: python
|
| 40 |
+
|
| 41 |
+
material_set = ifcopenshell.api.material.add_material_set(model,
|
| 42 |
+
name="Window", set_type="IfcMaterialList")
|
| 43 |
+
|
| 44 |
+
aluminium = ifcopenshell.api.material.add_material(model, name="AL01", category="aluminium")
|
| 45 |
+
glass = ifcopenshell.api.material.add_material(model, name="GLZ01", category="glass")
|
| 46 |
+
|
| 47 |
+
# Now let's use those materials as two items in our list.
|
| 48 |
+
ifcopenshell.api.material.add_list_item(model, material_list=material_set, material=aluminium)
|
| 49 |
+
ifcopenshell.api.material.add_list_item(model, material_list=material_set, material=glass)
|
| 50 |
+
|
| 51 |
+
# Switch the order around, this has no meaning for a list, so this
|
| 52 |
+
# is just for fun.
|
| 53 |
+
ifcopenshell.api.material.reorder_set_item(model,
|
| 54 |
+
material_set=material_set, old_index=0, new_index=1)
|
| 55 |
+
"""
|
| 56 |
+
if material_set.is_a("IfcMaterialConstituentSet"):
|
| 57 |
+
set_name = "MaterialConstituents"
|
| 58 |
+
elif material_set.is_a("IfcMaterialLayerSet"):
|
| 59 |
+
set_name = "MaterialLayers"
|
| 60 |
+
elif material_set.is_a("IfcMaterialProfileSet"):
|
| 61 |
+
set_name = "MaterialProfiles"
|
| 62 |
+
elif material_set.is_a("IfcMaterialList"):
|
| 63 |
+
set_name = "Materials"
|
| 64 |
+
else:
|
| 65 |
+
raise ValueError(f"Unexpected material set type: '{material_set.is_a()}'.")
|
| 66 |
+
|
| 67 |
+
items = list(getattr(material_set, set_name) or [])
|
| 68 |
+
items.insert(new_index, items.pop(old_index))
|
| 69 |
+
setattr(material_set, set_name, items)
|
data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/resource/__init__.py
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# IfcOpenShell - IFC toolkit and geometry engine
|
| 2 |
+
# Copyright (C) 2022 Dion Moult <dion@thinkmoult.com>
|
| 3 |
+
#
|
| 4 |
+
# This file is part of IfcOpenShell.
|
| 5 |
+
#
|
| 6 |
+
# IfcOpenShell is free software: you can redistribute it and/or modify
|
| 7 |
+
# it under the terms of the GNU Lesser General Public License as published by
|
| 8 |
+
# the Free Software Foundation, either version 3 of the License, or
|
| 9 |
+
# (at your option) any later version.
|
| 10 |
+
#
|
| 11 |
+
# IfcOpenShell is distributed in the hope that it will be useful,
|
| 12 |
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 13 |
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 14 |
+
# GNU Lesser General Public License for more details.
|
| 15 |
+
#
|
| 16 |
+
# You should have received a copy of the GNU Lesser General Public License
|
| 17 |
+
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
|
| 18 |
+
|
| 19 |
+
"""Manage construction and maintenance resources
|
| 20 |
+
|
| 21 |
+
Resources include equipment (cranes, etc), labour, material, and products. They
|
| 22 |
+
are typically referenced in construction planning, maintenance schedules, or
|
| 23 |
+
cost items.
|
| 24 |
+
"""
|
| 25 |
+
|
| 26 |
+
from .. import wrap_usecases
|
| 27 |
+
from .add_resource import add_resource
|
| 28 |
+
from .add_resource_quantity import add_resource_quantity
|
| 29 |
+
from .add_resource_time import add_resource_time
|
| 30 |
+
from .assign_resource import assign_resource
|
| 31 |
+
from .calculate_resource_usage import calculate_resource_usage
|
| 32 |
+
from .calculate_resource_work import calculate_resource_work
|
| 33 |
+
from .edit_resource import edit_resource
|
| 34 |
+
from .edit_resource_quantity import edit_resource_quantity
|
| 35 |
+
from .edit_resource_time import edit_resource_time
|
| 36 |
+
from .remove_resource import remove_resource
|
| 37 |
+
from .remove_resource_quantity import remove_resource_quantity
|
| 38 |
+
from .unassign_resource import unassign_resource
|
| 39 |
+
|
| 40 |
+
wrap_usecases(__path__, __name__)
|
| 41 |
+
|
| 42 |
+
__all__ = [
|
| 43 |
+
"add_resource",
|
| 44 |
+
"add_resource_quantity",
|
| 45 |
+
"add_resource_time",
|
| 46 |
+
"assign_resource",
|
| 47 |
+
"calculate_resource_usage",
|
| 48 |
+
"calculate_resource_work",
|
| 49 |
+
"edit_resource",
|
| 50 |
+
"edit_resource_quantity",
|
| 51 |
+
"edit_resource_time",
|
| 52 |
+
"remove_resource",
|
| 53 |
+
"remove_resource_quantity",
|
| 54 |
+
"unassign_resource",
|
| 55 |
+
]
|
data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/resource/add_resource.py
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# IfcOpenShell - IFC toolkit and geometry engine
|
| 2 |
+
# Copyright (C) 2021 Dion Moult <dion@thinkmoult.com>
|
| 3 |
+
#
|
| 4 |
+
# This file is part of IfcOpenShell.
|
| 5 |
+
#
|
| 6 |
+
# IfcOpenShell is free software: you can redistribute it and/or modify
|
| 7 |
+
# it under the terms of the GNU Lesser General Public License as published by
|
| 8 |
+
# the Free Software Foundation, either version 3 of the License, or
|
| 9 |
+
# (at your option) any later version.
|
| 10 |
+
#
|
| 11 |
+
# IfcOpenShell is distributed in the hope that it will be useful,
|
| 12 |
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 13 |
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 14 |
+
# GNU Lesser General Public License for more details.
|
| 15 |
+
#
|
| 16 |
+
# You should have received a copy of the GNU Lesser General Public License
|
| 17 |
+
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
|
| 18 |
+
|
| 19 |
+
import ifcopenshell.api.root
|
| 20 |
+
import ifcopenshell.api.nest
|
| 21 |
+
import ifcopenshell.api.project
|
| 22 |
+
from typing import Optional
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
def add_resource(
|
| 26 |
+
file: ifcopenshell.file,
|
| 27 |
+
parent_resource: Optional[ifcopenshell.entity_instance] = None,
|
| 28 |
+
ifc_class: str = "IfcCrewResource",
|
| 29 |
+
name: Optional[str] = None,
|
| 30 |
+
predefined_type: str = "NOTDEFINED",
|
| 31 |
+
) -> ifcopenshell.entity_instance:
|
| 32 |
+
"""Add a new construction resource
|
| 33 |
+
|
| 34 |
+
Construction resources may be managed and connected to cost schedules
|
| 35 |
+
and construction schedules. This allows calculations to be done on
|
| 36 |
+
resource utilisation, cost optimisation (e.g. labour rates), and
|
| 37 |
+
optioneering on build strategies.
|
| 38 |
+
|
| 39 |
+
There are typically two types of resources. Crew resources are resources
|
| 40 |
+
where you manage your own crew and you have full control over the
|
| 41 |
+
equipment, labour, products, and materials used by your crew.
|
| 42 |
+
Alternatively, there are subcontractor resources, where you simply
|
| 43 |
+
delegate all the details to a subcontractor and it is not decomposed
|
| 44 |
+
into further levels of detail.
|
| 45 |
+
|
| 46 |
+
This means when adding resources, you'd first either add a crew or
|
| 47 |
+
subcontract resource. If it is a crew resource, you'd then add child
|
| 48 |
+
resources to that crew, such as equipment (cranes, excavators, hoists,
|
| 49 |
+
etc), material (wood, concrete, etc), and labour (rigging crews,
|
| 50 |
+
formworkers, etc).
|
| 51 |
+
|
| 52 |
+
:param parent_resource: If this is a child resource (typically to a crew
|
| 53 |
+
resource), then nominate the parent IfcConstructionResource here.
|
| 54 |
+
:param ifc_class: The class of resource chosen from
|
| 55 |
+
IfcConstructionEquipmentResource, IfcConstructionMaterialResource,
|
| 56 |
+
IfcConstructionProductResource, IfcCrewResource, IfcLaborResource,
|
| 57 |
+
or IfcSubContractResource.
|
| 58 |
+
:param name: The name of the resource
|
| 59 |
+
:param predefined_type: Consult the IFC documentation for the valid
|
| 60 |
+
predefined types for each type of resource class.
|
| 61 |
+
:return: The newly created resource depending on the nominated IFC
|
| 62 |
+
class.
|
| 63 |
+
|
| 64 |
+
Example:
|
| 65 |
+
|
| 66 |
+
.. code:: python
|
| 67 |
+
|
| 68 |
+
# Add our own crew
|
| 69 |
+
crew = ifcopenshell.api.resource.add_resource(model, ifc_class="IfcCrewResource")
|
| 70 |
+
|
| 71 |
+
# Add some labour to our crew.
|
| 72 |
+
ifcopenshell.api.resource.add_resource(model, parent_resource=crew, ifc_class="IfcLaborResource")
|
| 73 |
+
"""
|
| 74 |
+
|
| 75 |
+
resource = ifcopenshell.api.root.create_entity(
|
| 76 |
+
file,
|
| 77 |
+
ifc_class=ifc_class,
|
| 78 |
+
predefined_type=predefined_type,
|
| 79 |
+
name=name or "Unnamed",
|
| 80 |
+
)
|
| 81 |
+
# TODO: this is an ambiguity by buildingSMART: Can we nest an IfcCrewResource under an IfcCrewResource ?
|
| 82 |
+
# https://forums.buildingsmart.org/t/what-are-allowed-to-be-root-level-construction-resources/3550
|
| 83 |
+
if parent_resource:
|
| 84 |
+
ifcopenshell.api.nest.assign_object(file, related_objects=[resource], relating_object=parent_resource)
|
| 85 |
+
elif file.schema != "IFC2X3":
|
| 86 |
+
context = file.by_type("IfcContext")[0]
|
| 87 |
+
ifcopenshell.api.project.assign_declaration(file, definitions=[resource], relating_context=context)
|
| 88 |
+
return resource
|
data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/resource/add_resource_quantity.py
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# IfcOpenShell - IFC toolkit and geometry engine
|
| 2 |
+
# Copyright (C) 2021 Dion Moult <dion@thinkmoult.com>
|
| 3 |
+
#
|
| 4 |
+
# This file is part of IfcOpenShell.
|
| 5 |
+
#
|
| 6 |
+
# IfcOpenShell is free software: you can redistribute it and/or modify
|
| 7 |
+
# it under the terms of the GNU Lesser General Public License as published by
|
| 8 |
+
# the Free Software Foundation, either version 3 of the License, or
|
| 9 |
+
# (at your option) any later version.
|
| 10 |
+
#
|
| 11 |
+
# IfcOpenShell is distributed in the hope that it will be useful,
|
| 12 |
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 13 |
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 14 |
+
# GNU Lesser General Public License for more details.
|
| 15 |
+
#
|
| 16 |
+
# You should have received a copy of the GNU Lesser General Public License
|
| 17 |
+
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
|
| 18 |
+
|
| 19 |
+
import ifcopenshell.util.element
|
| 20 |
+
import ifcopenshell.util.resource
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
def add_resource_quantity(
|
| 24 |
+
file: ifcopenshell.file, resource: ifcopenshell.entity_instance, ifc_class: str = "IfcQuantityCount"
|
| 25 |
+
) -> ifcopenshell.entity_instance:
|
| 26 |
+
"""Adds a quantity to a resource
|
| 27 |
+
|
| 28 |
+
The quantity of a resource represents the "unit quantity" of that
|
| 29 |
+
resource. For example, labour might be hired on a daily basis (8 hours).
|
| 30 |
+
There are different types of quantities (e.g. volume, count, or time).
|
| 31 |
+
Which quantity is used depends on the type of resource. Material
|
| 32 |
+
resources may be quantified in terms of length, area, volume, or weight.
|
| 33 |
+
Equipment and labour resources are quantified in terms of time. Products
|
| 34 |
+
resources are quantified in terms of counts.
|
| 35 |
+
|
| 36 |
+
This base quantity is then used in other calculations.
|
| 37 |
+
|
| 38 |
+
:param resource: The IfcConstructionResource to add a quantity to.
|
| 39 |
+
:param ifc_class: The type of quantity to add, chosen from
|
| 40 |
+
IfcQuantityArea (for material), IfcQuantityCount (for products),
|
| 41 |
+
IfcQuantityLength (for material), IfcQuantityTime (for equipment or
|
| 42 |
+
labour), IfcQuantityVolume (for material), and IfcQuantityWeight
|
| 43 |
+
(for material).
|
| 44 |
+
:return: The newly created quantity depending on the IFC class
|
| 45 |
+
|
| 46 |
+
Example:
|
| 47 |
+
|
| 48 |
+
.. code:: python
|
| 49 |
+
|
| 50 |
+
# Add our own crew
|
| 51 |
+
crew = ifcopenshell.api.resource.add_resource(model, ifc_class="IfcCrewResource")
|
| 52 |
+
|
| 53 |
+
# Add some labour to our crew.
|
| 54 |
+
labour = ifcopenshell.api.resource.add_resource(model,
|
| 55 |
+
parent_resource=crew, ifc_class="IfcLaborResource")
|
| 56 |
+
|
| 57 |
+
# Labour resource is quantified in terms of time.
|
| 58 |
+
quantity = ifcopenshell.api.resource.add_resource_quantity(model,
|
| 59 |
+
resource=labour, ifc_class="IfcQuantityTime")
|
| 60 |
+
|
| 61 |
+
# Store the time used in hours
|
| 62 |
+
ifcopenshell.api.resource.edit_resource_quantity(model,
|
| 63 |
+
physical_quantity=quantity, attributes={"TimeValue": 8.0})
|
| 64 |
+
"""
|
| 65 |
+
resource_type = resource.is_a()
|
| 66 |
+
supported_quantities = ifcopenshell.util.resource.RESOURCES_TO_QUANTITIES[resource_type]
|
| 67 |
+
if ifc_class not in supported_quantities:
|
| 68 |
+
raise ValueError(
|
| 69 |
+
f"Resource type '{resource_type}' does not support quantity type '{ifc_class}'. "
|
| 70 |
+
f"Supported quantities: {','.join(supported_quantities)}"
|
| 71 |
+
)
|
| 72 |
+
|
| 73 |
+
quantity = file.create_entity(ifc_class, Name="Unnamed")
|
| 74 |
+
# 3 IfcPhysicalSimpleQuantity Value
|
| 75 |
+
if ifc_class == "IfcQuantityCount":
|
| 76 |
+
quantity[3] = 0
|
| 77 |
+
else:
|
| 78 |
+
quantity[3] = 0.0
|
| 79 |
+
old_quantity = resource.BaseQuantity
|
| 80 |
+
resource.BaseQuantity = quantity
|
| 81 |
+
if old_quantity:
|
| 82 |
+
ifcopenshell.util.element.remove_deep(file, old_quantity)
|
| 83 |
+
return quantity
|
data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/resource/add_resource_time.py
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# IfcOpenShell - IFC toolkit and geometry engine
|
| 2 |
+
# Copyright (C) 2021 Dion Moult <dion@thinkmoult.com>
|
| 3 |
+
#
|
| 4 |
+
# This file is part of IfcOpenShell.
|
| 5 |
+
#
|
| 6 |
+
# IfcOpenShell is free software: you can redistribute it and/or modify
|
| 7 |
+
# it under the terms of the GNU Lesser General Public License as published by
|
| 8 |
+
# the Free Software Foundation, either version 3 of the License, or
|
| 9 |
+
# (at your option) any later version.
|
| 10 |
+
#
|
| 11 |
+
# IfcOpenShell is distributed in the hope that it will be useful,
|
| 12 |
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 13 |
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 14 |
+
# GNU Lesser General Public License for more details.
|
| 15 |
+
#
|
| 16 |
+
# You should have received a copy of the GNU Lesser General Public License
|
| 17 |
+
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
|
| 18 |
+
|
| 19 |
+
import ifcopenshell.util.date
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
def add_resource_time(file: ifcopenshell.file, resource: ifcopenshell.entity_instance) -> ifcopenshell.entity_instance:
|
| 23 |
+
"""Adds the time that a resource is used for
|
| 24 |
+
|
| 25 |
+
For labour and equipment resources, the total duration that the resource
|
| 26 |
+
is used for may be stored. This may either be input manually or
|
| 27 |
+
calculated parametrically. This is known as the resource time, and may
|
| 28 |
+
be used to calculate other parameters like resource utilisation.
|
| 29 |
+
|
| 30 |
+
:param resource: The IfcConstructionResource to record time for.
|
| 31 |
+
:return: The newly created IfcResourceTime
|
| 32 |
+
|
| 33 |
+
Example:
|
| 34 |
+
|
| 35 |
+
.. code:: python
|
| 36 |
+
|
| 37 |
+
# Add our own crew
|
| 38 |
+
crew = ifcopenshell.api.resource.add_resource(model, ifc_class="IfcCrewResource")
|
| 39 |
+
|
| 40 |
+
# Add some labour to our crew.
|
| 41 |
+
labour = ifcopenshell.api.resource.add_resource(model,
|
| 42 |
+
parent_resource=crew, ifc_class="IfcLaborResource")
|
| 43 |
+
|
| 44 |
+
# Labour resource is quantified in terms of time.
|
| 45 |
+
quantity = ifcopenshell.api.resource.add_resource_quantity(model,
|
| 46 |
+
resource=labour, ifc_class="IfcQuantityTime")
|
| 47 |
+
|
| 48 |
+
# Store the unit time used in hours
|
| 49 |
+
ifcopenshell.api.resource.edit_resource_quantity(model,
|
| 50 |
+
physical_quantity=quantity, attributes={"TimeValue": 8.0})
|
| 51 |
+
|
| 52 |
+
# Let's imagine we've used the resource for 2 days.
|
| 53 |
+
time = ifcopenshell.api.resource.add_resource_time(model, resource=labour)
|
| 54 |
+
ifcopenshell.api.resource.edit_resource_time(model,
|
| 55 |
+
resource_time=time, attributes={"ScheduleWork": "PT16H"})
|
| 56 |
+
"""
|
| 57 |
+
resource_time = file.create_entity("IfcResourceTime")
|
| 58 |
+
resource.Usage = resource_time
|
| 59 |
+
return resource_time
|
data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/resource/assign_resource.py
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# IfcOpenShell - IFC toolkit and geometry engine
|
| 2 |
+
# Copyright (C) 2021 Dion Moult <dion@thinkmoult.com>
|
| 3 |
+
#
|
| 4 |
+
# This file is part of IfcOpenShell.
|
| 5 |
+
#
|
| 6 |
+
# IfcOpenShell is free software: you can redistribute it and/or modify
|
| 7 |
+
# it under the terms of the GNU Lesser General Public License as published by
|
| 8 |
+
# the Free Software Foundation, either version 3 of the License, or
|
| 9 |
+
# (at your option) any later version.
|
| 10 |
+
#
|
| 11 |
+
# IfcOpenShell is distributed in the hope that it will be useful,
|
| 12 |
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 13 |
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 14 |
+
# GNU Lesser General Public License for more details.
|
| 15 |
+
#
|
| 16 |
+
# You should have received a copy of the GNU Lesser General Public License
|
| 17 |
+
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
|
| 18 |
+
|
| 19 |
+
import ifcopenshell
|
| 20 |
+
import ifcopenshell.api.owner
|
| 21 |
+
import ifcopenshell.guid
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
def assign_resource(
|
| 25 |
+
file: ifcopenshell.file,
|
| 26 |
+
relating_resource: ifcopenshell.entity_instance,
|
| 27 |
+
related_object: ifcopenshell.entity_instance,
|
| 28 |
+
) -> ifcopenshell.entity_instance:
|
| 29 |
+
"""Assigns a resource to an object
|
| 30 |
+
|
| 31 |
+
Two types of objects are typically assigned to resources: products and
|
| 32 |
+
actors.
|
| 33 |
+
|
| 34 |
+
If a product is assigned to a resource, that means that the product
|
| 35 |
+
represents the resource on site. This may be represented via material
|
| 36 |
+
handling zones on a construction site, or equipment like cranes and
|
| 37 |
+
their physical locations.
|
| 38 |
+
|
| 39 |
+
If an actor is assigned to a resource, that means that the actor (person
|
| 40 |
+
or organisation) is the actor consuming the resource (e.g. if the
|
| 41 |
+
resource is material or equipment) or the actor performing the work
|
| 42 |
+
(e.g. if the resource is a labour resource).
|
| 43 |
+
|
| 44 |
+
:param relating_resource: The IfcResource to assign the object to.
|
| 45 |
+
:param related_object: The IfcProduct or IfcActor to assign to the
|
| 46 |
+
object.
|
| 47 |
+
:return: The newly created IfcRelAssignsToResource
|
| 48 |
+
|
| 49 |
+
Example:
|
| 50 |
+
|
| 51 |
+
.. code:: python
|
| 52 |
+
|
| 53 |
+
# Add our own crew
|
| 54 |
+
crew = ifcopenshell.api.resource.add_resource(model, ifc_class="IfcCrewResource")
|
| 55 |
+
|
| 56 |
+
# Add some a tower crane to our crew.
|
| 57 |
+
crane = ifcopenshell.api.resource.add_resource(model,
|
| 58 |
+
parent_resource=crew, ifc_class="IfcConstructionEquipmentResource", name="Tower Crane 01")
|
| 59 |
+
|
| 60 |
+
# Our tower crane will be placed via this physical product.
|
| 61 |
+
product = ifcopenshell.api.root.create_entity(model,
|
| 62 |
+
ifc_class="IfcBuildingElementProxy", predefined_type="CRANE")
|
| 63 |
+
|
| 64 |
+
# Let's place our crane at some X, Y coordinates.
|
| 65 |
+
matrix = numpy.eye(4)
|
| 66 |
+
matrix[0][3], matrix[1][3] = 3.0, 4.0
|
| 67 |
+
ifcopenshell.api.geometry.edit_object_placement(model, product=crane, matrix=matrix)
|
| 68 |
+
|
| 69 |
+
# Let's assign our crane to the resource. The crane now represents
|
| 70 |
+
# the resource.
|
| 71 |
+
ifcopenshell.api.resource.assign_resource(model, relating_resource=crane, related_object=product)
|
| 72 |
+
|
| 73 |
+
# Setup an organisation actor who will operate the crane
|
| 74 |
+
organisation = ifcopenshell.api.owner.add_organisation(model,
|
| 75 |
+
identification="UCO", name="Unionised Crane Operators Pty Ltd")
|
| 76 |
+
role = ifcopenshell.api.owner.add_role(model, assigned_object=organisation, role="CREW")
|
| 77 |
+
actor = ifcopenshell.api.owner.add_actor(model, actor=organisation)
|
| 78 |
+
|
| 79 |
+
# This means that UCO is now our crane operator.
|
| 80 |
+
ifcopenshell.api.resource.assign_resource(model, relating_resource=crane, related_object=actor)
|
| 81 |
+
"""
|
| 82 |
+
if related_object.HasAssignments:
|
| 83 |
+
for assignment in related_object.HasAssignments:
|
| 84 |
+
if assignment.is_a("IfclRelAssignsToResource") and assignment.RelatingResource == relating_resource:
|
| 85 |
+
return assignment
|
| 86 |
+
|
| 87 |
+
resource_of = None
|
| 88 |
+
if relating_resource.ResourceOf:
|
| 89 |
+
resource_of = relating_resource.ResourceOf[0]
|
| 90 |
+
|
| 91 |
+
if resource_of:
|
| 92 |
+
related_objects = list(resource_of.RelatedObjects)
|
| 93 |
+
related_objects.append(related_object)
|
| 94 |
+
resource_of.RelatedObjects = related_objects
|
| 95 |
+
ifcopenshell.api.owner.update_owner_history(file, element=resource_of)
|
| 96 |
+
else:
|
| 97 |
+
resource_of = file.create_entity(
|
| 98 |
+
"IfcRelAssignsToResource",
|
| 99 |
+
**{
|
| 100 |
+
"GlobalId": ifcopenshell.guid.new(),
|
| 101 |
+
"OwnerHistory": ifcopenshell.api.owner.create_owner_history(file),
|
| 102 |
+
"RelatedObjects": [related_object],
|
| 103 |
+
"RelatingResource": relating_resource,
|
| 104 |
+
}
|
| 105 |
+
)
|
| 106 |
+
return resource_of
|
data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/resource/calculate_resource_usage.py
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# IfcOpenShell - IFC toolkit and geometry engine
|
| 2 |
+
# Copyright (C) 2021 Dion Moult <dion@thinkmoult.com>
|
| 3 |
+
#
|
| 4 |
+
# This file is part of IfcOpenShell.
|
| 5 |
+
#
|
| 6 |
+
# IfcOpenShell is free software: you can redistribute it and/or modify
|
| 7 |
+
# it under the terms of the GNU Lesser General Public License as published by
|
| 8 |
+
# the Free Software Foundation, either version 3 of the License, or
|
| 9 |
+
# (at your option) any later version.
|
| 10 |
+
#
|
| 11 |
+
# IfcOpenShell is distributed in the hope that it will be useful,
|
| 12 |
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 13 |
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 14 |
+
# GNU Lesser General Public License for more details.
|
| 15 |
+
#
|
| 16 |
+
# You should have received a copy of the GNU Lesser General Public License
|
| 17 |
+
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
|
| 18 |
+
|
| 19 |
+
import math
|
| 20 |
+
import ifcopenshell.api
|
| 21 |
+
import ifcopenshell.util.constraint
|
| 22 |
+
import ifcopenshell.util.date
|
| 23 |
+
import ifcopenshell.util.element
|
| 24 |
+
import ifcopenshell.util.resource
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
def calculate_resource_usage(file: ifcopenshell.file, resource: ifcopenshell.entity_instance) -> None:
|
| 28 |
+
"""Calculates the number of resources required to perform scheduled work on a task.
|
| 29 |
+
|
| 30 |
+
:param resource: The IfcConstructionResource to calculate the usage for.
|
| 31 |
+
:return: None
|
| 32 |
+
"""
|
| 33 |
+
|
| 34 |
+
if ifcopenshell.util.constraint.is_attribute_locked(resource, "Usage.ScheduleUsage"):
|
| 35 |
+
return
|
| 36 |
+
if not resource.Usage or not resource.Usage.ScheduleWork:
|
| 37 |
+
return
|
| 38 |
+
|
| 39 |
+
task = ifcopenshell.util.resource.get_task_assignments(resource)
|
| 40 |
+
if not task or not task.TaskTime:
|
| 41 |
+
return
|
| 42 |
+
|
| 43 |
+
if not task.TaskTime.DurationType or task.TaskTime.DurationType == "WORKTIME":
|
| 44 |
+
hours_per_day = 8
|
| 45 |
+
else:
|
| 46 |
+
hours_per_day = 24
|
| 47 |
+
|
| 48 |
+
task_duration = ifcopenshell.util.date.ifc2datetime(task.TaskTime.ScheduleDuration)
|
| 49 |
+
seconds = task_duration.days * hours_per_day * 60 * 60
|
| 50 |
+
seconds += task_duration.seconds
|
| 51 |
+
|
| 52 |
+
person_hours = ifcopenshell.util.date.ifc2datetime(resource.Usage.ScheduleWork)
|
| 53 |
+
|
| 54 |
+
required_resources = person_hours.total_seconds() / seconds
|
| 55 |
+
resource.Usage.ScheduleUsage = float(required_resources)
|
data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/resource/calculate_resource_work.py
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# IfcOpenShell - IFC toolkit and geometry engine
|
| 2 |
+
# Copyright (C) 2021 Dion Moult <dion@thinkmoult.com>
|
| 3 |
+
#
|
| 4 |
+
# This file is part of IfcOpenShell.
|
| 5 |
+
#
|
| 6 |
+
# IfcOpenShell is free software: you can redistribute it and/or modify
|
| 7 |
+
# it under the terms of the GNU Lesser General Public License as published by
|
| 8 |
+
# the Free Software Foundation, either version 3 of the License, or
|
| 9 |
+
# (at your option) any later version.
|
| 10 |
+
#
|
| 11 |
+
# IfcOpenShell is distributed in the hope that it will be useful,
|
| 12 |
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 13 |
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 14 |
+
# GNU Lesser General Public License for more details.
|
| 15 |
+
#
|
| 16 |
+
# You should have received a copy of the GNU Lesser General Public License
|
| 17 |
+
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
|
| 18 |
+
|
| 19 |
+
import ifcopenshell.api.resource
|
| 20 |
+
import ifcopenshell.util.constraint
|
| 21 |
+
import ifcopenshell.util.date
|
| 22 |
+
import ifcopenshell.util.element
|
| 23 |
+
import ifcopenshell.util.resource
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
def calculate_resource_work(file: ifcopenshell.file, resource: ifcopenshell.entity_instance) -> None:
|
| 27 |
+
"""Calculates the work that a resource is used for
|
| 28 |
+
|
| 29 |
+
This is an unofficial parametric calculation that may be done on a
|
| 30 |
+
resource based on careful analysis of the relationships between the
|
| 31 |
+
costing, scheduling, and resource domains in IFC.
|
| 32 |
+
|
| 33 |
+
A resource may store a productivity rate in a property set called
|
| 34 |
+
EPset_Productivity. This stores three properties:
|
| 35 |
+
|
| 36 |
+
* BaseQuantityConsumed - a duration that the resource is consumed for.
|
| 37 |
+
* BaseQuantityProducedName - what quantity the resource can produce,
|
| 38 |
+
such as area or volume.
|
| 39 |
+
* BaseQuantityProducedValue - what value of that quantity the resource
|
| 40 |
+
can produce during that duration.
|
| 41 |
+
|
| 42 |
+
For example, a labour or equipment resource might produce 100m3 of
|
| 43 |
+
NetVolume every day (i.e. 8 hours are consumed).
|
| 44 |
+
|
| 45 |
+
Then, if a resource is assigned to a construction task, and that
|
| 46 |
+
construction task is assigned to concrete slabs totalling 200m3, we can
|
| 47 |
+
calculate that the resource consumes 16 hours of work.
|
| 48 |
+
|
| 49 |
+
This calculated work is stored against the resource as scheduled work
|
| 50 |
+
under the resource time data.
|
| 51 |
+
|
| 52 |
+
:param resource: The IfcConstructionResource that you want to calculate
|
| 53 |
+
the work performed.
|
| 54 |
+
:return None:
|
| 55 |
+
"""
|
| 56 |
+
if ifcopenshell.util.constraint.is_attribute_locked(resource, "Usage.ScheduleWork"):
|
| 57 |
+
return
|
| 58 |
+
amount_worked = ifcopenshell.util.resource.get_resource_required_work(resource)
|
| 59 |
+
if not amount_worked:
|
| 60 |
+
return
|
| 61 |
+
if not resource.Usage:
|
| 62 |
+
ifcopenshell.api.resource.add_resource_time(file, resource=resource)
|
| 63 |
+
resource.Usage.ScheduleWork = amount_worked
|
data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/resource/edit_resource.py
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# IfcOpenShell - IFC toolkit and geometry engine
|
| 2 |
+
# Copyright (C) 2021 Dion Moult <dion@thinkmoult.com>
|
| 3 |
+
#
|
| 4 |
+
# This file is part of IfcOpenShell.
|
| 5 |
+
#
|
| 6 |
+
# IfcOpenShell is free software: you can redistribute it and/or modify
|
| 7 |
+
# it under the terms of the GNU Lesser General Public License as published by
|
| 8 |
+
# the Free Software Foundation, either version 3 of the License, or
|
| 9 |
+
# (at your option) any later version.
|
| 10 |
+
#
|
| 11 |
+
# IfcOpenShell is distributed in the hope that it will be useful,
|
| 12 |
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 13 |
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 14 |
+
# GNU Lesser General Public License for more details.
|
| 15 |
+
#
|
| 16 |
+
# You should have received a copy of the GNU Lesser General Public License
|
| 17 |
+
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
|
| 18 |
+
import ifcopenshell
|
| 19 |
+
from typing import Any
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
def edit_resource(file: ifcopenshell.file, resource: ifcopenshell.entity_instance, attributes: dict[str, Any]) -> None:
|
| 23 |
+
"""Edits the attributes of an IfcResource
|
| 24 |
+
|
| 25 |
+
For more information about the attributes and data types of an
|
| 26 |
+
IfcResource, consult the IFC documentation.
|
| 27 |
+
|
| 28 |
+
:param resource: The IfcResource entity you want to edit
|
| 29 |
+
:param attributes: a dictionary of attribute names and values.
|
| 30 |
+
:return: None
|
| 31 |
+
|
| 32 |
+
Example:
|
| 33 |
+
|
| 34 |
+
.. code:: python
|
| 35 |
+
|
| 36 |
+
# Add our own crew
|
| 37 |
+
crew = ifcopenshell.api.resource.add_resource(model, ifc_class="IfcCrewResource")
|
| 38 |
+
|
| 39 |
+
# Change the name of the resource to "Zone A Crew"
|
| 40 |
+
ifcopenshell.api.resource.edit_resource(model, resource=resource, attributes={"Name": "Foo"})
|
| 41 |
+
"""
|
| 42 |
+
for name, value in attributes.items():
|
| 43 |
+
setattr(resource, name, value)
|
data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/resource/edit_resource_quantity.py
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# IfcOpenShell - IFC toolkit and geometry engine
|
| 2 |
+
# Copyright (C) 2021 Dion Moult <dion@thinkmoult.com>
|
| 3 |
+
#
|
| 4 |
+
# This file is part of IfcOpenShell.
|
| 5 |
+
#
|
| 6 |
+
# IfcOpenShell is free software: you can redistribute it and/or modify
|
| 7 |
+
# it under the terms of the GNU Lesser General Public License as published by
|
| 8 |
+
# the Free Software Foundation, either version 3 of the License, or
|
| 9 |
+
# (at your option) any later version.
|
| 10 |
+
#
|
| 11 |
+
# IfcOpenShell is distributed in the hope that it will be useful,
|
| 12 |
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 13 |
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 14 |
+
# GNU Lesser General Public License for more details.
|
| 15 |
+
#
|
| 16 |
+
# You should have received a copy of the GNU Lesser General Public License
|
| 17 |
+
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
|
| 18 |
+
import ifcopenshell
|
| 19 |
+
from typing import Any
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
def edit_resource_quantity(
|
| 23 |
+
file: ifcopenshell.file, physical_quantity: ifcopenshell.entity_instance, attributes: dict[str, Any]
|
| 24 |
+
) -> None:
|
| 25 |
+
"""Edits the attributes of an IFC quantity
|
| 26 |
+
|
| 27 |
+
For more information about the attributes and data types of an
|
| 28 |
+
IfC quantity, consult the IFC documentation.
|
| 29 |
+
|
| 30 |
+
:param physical_quantity: The IfC quantity entity you want to edit
|
| 31 |
+
:param attributes: a dictionary of attribute names and values.
|
| 32 |
+
:return: None
|
| 33 |
+
|
| 34 |
+
Example:
|
| 35 |
+
|
| 36 |
+
.. code:: python
|
| 37 |
+
|
| 38 |
+
# Add our own crew
|
| 39 |
+
crew = ifcopenshell.api.resource.add_resource(model, ifc_class="IfcCrewResource")
|
| 40 |
+
|
| 41 |
+
# Add some labour to our crew.
|
| 42 |
+
labour = ifcopenshell.api.resource.add_resource(model,
|
| 43 |
+
parent_resource=crew, ifc_class="IfcLaborResource")
|
| 44 |
+
|
| 45 |
+
# Labour resource is quantified in terms of time.
|
| 46 |
+
ifcopenshell.api.resource.add_resource_quantity(model,
|
| 47 |
+
resource=labour, ifc_class="IfcQuantityTime")
|
| 48 |
+
|
| 49 |
+
# Store the time used in hours
|
| 50 |
+
ifcopenshell.api.resource.edit_resource_quantity(model,
|
| 51 |
+
physical_quantity=time, attributes={"TimeValue": 8.0})
|
| 52 |
+
"""
|
| 53 |
+
for name, value in attributes.items():
|
| 54 |
+
setattr(physical_quantity, name, value)
|
data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/resource/edit_resource_time.py
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# IfcOpenShell - IFC toolkit and geometry engine
|
| 2 |
+
# Copyright (C) 2021 Dion Moult <dion@thinkmoult.com>
|
| 3 |
+
#
|
| 4 |
+
# This file is part of IfcOpenShell.
|
| 5 |
+
#
|
| 6 |
+
# IfcOpenShell is free software: you can redistribute it and/or modify
|
| 7 |
+
# it under the terms of the GNU Lesser General Public License as published by
|
| 8 |
+
# the Free Software Foundation, either version 3 of the License, or
|
| 9 |
+
# (at your option) any later version.
|
| 10 |
+
#
|
| 11 |
+
# IfcOpenShell is distributed in the hope that it will be useful,
|
| 12 |
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 13 |
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 14 |
+
# GNU Lesser General Public License for more details.
|
| 15 |
+
#
|
| 16 |
+
# You should have received a copy of the GNU Lesser General Public License
|
| 17 |
+
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
|
| 18 |
+
|
| 19 |
+
import ifcopenshell
|
| 20 |
+
import ifcopenshell.api.sequence
|
| 21 |
+
import ifcopenshell.util.constraint
|
| 22 |
+
import ifcopenshell.util.date
|
| 23 |
+
import ifcopenshell.util.resource
|
| 24 |
+
from typing import Any
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
def edit_resource_time(
|
| 28 |
+
file: ifcopenshell.file, resource_time: ifcopenshell.entity_instance, attributes: dict[str, Any]
|
| 29 |
+
) -> None:
|
| 30 |
+
"""Edits the attributes of an IfcResourceTime
|
| 31 |
+
|
| 32 |
+
For more information about the attributes and data types of an
|
| 33 |
+
IfcResourceTime, consult the IFC documentation.
|
| 34 |
+
|
| 35 |
+
:param resource_time: The IfcResourceTime entity you want to edit
|
| 36 |
+
:param attributes: a dictionary of attribute names and values.
|
| 37 |
+
:return: None
|
| 38 |
+
|
| 39 |
+
Example:
|
| 40 |
+
|
| 41 |
+
.. code:: python
|
| 42 |
+
|
| 43 |
+
# Add our own crew
|
| 44 |
+
crew = ifcopenshell.api.resource.add_resource(model, ifc_class="IfcCrewResource")
|
| 45 |
+
|
| 46 |
+
# Add some labour to our crew.
|
| 47 |
+
labour = ifcopenshell.api.resource.add_resource(model,
|
| 48 |
+
parent_resource=crew, ifc_class="IfcLaborResource")
|
| 49 |
+
|
| 50 |
+
# Labour resource is quantified in terms of time.
|
| 51 |
+
ifcopenshell.api.resource.add_resource_quantity(model,
|
| 52 |
+
resource=labour, ifc_class="IfcQuantityTime")
|
| 53 |
+
|
| 54 |
+
# Store the unit time used in hours
|
| 55 |
+
ifcopenshell.api.resource.edit_resource_quantity(model,
|
| 56 |
+
physical_quantity=time, attributes={"TimeValue": 8.0})
|
| 57 |
+
|
| 58 |
+
# Let's imagine we've used the resource for 2 days.
|
| 59 |
+
time = ifcopenshell.api.resource.add_resource_time(model, resource=labour)
|
| 60 |
+
ifcopenshell.api.resource.edit_resource_time(model,
|
| 61 |
+
resource_time=time, attributes={"ScheduleWork": "P16H"})
|
| 62 |
+
"""
|
| 63 |
+
usecase = Usecase()
|
| 64 |
+
usecase.file = file
|
| 65 |
+
return usecase.execute(resource_time, attributes)
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
class Usecase:
|
| 69 |
+
file: ifcopenshell.file
|
| 70 |
+
|
| 71 |
+
def execute(self, resource_time: ifcopenshell.entity_instance, attributes: dict[str, Any]) -> None:
|
| 72 |
+
resource = self.get_resource(resource_time)
|
| 73 |
+
|
| 74 |
+
# If the user specifies both an end date and a duration, the duration takes priority
|
| 75 |
+
if attributes.get("ScheduleWork", None) and "ScheduleFinish" in attributes.keys():
|
| 76 |
+
del attributes["ScheduleFinish"]
|
| 77 |
+
if attributes.get("ActualWork", None) and "ActualFinish" in attributes.keys():
|
| 78 |
+
del attributes["ActualFinish"]
|
| 79 |
+
|
| 80 |
+
for name, value in attributes.items():
|
| 81 |
+
metrics = ifcopenshell.util.constraint.get_metric_constraints(resource, "Usage." + name)
|
| 82 |
+
if metrics and ifcopenshell.util.constraint.is_hard_constraint(metrics[0]):
|
| 83 |
+
continue
|
| 84 |
+
if value:
|
| 85 |
+
if "Start" in name or "Finish" in name or name == "StatusTime":
|
| 86 |
+
value = ifcopenshell.util.date.datetime2ifc(value, "IfcDateTime")
|
| 87 |
+
elif name == "ScheduleWork" or name == "ActualWork" or name == "RemainingTime":
|
| 88 |
+
value = ifcopenshell.util.date.datetime2ifc(value, "IfcDuration")
|
| 89 |
+
setattr(resource_time, name, value)
|
| 90 |
+
if name == "ScheduleUsage" and ifcopenshell.util.constraint.get_metric_constraints(
|
| 91 |
+
resource, "Usage.ScheduleWork"
|
| 92 |
+
):
|
| 93 |
+
task = ifcopenshell.util.resource.get_task_assignments(resource)
|
| 94 |
+
if task:
|
| 95 |
+
ifcopenshell.api.sequence.calculate_task_duration(self.file, task=task)
|
| 96 |
+
|
| 97 |
+
def get_resource(self, resource_time: ifcopenshell.entity_instance) -> ifcopenshell.entity_instance:
|
| 98 |
+
return next(e for e in self.file.get_inverse(resource_time) if e.is_a("IfcResource"))
|
data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/resource/remove_resource.py
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# IfcOpenShell - IFC toolkit and geometry engine
|
| 2 |
+
# Copyright (C) 2021-2022, Dion Moult <dion@thinkmoult.com>, Yassine Oualid <yassine@sigmadimensions.com>
|
| 3 |
+
#
|
| 4 |
+
# This file is part of IfcOpenShell.
|
| 5 |
+
#
|
| 6 |
+
# IfcOpenShell is free software: you can redistribute it and/or modify
|
| 7 |
+
# it under the terms of the GNU Lesser General Public License as published by
|
| 8 |
+
# the Free Software Foundation, either version 3 of the License, or
|
| 9 |
+
# (at your option) any later version.
|
| 10 |
+
#
|
| 11 |
+
# IfcOpenShell is distributed in the hope that it will be useful,
|
| 12 |
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 13 |
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 14 |
+
# GNU Lesser General Public License for more details.
|
| 15 |
+
#
|
| 16 |
+
# You should have received a copy of the GNU Lesser General Public License
|
| 17 |
+
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
|
| 18 |
+
|
| 19 |
+
import ifcopenshell
|
| 20 |
+
import ifcopenshell.api.resource
|
| 21 |
+
import ifcopenshell.util.element
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
def remove_resource(file: ifcopenshell.file, resource: ifcopenshell.entity_instance) -> None:
|
| 25 |
+
"""Removes a resource and all relationships
|
| 26 |
+
|
| 27 |
+
Example:
|
| 28 |
+
|
| 29 |
+
.. code:: python
|
| 30 |
+
|
| 31 |
+
# Add our own crew
|
| 32 |
+
crew = ifcopenshell.api.resource.add_resource(model, ifc_class="IfcCrewResource")
|
| 33 |
+
|
| 34 |
+
# Fire our crew
|
| 35 |
+
ifcopenshell.api.resource.remove_resource(model, resource=crew)
|
| 36 |
+
"""
|
| 37 |
+
settings = {"resource": resource}
|
| 38 |
+
|
| 39 |
+
def remove_consider_history(root: ifcopenshell.entity_instance) -> None:
|
| 40 |
+
history = root.OwnerHistory
|
| 41 |
+
file.remove(root)
|
| 42 |
+
if history:
|
| 43 |
+
ifcopenshell.util.element.remove_deep2(file, history)
|
| 44 |
+
|
| 45 |
+
# TODO: review deep purge
|
| 46 |
+
for inverse in file.get_inverse(settings["resource"]):
|
| 47 |
+
if inverse.is_a("IfcRelNests"):
|
| 48 |
+
if inverse.RelatingObject == settings["resource"]:
|
| 49 |
+
# Remove rel before iteration over objects
|
| 50 |
+
# to simplify removal of nested resources and avoid crashes.
|
| 51 |
+
related_objects = inverse.RelatedObjects
|
| 52 |
+
remove_consider_history(inverse)
|
| 53 |
+
for related_object in related_objects:
|
| 54 |
+
ifcopenshell.api.resource.remove_resource(file, resource=related_object)
|
| 55 |
+
elif inverse.RelatedObjects == (resource,):
|
| 56 |
+
remove_consider_history(inverse)
|
| 57 |
+
|
| 58 |
+
elif inverse.is_a("IfcRelAssignsToControl"):
|
| 59 |
+
if len(inverse.RelatedObjects) == 1:
|
| 60 |
+
remove_consider_history(inverse)
|
| 61 |
+
else:
|
| 62 |
+
related_objects = list(inverse.RelatedObjects)
|
| 63 |
+
related_objects.remove(settings["resource"])
|
| 64 |
+
inverse.RelatedObjects = related_objects
|
| 65 |
+
elif inverse.is_a("IfcRelAssignsToResource"):
|
| 66 |
+
if inverse.RelatingResource == settings["resource"]:
|
| 67 |
+
for related_object in inverse.RelatedObjects:
|
| 68 |
+
ifcopenshell.api.resource.unassign_resource(
|
| 69 |
+
file, related_object=related_object, relating_resource=settings["resource"]
|
| 70 |
+
)
|
| 71 |
+
elif inverse.RelatedObjects == (resource,):
|
| 72 |
+
remove_consider_history(inverse)
|
| 73 |
+
# Usage was added in IFC4.
|
| 74 |
+
if usage := getattr(settings["resource"], "Usage", None):
|
| 75 |
+
file.remove(usage)
|
| 76 |
+
if settings["resource"].BaseQuantity:
|
| 77 |
+
ifcopenshell.api.resource.remove_resource_quantity(file, resource=settings["resource"])
|
| 78 |
+
remove_consider_history(resource)
|
data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/resource/remove_resource_quantity.py
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# IfcOpenShell - IFC toolkit and geometry engine
|
| 2 |
+
# Copyright (C) 2021 Dion Moult <dion@thinkmoult.com>
|
| 3 |
+
#
|
| 4 |
+
# This file is part of IfcOpenShell.
|
| 5 |
+
#
|
| 6 |
+
# IfcOpenShell is free software: you can redistribute it and/or modify
|
| 7 |
+
# it under the terms of the GNU Lesser General Public License as published by
|
| 8 |
+
# the Free Software Foundation, either version 3 of the License, or
|
| 9 |
+
# (at your option) any later version.
|
| 10 |
+
#
|
| 11 |
+
# IfcOpenShell is distributed in the hope that it will be useful,
|
| 12 |
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 13 |
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 14 |
+
# GNU Lesser General Public License for more details.
|
| 15 |
+
#
|
| 16 |
+
# You should have received a copy of the GNU Lesser General Public License
|
| 17 |
+
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
|
| 18 |
+
|
| 19 |
+
import ifcopenshell.util.element
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
def remove_resource_quantity(file: ifcopenshell.file, resource: ifcopenshell.entity_instance) -> None:
|
| 23 |
+
"""Removes the base quantity of a resource
|
| 24 |
+
|
| 25 |
+
:param resource: The IfcConstructionResource to remove the quantity from.
|
| 26 |
+
:return: None
|
| 27 |
+
|
| 28 |
+
Example:
|
| 29 |
+
|
| 30 |
+
.. code:: python
|
| 31 |
+
|
| 32 |
+
# Add our own crew
|
| 33 |
+
crew = ifcopenshell.api.resource.add_resource(model, ifc_class="IfcCrewResource")
|
| 34 |
+
|
| 35 |
+
# Add some labour to our crew.
|
| 36 |
+
labour = ifcopenshell.api.resource.add_resource(model,
|
| 37 |
+
parent_resource=crew, ifc_class="IfcLaborResource")
|
| 38 |
+
|
| 39 |
+
# Labour resource is quantified in terms of time.
|
| 40 |
+
ifcopenshell.api.resource.add_resource_quantity(model,
|
| 41 |
+
resource=labour, ifc_class="IfcQuantityTime")
|
| 42 |
+
|
| 43 |
+
# Let's say we only want to store the resource but no quantities,
|
| 44 |
+
# let's clean up our mess and remove the quantity.
|
| 45 |
+
ifcopenshell.api.resource.remove_resource_quantity(model, resource=labour)
|
| 46 |
+
"""
|
| 47 |
+
old_quantity = resource.BaseQuantity
|
| 48 |
+
resource.BaseQuantity = None
|
| 49 |
+
if old_quantity:
|
| 50 |
+
ifcopenshell.util.element.remove_deep(file, old_quantity)
|
data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/resource/unassign_resource.py
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# IfcOpenShell - IFC toolkit and geometry engine
|
| 2 |
+
# Copyright (C) 2021 Dion Moult <dion@thinkmoult.com>
|
| 3 |
+
#
|
| 4 |
+
# This file is part of IfcOpenShell.
|
| 5 |
+
#
|
| 6 |
+
# IfcOpenShell is free software: you can redistribute it and/or modify
|
| 7 |
+
# it under the terms of the GNU Lesser General Public License as published by
|
| 8 |
+
# the Free Software Foundation, either version 3 of the License, or
|
| 9 |
+
# (at your option) any later version.
|
| 10 |
+
#
|
| 11 |
+
# IfcOpenShell is distributed in the hope that it will be useful,
|
| 12 |
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 13 |
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 14 |
+
# GNU Lesser General Public License for more details.
|
| 15 |
+
#
|
| 16 |
+
# You should have received a copy of the GNU Lesser General Public License
|
| 17 |
+
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
|
| 18 |
+
|
| 19 |
+
import ifcopenshell
|
| 20 |
+
import ifcopenshell.api.owner
|
| 21 |
+
import ifcopenshell.util.element
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
def unassign_resource(
|
| 25 |
+
file: ifcopenshell.file,
|
| 26 |
+
relating_resource: ifcopenshell.entity_instance,
|
| 27 |
+
related_object: ifcopenshell.entity_instance,
|
| 28 |
+
) -> None:
|
| 29 |
+
"""Removes the relationship between a resource and object
|
| 30 |
+
|
| 31 |
+
:param relating_resource: The IfcResource to assign the object to.
|
| 32 |
+
:param related_object: The IfcProduct or IfcActor to assign to the
|
| 33 |
+
object.
|
| 34 |
+
:return: None
|
| 35 |
+
|
| 36 |
+
Example:
|
| 37 |
+
|
| 38 |
+
.. code:: python
|
| 39 |
+
|
| 40 |
+
# Add our own crew
|
| 41 |
+
crew = ifcopenshell.api.resource.add_resource(model, ifc_class="IfcCrewResource")
|
| 42 |
+
|
| 43 |
+
# Add some a tower crane to our crew.
|
| 44 |
+
crane = ifcopenshell.api.resource.add_resource(model,
|
| 45 |
+
parent_resource=crew, ifc_class="IfcConstructionEquipmentResource", name="Tower Crane 01")
|
| 46 |
+
|
| 47 |
+
# Our tower crane will be placed via this physical product.
|
| 48 |
+
product = ifcopenshell.api.root.create_entity(model,
|
| 49 |
+
ifc_class="IfcBuildingElementProxy", predefined_type="CRANE")
|
| 50 |
+
|
| 51 |
+
# Let's assign our crane to the resource. The crane now represents
|
| 52 |
+
# the resource.
|
| 53 |
+
ifcopenshell.api.resource.assign_resource(model,
|
| 54 |
+
relating_resource=crane, related_object=product)
|
| 55 |
+
|
| 56 |
+
# Undo it.
|
| 57 |
+
ifcopenshell.api.resource.unassign_resource(model,
|
| 58 |
+
relating_resource=crane, related_object=product)
|
| 59 |
+
"""
|
| 60 |
+
for rel in related_object.HasAssignments or []:
|
| 61 |
+
if not rel.is_a("IfcRelAssignsToResource") or rel.RelatingResource != relating_resource:
|
| 62 |
+
continue
|
| 63 |
+
if len(rel.RelatedObjects) == 1:
|
| 64 |
+
history = rel.OwnerHistory
|
| 65 |
+
file.remove(rel)
|
| 66 |
+
if history:
|
| 67 |
+
ifcopenshell.util.element.remove_deep2(file, history)
|
| 68 |
+
return
|
| 69 |
+
related_objects = list(rel.RelatedObjects)
|
| 70 |
+
related_objects.remove(related_object)
|
| 71 |
+
rel.RelatedObjects = related_objects
|
| 72 |
+
ifcopenshell.api.owner.update_owner_history(file, element=rel)
|
data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/root/__init__.py
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# IfcOpenShell - IFC toolkit and geometry engine
|
| 2 |
+
# Copyright (C) 2022 Dion Moult <dion@thinkmoult.com>
|
| 3 |
+
#
|
| 4 |
+
# This file is part of IfcOpenShell.
|
| 5 |
+
#
|
| 6 |
+
# IfcOpenShell is free software: you can redistribute it and/or modify
|
| 7 |
+
# it under the terms of the GNU Lesser General Public License as published by
|
| 8 |
+
# the Free Software Foundation, either version 3 of the License, or
|
| 9 |
+
# (at your option) any later version.
|
| 10 |
+
#
|
| 11 |
+
# IfcOpenShell is distributed in the hope that it will be useful,
|
| 12 |
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 13 |
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 14 |
+
# GNU Lesser General Public License for more details.
|
| 15 |
+
#
|
| 16 |
+
# You should have received a copy of the GNU Lesser General Public License
|
| 17 |
+
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
|
| 18 |
+
|
| 19 |
+
"""Create, copy, or remove physical elements such as walls, doors, slabs, etc
|
| 20 |
+
|
| 21 |
+
This is one of the most used API modules and should be used any time you want
|
| 22 |
+
to create, remove, copy, or change a physical or spatial element. See
|
| 23 |
+
:func:`create_entity` to get started.
|
| 24 |
+
|
| 25 |
+
This module should also be used to create types. To then associate types with
|
| 26 |
+
elements, see :mod:`ifcopenshell.api.type`.
|
| 27 |
+
"""
|
| 28 |
+
|
| 29 |
+
from .. import wrap_usecases
|
| 30 |
+
from .copy_class import copy_class
|
| 31 |
+
from .create_entity import create_entity
|
| 32 |
+
from .reassign_class import reassign_class
|
| 33 |
+
from .remove_product import remove_product
|
| 34 |
+
|
| 35 |
+
wrap_usecases(__path__, __name__)
|
| 36 |
+
|
| 37 |
+
__all__ = [
|
| 38 |
+
"copy_class",
|
| 39 |
+
"create_entity",
|
| 40 |
+
"reassign_class",
|
| 41 |
+
"remove_product",
|
| 42 |
+
]
|
data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/root/copy_class.py
ADDED
|
@@ -0,0 +1,194 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# IfcOpenShell - IFC toolkit and geometry engine
|
| 2 |
+
# Copyright (C) 2021 Dion Moult <dion@thinkmoult.com>
|
| 3 |
+
#
|
| 4 |
+
# This file is part of IfcOpenShell.
|
| 5 |
+
#
|
| 6 |
+
# IfcOpenShell is free software: you can redistribute it and/or modify
|
| 7 |
+
# it under the terms of the GNU Lesser General Public License as published by
|
| 8 |
+
# the Free Software Foundation, either version 3 of the License, or
|
| 9 |
+
# (at your option) any later version.
|
| 10 |
+
#
|
| 11 |
+
# IfcOpenShell is distributed in the hope that it will be useful,
|
| 12 |
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 13 |
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 14 |
+
# GNU Lesser General Public License for more details.
|
| 15 |
+
#
|
| 16 |
+
# You should have received a copy of the GNU Lesser General Public License
|
| 17 |
+
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
|
| 18 |
+
|
| 19 |
+
import ifcopenshell
|
| 20 |
+
import ifcopenshell.api.material
|
| 21 |
+
import ifcopenshell.api.root
|
| 22 |
+
import ifcopenshell.api.system
|
| 23 |
+
import ifcopenshell.api.geometry
|
| 24 |
+
import ifcopenshell.util.system
|
| 25 |
+
import ifcopenshell.util.element
|
| 26 |
+
import ifcopenshell.util.placement
|
| 27 |
+
from typing import Any
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
def copy_class(file: ifcopenshell.file, product: ifcopenshell.entity_instance) -> ifcopenshell.entity_instance:
|
| 31 |
+
"""Copies a product
|
| 32 |
+
|
| 33 |
+
The following relationships are also duplicated:
|
| 34 |
+
|
| 35 |
+
* The copy will have the same object placement coordinates as the
|
| 36 |
+
original.
|
| 37 |
+
* The copy will have duplicated property sets, properties, and quantities
|
| 38 |
+
* The copy will have all nested distribution ports copied too
|
| 39 |
+
* The copy will be part of the same aggregate
|
| 40 |
+
* The copy will be contained in the same spatial structure
|
| 41 |
+
* The copy, if it is an occurrence, will have the same type
|
| 42 |
+
* Voids are duplicated too
|
| 43 |
+
* The copy will have the same material as the original. Parametric
|
| 44 |
+
material set usages will be copied.
|
| 45 |
+
* The copy will be part of the same groups as the original.
|
| 46 |
+
|
| 47 |
+
Be warned that:
|
| 48 |
+
|
| 49 |
+
* Representations are _not_ copied. Copying representations is an
|
| 50 |
+
expensive operation so for now the user is responsible for handling
|
| 51 |
+
representations.
|
| 52 |
+
* Filled voids are not copied, as there is no guarantee that the filling
|
| 53 |
+
will also be copied.
|
| 54 |
+
* Path connectivity is not copied, as there is no guarantee that the
|
| 55 |
+
connections are still valid.
|
| 56 |
+
|
| 57 |
+
:param product: The IfcProduct to copy.
|
| 58 |
+
:return: The copied product
|
| 59 |
+
|
| 60 |
+
Example:
|
| 61 |
+
|
| 62 |
+
.. code:: python
|
| 63 |
+
|
| 64 |
+
# We have a wall
|
| 65 |
+
wall = ifcopenshell.api.root.create_entity(model, ifc_class="IfcWall")
|
| 66 |
+
|
| 67 |
+
# And now we have two
|
| 68 |
+
wall_copy = ifcopenshell.api.root.copy_class(model, product=wall)
|
| 69 |
+
"""
|
| 70 |
+
usecase = Usecase()
|
| 71 |
+
usecase.file = file
|
| 72 |
+
return usecase.execute(product)
|
| 73 |
+
|
| 74 |
+
|
| 75 |
+
class Usecase:
|
| 76 |
+
file: ifcopenshell.file
|
| 77 |
+
|
| 78 |
+
def execute(self, product: ifcopenshell.entity_instance) -> ifcopenshell.entity_instance:
|
| 79 |
+
result = ifcopenshell.util.element.copy(self.file, product)
|
| 80 |
+
self.copy_direct_attributes(result)
|
| 81 |
+
self.copy_indirect_attributes(product, result)
|
| 82 |
+
return result
|
| 83 |
+
|
| 84 |
+
def copy_direct_attributes(self, to_element: ifcopenshell.entity_instance) -> None:
|
| 85 |
+
self.remove_representations(to_element)
|
| 86 |
+
self.copy_object_placements(to_element)
|
| 87 |
+
self.copy_psets(to_element)
|
| 88 |
+
|
| 89 |
+
def copy_indirect_attributes(
|
| 90 |
+
self, from_element: ifcopenshell.entity_instance, to_element: ifcopenshell.entity_instance
|
| 91 |
+
) -> None:
|
| 92 |
+
for inverse in self.file.get_inverse(from_element):
|
| 93 |
+
if inverse.is_a("IfcRelDefinesByProperties"):
|
| 94 |
+
# Properties must not be shared between objects for convenience of authoring
|
| 95 |
+
inverse = ifcopenshell.util.element.copy(self.file, inverse)
|
| 96 |
+
inverse.RelatedObjects = [to_element]
|
| 97 |
+
pset = ifcopenshell.util.element.copy_deep(self.file, inverse.RelatingPropertyDefinition)
|
| 98 |
+
inverse.RelatingPropertyDefinition = pset
|
| 99 |
+
elif (
|
| 100 |
+
inverse.is_a("IfcRelNests")
|
| 101 |
+
and inverse.RelatingObject == from_element
|
| 102 |
+
or inverse.is_a("IfcRelConnectsPortToElement")
|
| 103 |
+
and inverse.RelatedElement == from_element
|
| 104 |
+
):
|
| 105 |
+
# IfcRelConnectsPortToElement was used in IFC2X3
|
| 106 |
+
if inverse.is_a("IfcRelNests"):
|
| 107 |
+
ports = [e for e in inverse.RelatedObjects if e.is_a("IfcDistributionPort")]
|
| 108 |
+
else: # IfcRelConnectsPortToElement
|
| 109 |
+
ports = [inverse.RelatingPort]
|
| 110 |
+
if not ports:
|
| 111 |
+
continue
|
| 112 |
+
new_ports = [ifcopenshell.api.root.copy_class(self.file, product=p) for p in ports]
|
| 113 |
+
inverse = ifcopenshell.util.element.copy(self.file, inverse)
|
| 114 |
+
|
| 115 |
+
if inverse.is_a("IfcRelNests"):
|
| 116 |
+
inverse.RelatingObject = to_element
|
| 117 |
+
inverse.RelatedObjects = new_ports
|
| 118 |
+
else:
|
| 119 |
+
inverse.RelatedElement = to_element
|
| 120 |
+
inverse.RelatingPort = new_ports[0]
|
| 121 |
+
|
| 122 |
+
for port in new_ports:
|
| 123 |
+
ifcopenshell.api.system.unassign_port(self.file, element=from_element, port=port)
|
| 124 |
+
ifcopenshell.api.system.disconnect_port(self.file, port=port)
|
| 125 |
+
matrix = ifcopenshell.util.placement.get_local_placement(port.ObjectPlacement)
|
| 126 |
+
ifcopenshell.api.geometry.edit_object_placement(
|
| 127 |
+
self.file,
|
| 128 |
+
product=port,
|
| 129 |
+
matrix=matrix,
|
| 130 |
+
is_si=False,
|
| 131 |
+
should_transform_children=False,
|
| 132 |
+
)
|
| 133 |
+
elif inverse.is_a("IfcRelAggregates") and inverse.RelatingObject == from_element:
|
| 134 |
+
continue
|
| 135 |
+
elif inverse.is_a("IfcRelContainedInSpatialStructure") and inverse.RelatingStructure == from_element:
|
| 136 |
+
continue
|
| 137 |
+
elif inverse.is_a("IfcRelDefinesByType") and inverse.RelatingType == from_element:
|
| 138 |
+
continue
|
| 139 |
+
elif inverse.is_a("IfcRelVoidsElement") and inverse.RelatingBuildingElement == from_element:
|
| 140 |
+
opening = inverse.RelatedOpeningElement
|
| 141 |
+
# We don't copy filled openings, since there is no guarantee the filling is also copied
|
| 142 |
+
if not opening.is_a("IfcOpeningElement") or not opening.HasFillings:
|
| 143 |
+
new_opening = ifcopenshell.api.root.copy_class(self.file, product=opening)
|
| 144 |
+
new_opening.VoidsElements[0].RelatingBuildingElement = to_element
|
| 145 |
+
if new_opening.ObjectPlacement and new_opening.ObjectPlacement.is_a("IfcLocalPlacement"):
|
| 146 |
+
if to_element.ObjectPlacement:
|
| 147 |
+
new_opening.ObjectPlacement.PlacementRelTo = to_element.ObjectPlacement
|
| 148 |
+
# For now, we do copy opening representations
|
| 149 |
+
if opening.Representation:
|
| 150 |
+
new_opening.Representation = ifcopenshell.util.element.copy_deep(
|
| 151 |
+
self.file, opening.Representation, exclude=["IfcGeometricRepresentationContext"]
|
| 152 |
+
)
|
| 153 |
+
elif inverse.is_a("IfcRelFillsElement"):
|
| 154 |
+
continue
|
| 155 |
+
elif inverse.is_a("IfcRelConnectsPathElements"):
|
| 156 |
+
continue
|
| 157 |
+
elif inverse.is_a("IfcRelAssociatesMaterial") and "Usage" in inverse.RelatingMaterial.is_a():
|
| 158 |
+
inverse = ifcopenshell.util.element.copy(self.file, inverse)
|
| 159 |
+
inverse.RelatingMaterial = ifcopenshell.util.element.copy(self.file, inverse.RelatingMaterial)
|
| 160 |
+
inverse.RelatedObjects = [to_element]
|
| 161 |
+
elif inverse.is_a("IfcRelAssociatesMaterial") and "Set" in inverse.RelatingMaterial.is_a():
|
| 162 |
+
inverse = ifcopenshell.util.element.copy(self.file, inverse)
|
| 163 |
+
inverse.RelatingMaterial = ifcopenshell.api.material.copy_material(self.file, inverse.RelatingMaterial)
|
| 164 |
+
inverse.RelatedObjects = [to_element]
|
| 165 |
+
else:
|
| 166 |
+
for i, value in enumerate(inverse):
|
| 167 |
+
if value == from_element:
|
| 168 |
+
new_inverse = ifcopenshell.util.element.copy(self.file, inverse)
|
| 169 |
+
new_inverse[i] = to_element
|
| 170 |
+
elif isinstance(value, (tuple, list)) and from_element in value:
|
| 171 |
+
new_value = list(value)
|
| 172 |
+
new_value.append(to_element)
|
| 173 |
+
inverse[i] = new_value
|
| 174 |
+
|
| 175 |
+
def remove_representations(self, element: ifcopenshell.entity_instance) -> None:
|
| 176 |
+
if element.is_a("IfcProduct"):
|
| 177 |
+
element.Representation = None
|
| 178 |
+
elif element.is_a("IfcTypeProduct"):
|
| 179 |
+
element.RepresentationMaps = None
|
| 180 |
+
|
| 181 |
+
def copy_object_placements(self, element: ifcopenshell.entity_instance) -> None:
|
| 182 |
+
if not element.is_a("IfcProduct") or not element.ObjectPlacement:
|
| 183 |
+
return
|
| 184 |
+
element.ObjectPlacement = ifcopenshell.util.element.copy(self.file, element.ObjectPlacement)
|
| 185 |
+
element.ObjectPlacement.RelativePlacement = ifcopenshell.util.element.copy_deep(
|
| 186 |
+
self.file, element.ObjectPlacement.RelativePlacement
|
| 187 |
+
)
|
| 188 |
+
|
| 189 |
+
def copy_psets(self, element: ifcopenshell.entity_instance) -> None:
|
| 190 |
+
if not element.is_a("IfcTypeObject") or not element.HasPropertySets:
|
| 191 |
+
return
|
| 192 |
+
element.HasPropertySets = [
|
| 193 |
+
ifcopenshell.util.element.copy_deep(self.file, pset) for pset in element.HasPropertySets
|
| 194 |
+
]
|
data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/root/create_entity.py
ADDED
|
@@ -0,0 +1,139 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# IfcOpenShell - IFC toolkit and geometry engine
|
| 2 |
+
# Copyright (C) 2021 Dion Moult <dion@thinkmoult.com>
|
| 3 |
+
#
|
| 4 |
+
# This file is part of IfcOpenShell.
|
| 5 |
+
#
|
| 6 |
+
# IfcOpenShell is free software: you can redistribute it and/or modify
|
| 7 |
+
# it under the terms of the GNU Lesser General Public License as published by
|
| 8 |
+
# the Free Software Foundation, either version 3 of the License, or
|
| 9 |
+
# (at your option) any later version.
|
| 10 |
+
#
|
| 11 |
+
# IfcOpenShell is distributed in the hope that it will be useful,
|
| 12 |
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 13 |
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 14 |
+
# GNU Lesser General Public License for more details.
|
| 15 |
+
#
|
| 16 |
+
# You should have received a copy of the GNU Lesser General Public License
|
| 17 |
+
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
|
| 18 |
+
|
| 19 |
+
import ifcopenshell
|
| 20 |
+
import ifcopenshell.api.owner
|
| 21 |
+
import ifcopenshell.guid
|
| 22 |
+
from typing import Optional, Any
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
def create_entity(
|
| 26 |
+
file: ifcopenshell.file,
|
| 27 |
+
ifc_class: str = "IfcBuildingElementProxy",
|
| 28 |
+
predefined_type: Optional[str] = None,
|
| 29 |
+
name: Optional[str] = None,
|
| 30 |
+
) -> ifcopenshell.entity_instance:
|
| 31 |
+
"""Create a new rooted product
|
| 32 |
+
|
| 33 |
+
This is a critical function used to create almost any rooted product or
|
| 34 |
+
product type. If you want to create walls, spaces, buildings, wall
|
| 35 |
+
types, and so on, use this function.
|
| 36 |
+
|
| 37 |
+
Just specify the class you want to create, as well as the predefined
|
| 38 |
+
type and name. It will handle the storage of the predefined type and
|
| 39 |
+
check whether the predefined type is built-in or custom. It will also
|
| 40 |
+
generate a valid GlobalId and store ownership history. It will also
|
| 41 |
+
handle some edge cases for default validity where users might forget to
|
| 42 |
+
populate some mandatory attributes. For example, doors must define an
|
| 43 |
+
operation type but many people forget.
|
| 44 |
+
|
| 45 |
+
:param ifc_class: Any rooted IFC class.
|
| 46 |
+
:param predefined_type: Any built-in or user-defined predefined type that
|
| 47 |
+
is applicable to that IFC class. For user-defined predefined types
|
| 48 |
+
just enter in any value and the API will handle it automatically.
|
| 49 |
+
:param name: The name of the new element.
|
| 50 |
+
:return: The newly created element based on the specified IFC class.
|
| 51 |
+
|
| 52 |
+
Example:
|
| 53 |
+
|
| 54 |
+
.. code:: python
|
| 55 |
+
|
| 56 |
+
# We have a project.
|
| 57 |
+
ifcopenshell.api.root.create_entity(model, ifc_class="IfcProject")
|
| 58 |
+
|
| 59 |
+
# We have a building.
|
| 60 |
+
ifcopenshell.api.root.create_entity(model, ifc_class="IfcBuilding")
|
| 61 |
+
|
| 62 |
+
# We have a wall.
|
| 63 |
+
ifcopenshell.api.root.create_entity(model, ifc_class="IfcWall")
|
| 64 |
+
|
| 65 |
+
# We have a wall type.
|
| 66 |
+
ifcopenshell.api.root.create_entity(model, ifc_class="IfcWallType")
|
| 67 |
+
"""
|
| 68 |
+
usecase = Usecase()
|
| 69 |
+
usecase.file = file
|
| 70 |
+
return usecase.execute(ifc_class, predefined_type, name)
|
| 71 |
+
|
| 72 |
+
|
| 73 |
+
class Usecase:
|
| 74 |
+
file: ifcopenshell.file
|
| 75 |
+
|
| 76 |
+
def execute(
|
| 77 |
+
self, ifc_class: str, predefined_type: Optional[str] = None, name: Optional[str] = None
|
| 78 |
+
) -> ifcopenshell.entity_instance:
|
| 79 |
+
element = self.file.create_entity(
|
| 80 |
+
ifc_class,
|
| 81 |
+
**{
|
| 82 |
+
"GlobalId": ifcopenshell.guid.new(),
|
| 83 |
+
"OwnerHistory": ifcopenshell.api.owner.create_owner_history(self.file),
|
| 84 |
+
}
|
| 85 |
+
)
|
| 86 |
+
element.Name = name or None
|
| 87 |
+
if predefined_type:
|
| 88 |
+
if hasattr(element, "PredefinedType"):
|
| 89 |
+
try:
|
| 90 |
+
element.PredefinedType = predefined_type
|
| 91 |
+
except:
|
| 92 |
+
element.PredefinedType = "USERDEFINED"
|
| 93 |
+
if hasattr(element, "ObjectType"):
|
| 94 |
+
element.ObjectType = predefined_type
|
| 95 |
+
elif hasattr(element, "ElementType"):
|
| 96 |
+
element.ElementType = predefined_type
|
| 97 |
+
elif hasattr(element, "ProcessType"):
|
| 98 |
+
element.ProcessType = predefined_type
|
| 99 |
+
elif hasattr(element, "ObjectType"):
|
| 100 |
+
element.ObjectType = predefined_type
|
| 101 |
+
if self.file.schema == "IFC2X3":
|
| 102 |
+
self.handle_2x3_defaults(element)
|
| 103 |
+
else:
|
| 104 |
+
self.handle_4_defaults(element)
|
| 105 |
+
return element
|
| 106 |
+
|
| 107 |
+
def handle_2x3_defaults(self, element: ifcopenshell.entity_instance) -> None:
|
| 108 |
+
if element.is_a("IfcElementType"):
|
| 109 |
+
if hasattr(element, "PredefinedType") and not element.PredefinedType:
|
| 110 |
+
element.PredefinedType = "NOTDEFINED"
|
| 111 |
+
|
| 112 |
+
if element.is_a("IfcSpatialStructureElement"):
|
| 113 |
+
element.CompositionType = "ELEMENT"
|
| 114 |
+
elif element.is_a("IfcRoof"):
|
| 115 |
+
element.ShapeType = "NOTDEFINED"
|
| 116 |
+
elif element.is_a("IfcFurnitureType"):
|
| 117 |
+
element.AssemblyPlace = "NOTDEFINED"
|
| 118 |
+
elif element.is_a("IfcDoorStyle") or element.is_a("IfcWindowStyle"):
|
| 119 |
+
element.OperationType = "NOTDEFINED"
|
| 120 |
+
element.ConstructionType = "NOTDEFINED"
|
| 121 |
+
element.ParameterTakesPrecedence = False
|
| 122 |
+
element.Sizeable = False
|
| 123 |
+
|
| 124 |
+
def handle_4_defaults(self, element: ifcopenshell.entity_instance) -> None:
|
| 125 |
+
if element.is_a("IfcElementType"):
|
| 126 |
+
if hasattr(element, "PredefinedType") and not element.PredefinedType:
|
| 127 |
+
element.PredefinedType = "NOTDEFINED"
|
| 128 |
+
|
| 129 |
+
if element.file.schema == "IFC4" and (element.is_a("IfcDoorStyle") or element.is_a("IfcWindowStyle")):
|
| 130 |
+
element.OperationType = "NOTDEFINED"
|
| 131 |
+
element.ConstructionType = "NOTDEFINED"
|
| 132 |
+
element.ParameterTakesPrecedence = False
|
| 133 |
+
element.Sizeable = False
|
| 134 |
+
elif element.is_a("IfcDoorType"):
|
| 135 |
+
element.OperationType = "NOTDEFINED"
|
| 136 |
+
elif element.is_a("IfcWindowType"):
|
| 137 |
+
element.PartitioningType = "NOTDEFINED"
|
| 138 |
+
elif element.is_a("IfcFurnitureType"):
|
| 139 |
+
element.AssemblyPlace = "NOTDEFINED"
|
data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/root/reassign_class.py
ADDED
|
@@ -0,0 +1,236 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# IfcOpenShell - IFC toolkit and geometry engine
|
| 2 |
+
# Copyright (C) 2021 Dion Moult <dion@thinkmoult.com>
|
| 3 |
+
#
|
| 4 |
+
# This file is part of IfcOpenShell.
|
| 5 |
+
#
|
| 6 |
+
# IfcOpenShell is free software: you can redistribute it and/or modify
|
| 7 |
+
# it under the terms of the GNU Lesser General Public License as published by
|
| 8 |
+
# the Free Software Foundation, either version 3 of the License, or
|
| 9 |
+
# (at your option) any later version.
|
| 10 |
+
#
|
| 11 |
+
# IfcOpenShell is distributed in the hope that it will be useful,
|
| 12 |
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 13 |
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 14 |
+
# GNU Lesser General Public License for more details.
|
| 15 |
+
#
|
| 16 |
+
# You should have received a copy of the GNU Lesser General Public License
|
| 17 |
+
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
|
| 18 |
+
|
| 19 |
+
import ifcopenshell
|
| 20 |
+
import ifcopenshell.api.aggregate
|
| 21 |
+
import ifcopenshell.api.geometry
|
| 22 |
+
import ifcopenshell.api.pset
|
| 23 |
+
import ifcopenshell.api.spatial
|
| 24 |
+
import ifcopenshell.api.type
|
| 25 |
+
import ifcopenshell.guid
|
| 26 |
+
import ifcopenshell.util.representation
|
| 27 |
+
import ifcopenshell.util.type
|
| 28 |
+
import ifcopenshell.util.schema
|
| 29 |
+
import ifcopenshell.util.element
|
| 30 |
+
from typing import Optional, Union, Literal
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
def reassign_class(
|
| 34 |
+
file: ifcopenshell.file,
|
| 35 |
+
product: ifcopenshell.entity_instance,
|
| 36 |
+
ifc_class: str = "IfcBuildingElementProxy",
|
| 37 |
+
predefined_type: Optional[str] = None,
|
| 38 |
+
occurrence_class: Optional[str] = None,
|
| 39 |
+
) -> ifcopenshell.entity_instance:
|
| 40 |
+
"""Changes the class of a product
|
| 41 |
+
|
| 42 |
+
If you ever created a wall then realised it's meant to be something
|
| 43 |
+
else, this function lets you change the IFC class whilst retaining all
|
| 44 |
+
other geometry and relationships.
|
| 45 |
+
|
| 46 |
+
This is especially useful when dealing with poorly classified data from
|
| 47 |
+
proprietary software with limited IFC capabilities.
|
| 48 |
+
|
| 49 |
+
If you are reassigning a type, the occurrence classes are also
|
| 50 |
+
reassigned to maintain validity.
|
| 51 |
+
|
| 52 |
+
Vice versa, if you are reassigning an occurrence, the type is also
|
| 53 |
+
reassigned in IFC4 and up. In IFC2X3, this may not occur if the type
|
| 54 |
+
cannot be unambiguously derived, so you are required to manually check
|
| 55 |
+
this.
|
| 56 |
+
|
| 57 |
+
Reassigning type class to occurrence (and vice versa) is supported.
|
| 58 |
+
|
| 59 |
+
:param product: The IfcProduct that you want to change the class of.
|
| 60 |
+
:param ifc_class: The new IFC class you want to change it to.
|
| 61 |
+
:param predefined_type: In case you want to change the predefined type
|
| 62 |
+
too. User defined types are also allowed, just type what you want.
|
| 63 |
+
:param occurrence_class: IFC class to assign to occurrences in case
|
| 64 |
+
if provided ``ifc_class`` is IfcTypeProduct.
|
| 65 |
+
If omitted, class will be deduced automatically from the type.
|
| 66 |
+
Only really needed in IFC2X3, since in IFC4+ there is no ambiguity on
|
| 67 |
+
what class to assign to occurrences.
|
| 68 |
+
:return: The newly modified product.
|
| 69 |
+
|
| 70 |
+
Example:
|
| 71 |
+
|
| 72 |
+
.. code:: python
|
| 73 |
+
|
| 74 |
+
# We have a wall.
|
| 75 |
+
wall = ifcopenshell.api.root.create_entity(model, ifc_class="IfcWall")
|
| 76 |
+
|
| 77 |
+
# Oh, did I say wall? I meant slab.
|
| 78 |
+
slab = ifcopenshell.api.root.reassign_class(model, product=wall, ifc_class="IfcSlab")
|
| 79 |
+
|
| 80 |
+
# Warning: this will crash since wall doesn't exist any more.
|
| 81 |
+
print(wall) # Kaboom.
|
| 82 |
+
"""
|
| 83 |
+
usecase = Usecase()
|
| 84 |
+
usecase.file = file
|
| 85 |
+
return usecase.execute(product, ifc_class, predefined_type, occurrence_class)
|
| 86 |
+
|
| 87 |
+
|
| 88 |
+
class Usecase:
|
| 89 |
+
file: ifcopenshell.file
|
| 90 |
+
|
| 91 |
+
def execute(
|
| 92 |
+
self,
|
| 93 |
+
product: ifcopenshell.entity_instance,
|
| 94 |
+
ifc_class: str,
|
| 95 |
+
predefined_type: Union[str, None],
|
| 96 |
+
occurrence_class: Union[str, None],
|
| 97 |
+
) -> ifcopenshell.entity_instance:
|
| 98 |
+
self.occurrence_class = occurrence_class
|
| 99 |
+
was_type_product_before = product.is_a("IfcTypeProduct")
|
| 100 |
+
self.schema = schema = ifcopenshell.schema_by_name(self.file.schema)
|
| 101 |
+
is_type_product_after: bool
|
| 102 |
+
is_type_product_after = schema.declaration_by_name(ifc_class)._is("IfcTypeProduct")
|
| 103 |
+
|
| 104 |
+
if was_type_product_before == is_type_product_after:
|
| 105 |
+
return self.simple_reassignment(product, ifc_class, predefined_type)
|
| 106 |
+
|
| 107 |
+
switch_type = "occurrence_to_type" if is_type_product_after else "type_to_occurrence"
|
| 108 |
+
|
| 109 |
+
return self.switch_between_class_types(
|
| 110 |
+
product,
|
| 111 |
+
switch_type,
|
| 112 |
+
ifc_class,
|
| 113 |
+
predefined_type,
|
| 114 |
+
)
|
| 115 |
+
|
| 116 |
+
def switch_between_class_types(
|
| 117 |
+
self,
|
| 118 |
+
element: ifcopenshell.entity_instance,
|
| 119 |
+
switch_type: Literal["occurrence_to_type", "type_to_occurrence"],
|
| 120 |
+
ifc_class: str,
|
| 121 |
+
predefined_type: Union[str, None],
|
| 122 |
+
) -> ifcopenshell.entity_instance:
|
| 123 |
+
|
| 124 |
+
psets_to_reassign: list[ifcopenshell.entity_instance] = []
|
| 125 |
+
|
| 126 |
+
representations = list(ifcopenshell.util.representation.get_representations_iter(element))
|
| 127 |
+
for rep in representations:
|
| 128 |
+
if switch_type == "type_to_occurrence":
|
| 129 |
+
rep = ifcopenshell.util.representation.resolve_representation(rep)
|
| 130 |
+
ifcopenshell.api.geometry.unassign_representation(self.file, product=element, representation=rep)
|
| 131 |
+
|
| 132 |
+
if switch_type == "type_to_occurrence":
|
| 133 |
+
occurrences = ifcopenshell.util.element.get_types(element)
|
| 134 |
+
# Don't need to reassign as psets are linked to type directly, without rel.
|
| 135 |
+
psets_to_reassign = element.HasPropertySets or []
|
| 136 |
+
|
| 137 |
+
element = self.reassign_class(element, ifc_class, predefined_type)
|
| 138 |
+
ifcopenshell.api.type.unassign_type(self.file, occurrences)
|
| 139 |
+
|
| 140 |
+
else: # occurrence_to_type
|
| 141 |
+
element_type = ifcopenshell.util.element.get_type(element)
|
| 142 |
+
# Handle element type.
|
| 143 |
+
if element_type:
|
| 144 |
+
ifcopenshell.api.type.unassign_type(self.file, [element])
|
| 145 |
+
|
| 146 |
+
# Handle containers and aggregates.
|
| 147 |
+
if ifcopenshell.util.element.get_container(element):
|
| 148 |
+
ifcopenshell.api.spatial.unassign_container(self.file, [element])
|
| 149 |
+
elif ifcopenshell.util.element.get_aggregate(element):
|
| 150 |
+
ifcopenshell.api.aggregate.unassign_object(self.file, [element])
|
| 151 |
+
|
| 152 |
+
psets = ifcopenshell.util.element.get_psets(element)
|
| 153 |
+
for pset_name in psets:
|
| 154 |
+
pset = self.file.by_id(psets[pset_name]["id"])
|
| 155 |
+
psets_to_reassign.append(pset)
|
| 156 |
+
ifcopenshell.api.pset.unassign_pset(self.file, [element], pset)
|
| 157 |
+
|
| 158 |
+
element = self.reassign_class(element, ifc_class, predefined_type)
|
| 159 |
+
|
| 160 |
+
# Reassign psets.
|
| 161 |
+
for pset in psets_to_reassign:
|
| 162 |
+
ifcopenshell.api.pset.assign_pset(self.file, [element], pset)
|
| 163 |
+
|
| 164 |
+
# Reassign representations.
|
| 165 |
+
for rep in representations:
|
| 166 |
+
ifcopenshell.api.geometry.assign_representation(self.file, product=element, representation=rep)
|
| 167 |
+
|
| 168 |
+
# Keep IFC valid (PlacementForShapeRepresentation).
|
| 169 |
+
if switch_type == "type_to_occurrence" and representations:
|
| 170 |
+
ifcopenshell.api.geometry.edit_object_placement(self.file, product=element)
|
| 171 |
+
|
| 172 |
+
return element
|
| 173 |
+
|
| 174 |
+
def simple_reassignment(
|
| 175 |
+
self,
|
| 176 |
+
element: ifcopenshell.entity_instance,
|
| 177 |
+
ifc_class: str,
|
| 178 |
+
predefined_type: Union[str, None],
|
| 179 |
+
) -> ifcopenshell.entity_instance:
|
| 180 |
+
"""
|
| 181 |
+
Simple class reassignment doesn't involve changing class type.
|
| 182 |
+
|
| 183 |
+
E.g. IfcWindow (IfcProduct class) -> IfcWall (other IfcProduct class).
|
| 184 |
+
|
| 185 |
+
Changing class type (e.g. IfcWindowType -> IfcWindow) is more complex
|
| 186 |
+
as it requires to recreate some entities / assign them in different way
|
| 187 |
+
(e.g. representations, property sets and their rels).
|
| 188 |
+
"""
|
| 189 |
+
element = self.reassign_class(element, ifc_class, predefined_type)
|
| 190 |
+
if element.is_a("IfcTypeProduct"):
|
| 191 |
+
|
| 192 |
+
if self.occurrence_class:
|
| 193 |
+
occurrence_class = self.occurrence_class
|
| 194 |
+
else:
|
| 195 |
+
# NOTE: in theory we can skip reassignment in IFC2X3 in some cases
|
| 196 |
+
# e.g. if occurrence is IfcRoof and we're reassigning to IfcBuildingElementProxyType
|
| 197 |
+
# but currently type_to_entity_map doesn't completely match entity_to_type_map,
|
| 198 |
+
# see type.py for more details.
|
| 199 |
+
occurrence_class = next(
|
| 200 |
+
iter(ifcopenshell.util.type.get_applicable_entities(ifc_class, self.file.schema))
|
| 201 |
+
)
|
| 202 |
+
assert not self.schema.declaration_by_name(occurrence_class)._is(
|
| 203 |
+
"IfcTypeProduct"
|
| 204 |
+
), f"Unexpected occurrence_class: '{occurrence_class}' / '{self.occurrence_class}'."
|
| 205 |
+
|
| 206 |
+
for occurrence in ifcopenshell.util.element.get_types(element):
|
| 207 |
+
self.reassign_class(occurrence, occurrence_class, predefined_type)
|
| 208 |
+
else:
|
| 209 |
+
element_type = ifcopenshell.util.element.get_type(element)
|
| 210 |
+
if element_type:
|
| 211 |
+
ifc_class_ = next(iter(ifcopenshell.util.type.get_applicable_types(ifc_class, self.file.schema)))
|
| 212 |
+
element_type = self.reassign_class(element_type, ifc_class_, predefined_type)
|
| 213 |
+
ifc_class = element.is_a()
|
| 214 |
+
for occurrence in ifcopenshell.util.element.get_types(element_type):
|
| 215 |
+
if occurrence == element:
|
| 216 |
+
continue
|
| 217 |
+
self.reassign_class(occurrence, ifc_class, predefined_type)
|
| 218 |
+
return element
|
| 219 |
+
|
| 220 |
+
def reassign_class(
|
| 221 |
+
self, element: ifcopenshell.entity_instance, ifc_class: str, predefined_type: Union[str, None]
|
| 222 |
+
) -> ifcopenshell.entity_instance:
|
| 223 |
+
element = ifcopenshell.util.schema.reassign_class(self.file, element, ifc_class)
|
| 224 |
+
if predefined_type and hasattr(element, "PredefinedType"):
|
| 225 |
+
try:
|
| 226 |
+
element.PredefinedType = predefined_type
|
| 227 |
+
except:
|
| 228 |
+
# PredefinedType wasn't in the respective enum, assume it's actually USERDEFINED
|
| 229 |
+
# and set .ElementType / .ObjectType to the provided predefined type
|
| 230 |
+
element.PredefinedType = "USERDEFINED"
|
| 231 |
+
if element.is_a("IfcTypeProduct"):
|
| 232 |
+
element.ElementType = predefined_type
|
| 233 |
+
else:
|
| 234 |
+
element.ObjectType = predefined_type
|
| 235 |
+
|
| 236 |
+
return element
|
data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/root/remove_product.py
ADDED
|
@@ -0,0 +1,223 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# IfcOpenShell - IFC toolkit and geometry engine
|
| 2 |
+
# Copyright (C) 2021 Dion Moult <dion@thinkmoult.com>
|
| 3 |
+
#
|
| 4 |
+
# This file is part of IfcOpenShell.
|
| 5 |
+
#
|
| 6 |
+
# IfcOpenShell is free software: you can redistribute it and/or modify
|
| 7 |
+
# it under the terms of the GNU Lesser General Public License as published by
|
| 8 |
+
# the Free Software Foundation, either version 3 of the License, or
|
| 9 |
+
# (at your option) any later version.
|
| 10 |
+
#
|
| 11 |
+
# IfcOpenShell is distributed in the hope that it will be useful,
|
| 12 |
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 13 |
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 14 |
+
# GNU Lesser General Public License for more details.
|
| 15 |
+
#
|
| 16 |
+
# You should have received a copy of the GNU Lesser General Public License
|
| 17 |
+
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
|
| 18 |
+
|
| 19 |
+
import ifcopenshell.api.type
|
| 20 |
+
import ifcopenshell.api.grid
|
| 21 |
+
import ifcopenshell.api.feature
|
| 22 |
+
import ifcopenshell.api.root
|
| 23 |
+
import ifcopenshell.api.pset
|
| 24 |
+
import ifcopenshell.api.boundary
|
| 25 |
+
import ifcopenshell.api.material
|
| 26 |
+
import ifcopenshell.api.geometry
|
| 27 |
+
import ifcopenshell.util.element
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
def remove_product(file: ifcopenshell.file, product: ifcopenshell.entity_instance) -> None:
|
| 31 |
+
"""Removes a product
|
| 32 |
+
|
| 33 |
+
This is effectively a smart delete function that not only removes a
|
| 34 |
+
product, but also all of its relationships. It is always recommended to
|
| 35 |
+
use this function to prevent orphaned data in your IFC model.
|
| 36 |
+
|
| 37 |
+
This is intended to be used for removing:
|
| 38 |
+
|
| 39 |
+
- IfcAnnotation
|
| 40 |
+
- IfcElement
|
| 41 |
+
- IfcElementType
|
| 42 |
+
- IfcSpatialElement
|
| 43 |
+
- IfcSpatialElementType
|
| 44 |
+
|
| 45 |
+
For example, geometric representations are removed. Placement
|
| 46 |
+
coordinates are also removed. Properties are removed. Material, type,
|
| 47 |
+
containment, aggregation, and nesting relationships are removed (but
|
| 48 |
+
naturally, the materials, types, containers, etc themselves remain).
|
| 49 |
+
|
| 50 |
+
:param product: The element to remove.
|
| 51 |
+
:return: None
|
| 52 |
+
|
| 53 |
+
Example:
|
| 54 |
+
|
| 55 |
+
.. code:: python
|
| 56 |
+
|
| 57 |
+
# We have a wall.
|
| 58 |
+
wall = ifcopenshell.api.root.create_entity(model, ifc_class="IfcWall")
|
| 59 |
+
|
| 60 |
+
# No we don't.
|
| 61 |
+
ifcopenshell.api.root.remove_product(model, product=wall)
|
| 62 |
+
"""
|
| 63 |
+
representations: list[ifcopenshell.entity_instance] = []
|
| 64 |
+
if product.is_a("IfcProduct"):
|
| 65 |
+
if product.Representation:
|
| 66 |
+
representations = product.Representation.Representations or []
|
| 67 |
+
else:
|
| 68 |
+
representations = []
|
| 69 |
+
|
| 70 |
+
# remove object placements
|
| 71 |
+
object_placement = product.ObjectPlacement
|
| 72 |
+
if object_placement:
|
| 73 |
+
if file.get_total_inverses(object_placement) == 1:
|
| 74 |
+
product.ObjectPlacement = None # remove the inverse for remove_deep2 to work
|
| 75 |
+
ifcopenshell.util.element.remove_deep2(file, object_placement)
|
| 76 |
+
|
| 77 |
+
elif product.is_a("IfcTypeProduct"):
|
| 78 |
+
representations = [rm.MappedRepresentation for rm in product.RepresentationMaps or []]
|
| 79 |
+
|
| 80 |
+
# remove psets
|
| 81 |
+
psets = product.HasPropertySets or []
|
| 82 |
+
for pset in psets:
|
| 83 |
+
if file.get_total_inverses(pset) != 1:
|
| 84 |
+
continue
|
| 85 |
+
ifcopenshell.api.pset.remove_pset(file, product=product, pset=pset)
|
| 86 |
+
|
| 87 |
+
for representation in representations:
|
| 88 |
+
ifcopenshell.api.geometry.unassign_representation(file, product=product, representation=representation)
|
| 89 |
+
ifcopenshell.api.geometry.remove_representation(file, representation=representation)
|
| 90 |
+
for opening in getattr(product, "HasOpenings", []) or []:
|
| 91 |
+
ifcopenshell.api.feature.remove_feature(file, feature=opening.RelatedOpeningElement)
|
| 92 |
+
|
| 93 |
+
if product.is_a("IfcGrid"):
|
| 94 |
+
for axis in product.UAxes + product.VAxes + (product.WAxes or ()):
|
| 95 |
+
ifcopenshell.api.grid.remove_grid_axis(file, axis=axis)
|
| 96 |
+
|
| 97 |
+
def element_exists(element_id):
|
| 98 |
+
try:
|
| 99 |
+
file.by_id(element_id)
|
| 100 |
+
return True
|
| 101 |
+
except RuntimeError:
|
| 102 |
+
return False
|
| 103 |
+
|
| 104 |
+
# TODO: remove object placement and other relationships
|
| 105 |
+
for inverse_id in [i.id() for i in file.get_inverse(product)]:
|
| 106 |
+
try:
|
| 107 |
+
inverse = file.by_id(inverse_id)
|
| 108 |
+
except:
|
| 109 |
+
continue
|
| 110 |
+
if inverse.is_a("IfcRelDefinesByProperties"):
|
| 111 |
+
ifcopenshell.api.pset.remove_pset(file, product=product, pset=inverse.RelatingPropertyDefinition)
|
| 112 |
+
elif inverse.is_a("IfcRelAssociatesMaterial"):
|
| 113 |
+
ifcopenshell.api.material.unassign_material(file, products=[product])
|
| 114 |
+
elif inverse.is_a("IfcRelDefinesByType"):
|
| 115 |
+
if inverse.RelatingType == product:
|
| 116 |
+
ifcopenshell.api.type.unassign_type(file, related_objects=inverse.RelatedObjects)
|
| 117 |
+
else:
|
| 118 |
+
ifcopenshell.api.type.unassign_type(file, related_objects=[product])
|
| 119 |
+
elif inverse.is_a("IfcRelSpaceBoundary"):
|
| 120 |
+
ifcopenshell.api.boundary.remove_boundary(file, boundary=inverse)
|
| 121 |
+
elif inverse.is_a("IfcRelFillsElement"):
|
| 122 |
+
history = inverse.OwnerHistory
|
| 123 |
+
file.remove(inverse)
|
| 124 |
+
if history:
|
| 125 |
+
ifcopenshell.util.element.remove_deep2(file, history)
|
| 126 |
+
elif inverse.is_a("IfcRelVoidsElement"):
|
| 127 |
+
history = inverse.OwnerHistory
|
| 128 |
+
file.remove(inverse)
|
| 129 |
+
if history:
|
| 130 |
+
ifcopenshell.util.element.remove_deep2(file, history)
|
| 131 |
+
elif inverse.is_a("IfcRelServicesBuildings"):
|
| 132 |
+
history = inverse.OwnerHistory
|
| 133 |
+
file.remove(inverse)
|
| 134 |
+
if history:
|
| 135 |
+
ifcopenshell.util.element.remove_deep2(file, history)
|
| 136 |
+
elif inverse.is_a("IfcRelNests"):
|
| 137 |
+
if inverse.RelatingObject == product:
|
| 138 |
+
inverse_id = inverse.id()
|
| 139 |
+
for subelement in inverse.RelatedObjects:
|
| 140 |
+
if subelement.is_a("IfcDistributionPort"):
|
| 141 |
+
ifcopenshell.api.root.remove_product(file, product=subelement)
|
| 142 |
+
# IfcRelNests could have been already deleted after removing one of the products
|
| 143 |
+
if element_exists(inverse_id):
|
| 144 |
+
history = inverse.OwnerHistory
|
| 145 |
+
file.remove(inverse)
|
| 146 |
+
if history:
|
| 147 |
+
ifcopenshell.util.element.remove_deep2(file, history)
|
| 148 |
+
elif inverse.RelatedObjects == (product,):
|
| 149 |
+
history = inverse.OwnerHistory
|
| 150 |
+
file.remove(inverse)
|
| 151 |
+
if history:
|
| 152 |
+
ifcopenshell.util.element.remove_deep2(file, history)
|
| 153 |
+
elif inverse.is_a("IfcRelAggregates"):
|
| 154 |
+
if inverse.RelatingObject == product or len(inverse.RelatedObjects) == 1:
|
| 155 |
+
history = inverse.OwnerHistory
|
| 156 |
+
file.remove(inverse)
|
| 157 |
+
if history:
|
| 158 |
+
ifcopenshell.util.element.remove_deep2(file, history)
|
| 159 |
+
elif inverse.is_a("IfcRelContainedInSpatialStructure"):
|
| 160 |
+
if inverse.RelatingStructure == product or len(inverse.RelatedElements) == 1:
|
| 161 |
+
history = inverse.OwnerHistory
|
| 162 |
+
file.remove(inverse)
|
| 163 |
+
if history:
|
| 164 |
+
ifcopenshell.util.element.remove_deep2(file, history)
|
| 165 |
+
elif inverse.is_a("IfcRelConnectsElements"):
|
| 166 |
+
if inverse.is_a("IfcRelConnectsWithRealizingElements"):
|
| 167 |
+
if product not in (inverse.RelatingElement, inverse.RelatedElement) and any(
|
| 168 |
+
el for el in inverse.RealizingElements if el != product
|
| 169 |
+
):
|
| 170 |
+
continue
|
| 171 |
+
history = inverse.OwnerHistory
|
| 172 |
+
file.remove(inverse)
|
| 173 |
+
if history:
|
| 174 |
+
ifcopenshell.util.element.remove_deep2(file, history)
|
| 175 |
+
elif inverse.is_a("IfcRelConnectsPortToElement"):
|
| 176 |
+
if inverse.RelatedElement == product:
|
| 177 |
+
ifcopenshell.api.root.remove_product(file, product=inverse.RelatingPort)
|
| 178 |
+
elif inverse.RelatingPort == product:
|
| 179 |
+
history = inverse.OwnerHistory
|
| 180 |
+
file.remove(inverse)
|
| 181 |
+
if history:
|
| 182 |
+
ifcopenshell.util.element.remove_deep2(file, history)
|
| 183 |
+
elif inverse.is_a("IfcRelConnectsPorts"):
|
| 184 |
+
if product not in (inverse.RelatingPort, inverse.RelatedPort):
|
| 185 |
+
# if it's not RelatingPort/RelatedPort then it's optional RealizingElement
|
| 186 |
+
# so we keep the relationship
|
| 187 |
+
continue
|
| 188 |
+
history = inverse.OwnerHistory
|
| 189 |
+
file.remove(inverse)
|
| 190 |
+
if history:
|
| 191 |
+
ifcopenshell.util.element.remove_deep2(file, history)
|
| 192 |
+
elif inverse.is_a("IfcRelAssignsToGroup"):
|
| 193 |
+
if len(inverse.RelatedObjects) == 1:
|
| 194 |
+
history = inverse.OwnerHistory
|
| 195 |
+
file.remove(inverse)
|
| 196 |
+
if history:
|
| 197 |
+
ifcopenshell.util.element.remove_deep2(file, history)
|
| 198 |
+
elif inverse.is_a("IfcRelAssignsToProduct"):
|
| 199 |
+
if inverse.RelatingProduct == product:
|
| 200 |
+
history = inverse.OwnerHistory
|
| 201 |
+
file.remove(inverse)
|
| 202 |
+
if history:
|
| 203 |
+
ifcopenshell.util.element.remove_deep2(file, history)
|
| 204 |
+
elif len(inverse.RelatedObjects) == 1:
|
| 205 |
+
history = inverse.OwnerHistory
|
| 206 |
+
file.remove(inverse)
|
| 207 |
+
if history:
|
| 208 |
+
ifcopenshell.util.element.remove_deep2(file, history)
|
| 209 |
+
elif inverse.is_a("IfcRelFlowControlElements"):
|
| 210 |
+
if inverse.RelatingFlowElement == product:
|
| 211 |
+
history = inverse.OwnerHistory
|
| 212 |
+
file.remove(inverse)
|
| 213 |
+
if history:
|
| 214 |
+
ifcopenshell.util.element.remove_deep2(file, history)
|
| 215 |
+
elif inverse.RelatedControlElements == (product,):
|
| 216 |
+
history = inverse.OwnerHistory
|
| 217 |
+
file.remove(inverse)
|
| 218 |
+
if history:
|
| 219 |
+
ifcopenshell.util.element.remove_deep2(file, history)
|
| 220 |
+
history = product.OwnerHistory
|
| 221 |
+
file.remove(product)
|
| 222 |
+
if history:
|
| 223 |
+
ifcopenshell.util.element.remove_deep2(file, history)
|
data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/sequence/assign_recurrence_pattern.py
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# IfcOpenShell - IFC toolkit and geometry engine
|
| 2 |
+
# Copyright (C) 2021 Dion Moult <dion@thinkmoult.com>
|
| 3 |
+
#
|
| 4 |
+
# This file is part of IfcOpenShell.
|
| 5 |
+
#
|
| 6 |
+
# IfcOpenShell is free software: you can redistribute it and/or modify
|
| 7 |
+
# it under the terms of the GNU Lesser General Public License as published by
|
| 8 |
+
# the Free Software Foundation, either version 3 of the License, or
|
| 9 |
+
# (at your option) any later version.
|
| 10 |
+
#
|
| 11 |
+
# IfcOpenShell is distributed in the hope that it will be useful,
|
| 12 |
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 13 |
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 14 |
+
# GNU Lesser General Public License for more details.
|
| 15 |
+
#
|
| 16 |
+
# You should have received a copy of the GNU Lesser General Public License
|
| 17 |
+
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
|
| 18 |
+
import ifcopenshell
|
| 19 |
+
import ifcopenshell.util.sequence
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
def assign_recurrence_pattern(
|
| 23 |
+
file: ifcopenshell.file,
|
| 24 |
+
parent: ifcopenshell.entity_instance,
|
| 25 |
+
recurrence_type: ifcopenshell.util.sequence.RECURRENCE_TYPE = "WEEKLY",
|
| 26 |
+
) -> ifcopenshell.entity_instance:
|
| 27 |
+
"""Define a time to recur at a particular interval
|
| 28 |
+
|
| 29 |
+
There are two scenarios where you might want to define a recurring time
|
| 30 |
+
pattern.
|
| 31 |
+
|
| 32 |
+
You might want a task to be scheduled at a recurring interval,
|
| 33 |
+
this is common for maintenance tasks which need to be performed monthly,
|
| 34 |
+
every 6 months, every year, etc.
|
| 35 |
+
|
| 36 |
+
Alternatively, you might be defining a work calendar, which defines
|
| 37 |
+
working days or holidays. The working days might be every week from
|
| 38 |
+
monday to friday ("every" week means it recurs every week), or the
|
| 39 |
+
holidays might be the same every year.
|
| 40 |
+
|
| 41 |
+
The types of recurrence are:
|
| 42 |
+
|
| 43 |
+
- DAILY: every Nth (interval) day for up to X (Occurrences) occurrences.
|
| 44 |
+
e.g. Every day, every 2 days, every day up to 5 times, etc
|
| 45 |
+
- WEEKLY: every Nth (interval) MTWTFSS (WeekdayComponent) for up to X
|
| 46 |
+
(Occurrences) occurrences. e.g. Every Monday, every weekday, every
|
| 47 |
+
other saturday, etc
|
| 48 |
+
- MONTHLY_BY_DAY_OF_MONTH: every Nth (DayComponent) of every Xth
|
| 49 |
+
(Interval) Month up to Y (Occurrences) occurrences. e.g. Every 15th of
|
| 50 |
+
the Month.
|
| 51 |
+
- MONTHLY_BY_POSITION: Every Nth (Position) MTWTFSS (WeekdayComponent)
|
| 52 |
+
of every Xth (Interval) Month up to Y (Occurrences) occurrences. e.g.
|
| 53 |
+
Every second Tuesday of the Month.
|
| 54 |
+
- YEARLY_BY_DAY_OF_MONTH: every Nth (DayComponent) of every JFMAMJJASOND
|
| 55 |
+
(MonthComponent) month of every Yth (Interval) Year up to Z
|
| 56 |
+
(Occurrences) occurrences. e.g. every 25th of December.
|
| 57 |
+
- YEARLY_BY_POSITION: every Nth (Position) MTWTFSS (WeekdayComponent) of
|
| 58 |
+
every JFMAMJJASOND (MonthComponent) month of every Yth (Interval)
|
| 59 |
+
Year up to Z (Occurrences) occurrences. e.g. every third Wednesday
|
| 60 |
+
of January.
|
| 61 |
+
|
| 62 |
+
These recurrence patterns are fairly standard in all calendar and
|
| 63 |
+
scheduling applications.
|
| 64 |
+
|
| 65 |
+
:param parent: Either an IfcTaskTimeRecurring if you are defining a
|
| 66 |
+
recurring schedule for a task, or IfcWorkTime if you are defining a
|
| 67 |
+
recurring pattern for a workdays or holidays in a calendar.
|
| 68 |
+
:param recurrence_type: One of the types of recurrences.
|
| 69 |
+
:return: The newly created IfcRecurrencePattern
|
| 70 |
+
|
| 71 |
+
Example:
|
| 72 |
+
|
| 73 |
+
.. code:: python
|
| 74 |
+
|
| 75 |
+
# Let's create a new calendar.
|
| 76 |
+
calendar = ifcopenshell.api.sequence.add_work_calendar(model)
|
| 77 |
+
|
| 78 |
+
# Let's start defining the times that we work during the week.
|
| 79 |
+
work_time = ifcopenshell.api.sequence.add_work_time(model,
|
| 80 |
+
work_calendar=calendar, time_type="WorkingTimes")
|
| 81 |
+
|
| 82 |
+
# We create a weekly recurrence
|
| 83 |
+
pattern = ifcopenshell.api.sequence.assign_recurrence_pattern(model,
|
| 84 |
+
parent=work_time, recurrence_type="WEEKLY")
|
| 85 |
+
|
| 86 |
+
# State that we work from weekdays 1 to 5 (i.e. Monday to Friday)
|
| 87 |
+
ifcopenshell.api.sequence.edit_recurrence_pattern(model,
|
| 88 |
+
recurrence_pattern=pattern, attributes={"WeekdayComponent": [1, 2, 3, 4, 5]})
|
| 89 |
+
|
| 90 |
+
# Let's imagine we are creating a maintenance schedule.
|
| 91 |
+
schedule = ifcopenshell.api.sequence.add_work_schedule(model, name="Equipment Maintenance")
|
| 92 |
+
|
| 93 |
+
# Now let's imagine we have a task to maintain the chillers
|
| 94 |
+
task = ifcopenshell.api.sequence.add_task(model,
|
| 95 |
+
work_schedule=schedule, name="Chiller maintenance")
|
| 96 |
+
|
| 97 |
+
# Because it is a maintenance task, we must schedule a recurring time
|
| 98 |
+
time = ifcopenshell.api.sequence.add_task_time(model, task=task, is_recurring=True)
|
| 99 |
+
|
| 100 |
+
# We create a monthly recurrence
|
| 101 |
+
pattern = ifcopenshell.api.sequence.assign_recurrence_pattern(model,
|
| 102 |
+
parent=work_time, recurrence_type="MONTHLY_BY_DAY_OF_MONTH")
|
| 103 |
+
|
| 104 |
+
# Specifically, the maintenance task must occur every 6 months
|
| 105 |
+
ifcopenshell.api.sequence.edit_recurrence_pattern(model,
|
| 106 |
+
recurrence_pattern=pattern, attributes={"DayComponent": [1], "Interval": 6})
|
| 107 |
+
"""
|
| 108 |
+
recurrence = file.create_entity("IfcRecurrencePattern", recurrence_type)
|
| 109 |
+
|
| 110 |
+
if parent.is_a("IfcWorkTime"):
|
| 111 |
+
if (old_recurrence := parent.RecurrencePattern) and file.get_total_inverses(old_recurrence) == 1:
|
| 112 |
+
file.remove(old_recurrence)
|
| 113 |
+
parent.RecurrencePattern = recurrence
|
| 114 |
+
elif parent.is_a("IfcTaskTimeRecurring"):
|
| 115 |
+
if (recurrence_old := parent.Recurrence) and file.get_total_inverses(recurrence_old) == 1:
|
| 116 |
+
file.remove(recurrence_old)
|
| 117 |
+
parent.Recurrence = recurrence
|
| 118 |
+
return recurrence
|
data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/sequence/remove_work_time.py
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# IfcOpenShell - IFC toolkit and geometry engine
|
| 2 |
+
# Copyright (C) 2021 Dion Moult <dion@thinkmoult.com>
|
| 3 |
+
#
|
| 4 |
+
# This file is part of IfcOpenShell.
|
| 5 |
+
#
|
| 6 |
+
# IfcOpenShell is free software: you can redistribute it and/or modify
|
| 7 |
+
# it under the terms of the GNU Lesser General Public License as published by
|
| 8 |
+
# the Free Software Foundation, either version 3 of the License, or
|
| 9 |
+
# (at your option) any later version.
|
| 10 |
+
#
|
| 11 |
+
# IfcOpenShell is distributed in the hope that it will be useful,
|
| 12 |
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 13 |
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 14 |
+
# GNU Lesser General Public License for more details.
|
| 15 |
+
#
|
| 16 |
+
# You should have received a copy of the GNU Lesser General Public License
|
| 17 |
+
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
|
| 18 |
+
import ifcopenshell
|
| 19 |
+
import ifcopenshell.api.sequence
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
def remove_work_time(file: ifcopenshell.file, work_time: ifcopenshell.entity_instance) -> None:
|
| 23 |
+
"""Removes a work time
|
| 24 |
+
|
| 25 |
+
:param work_time: The IfcWorkTime to remove.
|
| 26 |
+
:return: None
|
| 27 |
+
|
| 28 |
+
Example:
|
| 29 |
+
|
| 30 |
+
.. code:: python
|
| 31 |
+
|
| 32 |
+
# Let's create a new calendar.
|
| 33 |
+
calendar = ifcopenshell.api.sequence.add_work_calendar(model)
|
| 34 |
+
|
| 35 |
+
# Let's start defining the times that we work during the week.
|
| 36 |
+
work_time = ifcopenshell.api.sequence.add_work_time(model,
|
| 37 |
+
work_calendar=calendar, time_type="WorkingTimes")
|
| 38 |
+
|
| 39 |
+
# And remove it immediately
|
| 40 |
+
ifcopenshell.api.sequence.remove_work_time(model, work_time=work_time)
|
| 41 |
+
"""
|
| 42 |
+
|
| 43 |
+
# Currently in API recurrence patterns are created during assignment
|
| 44 |
+
# and removed during unassignment, so they are never reused.
|
| 45 |
+
if recurrence_pattern := work_time.RecurrencePattern:
|
| 46 |
+
ifcopenshell.api.sequence.unassign_recurrence_pattern(file, recurrence_pattern)
|
| 47 |
+
|
| 48 |
+
file.remove(work_time)
|
data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/unit/__init__.py
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# IfcOpenShell - IFC toolkit and geometry engine
|
| 2 |
+
# Copyright (C) 2022 Dion Moult <dion@thinkmoult.com>
|
| 3 |
+
#
|
| 4 |
+
# This file is part of IfcOpenShell.
|
| 5 |
+
#
|
| 6 |
+
# IfcOpenShell is free software: you can redistribute it and/or modify
|
| 7 |
+
# it under the terms of the GNU Lesser General Public License as published by
|
| 8 |
+
# the Free Software Foundation, either version 3 of the License, or
|
| 9 |
+
# (at your option) any later version.
|
| 10 |
+
#
|
| 11 |
+
# IfcOpenShell is distributed in the hope that it will be useful,
|
| 12 |
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 13 |
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 14 |
+
# GNU Lesser General Public License for more details.
|
| 15 |
+
#
|
| 16 |
+
# You should have received a copy of the GNU Lesser General Public License
|
| 17 |
+
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
|
| 18 |
+
|
| 19 |
+
"""Define units (length, area, monetary, pressure, etc)
|
| 20 |
+
|
| 21 |
+
Units can be defined as a default project unit or used specifically for certain
|
| 22 |
+
properties. Units may be especially complex when dealing with services and
|
| 23 |
+
equipment.
|
| 24 |
+
"""
|
| 25 |
+
|
| 26 |
+
from .. import wrap_usecases
|
| 27 |
+
from .add_context_dependent_unit import add_context_dependent_unit
|
| 28 |
+
from .add_conversion_based_unit import add_conversion_based_unit
|
| 29 |
+
from .add_monetary_unit import add_monetary_unit
|
| 30 |
+
from .add_si_unit import add_si_unit
|
| 31 |
+
from .add_derived_unit import add_derived_unit
|
| 32 |
+
from .assign_unit import assign_unit
|
| 33 |
+
from .edit_derived_unit import edit_derived_unit
|
| 34 |
+
from .edit_monetary_unit import edit_monetary_unit
|
| 35 |
+
from .edit_named_unit import edit_named_unit
|
| 36 |
+
from .remove_unit import remove_unit
|
| 37 |
+
from .unassign_unit import unassign_unit
|
| 38 |
+
|
| 39 |
+
wrap_usecases(__path__, __name__)
|
| 40 |
+
|
| 41 |
+
__all__ = [
|
| 42 |
+
"add_context_dependent_unit",
|
| 43 |
+
"add_conversion_based_unit",
|
| 44 |
+
"add_derived_unit",
|
| 45 |
+
"add_monetary_unit",
|
| 46 |
+
"add_si_unit",
|
| 47 |
+
"assign_unit",
|
| 48 |
+
"edit_derived_unit",
|
| 49 |
+
"edit_monetary_unit",
|
| 50 |
+
"edit_named_unit",
|
| 51 |
+
"remove_unit",
|
| 52 |
+
"unassign_unit",
|
| 53 |
+
]
|
data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/unit/add_context_dependent_unit.py
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# IfcOpenShell - IFC toolkit and geometry engine
|
| 2 |
+
# Copyright (C) 2021 Dion Moult <dion@thinkmoult.com>
|
| 3 |
+
#
|
| 4 |
+
# This file is part of IfcOpenShell.
|
| 5 |
+
#
|
| 6 |
+
# IfcOpenShell is free software: you can redistribute it and/or modify
|
| 7 |
+
# it under the terms of the GNU Lesser General Public License as published by
|
| 8 |
+
# the Free Software Foundation, either version 3 of the License, or
|
| 9 |
+
# (at your option) any later version.
|
| 10 |
+
#
|
| 11 |
+
# IfcOpenShell is distributed in the hope that it will be useful,
|
| 12 |
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 13 |
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 14 |
+
# GNU Lesser General Public License for more details.
|
| 15 |
+
#
|
| 16 |
+
# You should have received a copy of the GNU Lesser General Public License
|
| 17 |
+
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
|
| 18 |
+
import ifcopenshell
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
def add_context_dependent_unit(
|
| 22 |
+
file: ifcopenshell.file,
|
| 23 |
+
unit_type: str = "USERDEFINED",
|
| 24 |
+
name: str = "THINGAMAJIG",
|
| 25 |
+
dimensions: tuple[int, int, int, int, int, int, int] = (0, 0, 0, 0, 0, 0, 0),
|
| 26 |
+
) -> ifcopenshell.entity_instance:
|
| 27 |
+
"""Add a new arbitrary unit that can only be interpreted in a project specific context
|
| 28 |
+
|
| 29 |
+
Occasionally the construction industry uses arbitrary units to quantify
|
| 30 |
+
objects, like "pairs" of door hardware, "palettes" or "boxes" of fixings
|
| 31 |
+
or equipment.
|
| 32 |
+
|
| 33 |
+
:param unit_type: Typically should be left as USERDEFINED, unless for
|
| 34 |
+
some bizarre reason you are redefining something you could use a
|
| 35 |
+
sensible normal unit for. In that case, firstly stop whatever you're
|
| 36 |
+
doing and have a hard think about your life, and then if life really
|
| 37 |
+
is going that badly for you, check out the IFC docs for IfcUnitEnum.
|
| 38 |
+
:param name: Give your unit a name. X what? X bananas?
|
| 39 |
+
:param dimensions: Units typically measure one of 7 fundamental physical
|
| 40 |
+
dimensions: length, mass, time, electric current, temperature,
|
| 41 |
+
substance amount, or luminous intensity. These are represented as a
|
| 42 |
+
list of 7 integers, representing the exponents of each one of these
|
| 43 |
+
dimensions. For example, a length unit is (1, 0, 0, 0, 0, 0, 0),
|
| 44 |
+
where as an area unit is (2, 0, 0, 0, 0, 0, 0). A unit of meters per
|
| 45 |
+
second is (1, 0, -1, 0, 0, 0, 0). For context dependent units, it is
|
| 46 |
+
recommended to leave this as the default of (0, 0, 0, 0, 0, 0, 0).
|
| 47 |
+
:return: The new IfcContextDependentUnit
|
| 48 |
+
|
| 49 |
+
Example:
|
| 50 |
+
|
| 51 |
+
.. code:: python
|
| 52 |
+
|
| 53 |
+
# Boxes of things
|
| 54 |
+
ifcopenshell.api.unit.add_context_dependent_unit(model, name="BOXES")
|
| 55 |
+
"""
|
| 56 |
+
return file.create_entity(
|
| 57 |
+
"IfcContextDependentUnit",
|
| 58 |
+
Dimensions=file.createIfcDimensionalExponents(*dimensions),
|
| 59 |
+
UnitType=unit_type,
|
| 60 |
+
Name=name,
|
| 61 |
+
)
|
data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/unit/add_conversion_based_unit.py
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# IfcOpenShell - IFC toolkit and geometry engine
|
| 2 |
+
# Copyright (C) 2021 Dion Moult <dion@thinkmoult.com>
|
| 3 |
+
#
|
| 4 |
+
# This file is part of IfcOpenShell.
|
| 5 |
+
#
|
| 6 |
+
# IfcOpenShell is free software: you can redistribute it and/or modify
|
| 7 |
+
# it under the terms of the GNU Lesser General Public License as published by
|
| 8 |
+
# the Free Software Foundation, either version 3 of the License, or
|
| 9 |
+
# (at your option) any later version.
|
| 10 |
+
#
|
| 11 |
+
# IfcOpenShell is distributed in the hope that it will be useful,
|
| 12 |
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 13 |
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 14 |
+
# GNU Lesser General Public License for more details.
|
| 15 |
+
#
|
| 16 |
+
# You should have received a copy of the GNU Lesser General Public License
|
| 17 |
+
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
|
| 18 |
+
|
| 19 |
+
import ifcopenshell
|
| 20 |
+
import ifcopenshell.util.unit
|
| 21 |
+
from typing import Optional
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
def add_conversion_based_unit(
|
| 25 |
+
file: ifcopenshell.file, name: str = "foot", conversion_offset: Optional[float] = None
|
| 26 |
+
) -> ifcopenshell.entity_instance:
|
| 27 |
+
"""Add a conversion based unit
|
| 28 |
+
|
| 29 |
+
If you're in one of those countries who don't use SI units, you're
|
| 30 |
+
probably simply using SI units converted into another unit. If you want
|
| 31 |
+
to use _those_ units, you can create a conversion based unit with this
|
| 32 |
+
function. You can choose from one of: inch, foot, yard, mile, square
|
| 33 |
+
inch, square foot, square yard, acre, square mile, cubic inch, cubic
|
| 34 |
+
foot, cubic yard, litre, fluid ounce UK, fluid ounce US, pint UK, pint
|
| 35 |
+
US, gallon UK, gallon US, degree, ounce, pound, ton UK, ton US, lbf,
|
| 36 |
+
kip, psi, ksi, minute, hour, day, btu, and fahrenheit.
|
| 37 |
+
|
| 38 |
+
:param name: A converted name chosen from the list above.
|
| 39 |
+
:param conversion_offset: If you want to offset the conversion further
|
| 40 |
+
by a set number, you may specify it here. For example, fahrenheit is
|
| 41 |
+
1.8 * kelvin - 459.67. The -459.67 is the conversion offset. Note
|
| 42 |
+
that this is just an example and you don't actually need to specify
|
| 43 |
+
that for fahrenheit as it's built into this API function. For
|
| 44 |
+
advanced users only.
|
| 45 |
+
:return: The new IfcConversionBasedUnit or
|
| 46 |
+
IfcConversionBasedUnitWithOffset
|
| 47 |
+
|
| 48 |
+
Example:
|
| 49 |
+
|
| 50 |
+
.. code:: python
|
| 51 |
+
|
| 52 |
+
# Some common imperial measurements
|
| 53 |
+
length = ifcopenshell.api.unit.add_conversion_based_unit(model, name="inch")
|
| 54 |
+
area = ifcopenshell.api.unit.add_conversion_based_unit(model, name="square foot")
|
| 55 |
+
|
| 56 |
+
# Make it our default units, if we are doing an imperial building
|
| 57 |
+
ifcopenshell.api.unit.assign_unit(model, units=[length, area])
|
| 58 |
+
"""
|
| 59 |
+
|
| 60 |
+
unit_type = ifcopenshell.util.unit.imperial_types.get(name, "USERDEFINED")
|
| 61 |
+
dimensions = ifcopenshell.util.unit.named_dimensions[unit_type]
|
| 62 |
+
exponents = file.createIfcDimensionalExponents(*dimensions)
|
| 63 |
+
si_name = ifcopenshell.util.unit.si_type_names[unit_type]
|
| 64 |
+
si_unit = file.createIfcSIUnit(UnitType=unit_type, Name=si_name)
|
| 65 |
+
|
| 66 |
+
conversion_real = ifcopenshell.util.unit.si_conversions.get(name, 1)
|
| 67 |
+
value_component = file.create_entity("IfcReal", **{"wrappedValue": conversion_real})
|
| 68 |
+
conversion_factor = file.createIfcMeasureWithUnit(value_component, si_unit)
|
| 69 |
+
|
| 70 |
+
if not conversion_offset:
|
| 71 |
+
conversion_offset = ifcopenshell.util.unit.si_offsets.get(name, 0)
|
| 72 |
+
|
| 73 |
+
if conversion_offset:
|
| 74 |
+
return file.createIfcConversionBasedUnitWithOffset(
|
| 75 |
+
exponents,
|
| 76 |
+
unit_type,
|
| 77 |
+
name,
|
| 78 |
+
conversion_factor,
|
| 79 |
+
conversion_offset,
|
| 80 |
+
)
|
| 81 |
+
return file.createIfcConversionBasedUnit(exponents, unit_type, name, conversion_factor)
|
data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/unit/add_derived_unit.py
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# IfcOpenShell - IFC toolkit and geometry engine
|
| 2 |
+
# Copyright (C) 2021 Dion Moult <dion@thinkmoult.com>
|
| 3 |
+
#
|
| 4 |
+
# This file is part of IfcOpenShell.
|
| 5 |
+
#
|
| 6 |
+
# IfcOpenShell is free software: you can redistribute it and/or modify
|
| 7 |
+
# it under the terms of the GNU Lesser General Public License as published by
|
| 8 |
+
# the Free Software Foundation, either version 3 of the License, or
|
| 9 |
+
# (at your option) any later version.
|
| 10 |
+
#
|
| 11 |
+
# IfcOpenShell is distributed in the hope that it will be useful,
|
| 12 |
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 13 |
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 14 |
+
# GNU Lesser General Public License for more details.
|
| 15 |
+
#
|
| 16 |
+
# You should have received a copy of the GNU Lesser General Public License
|
| 17 |
+
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
|
| 18 |
+
|
| 19 |
+
import ifcopenshell.util.unit
|
| 20 |
+
from typing import Any, Optional
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
def add_derived_unit(
|
| 24 |
+
file: ifcopenshell.file, unit_type: str, userdefinedtype: str, attributes: dict[ifcopenshell.entity_instance, int]
|
| 25 |
+
) -> ifcopenshell.entity_instance:
|
| 26 |
+
"""Add a new Derive unit
|
| 27 |
+
|
| 28 |
+
The supported types are ANGULARVELOCITYUNIT, AREADENSITYUNIT, COMPOUNDPLANEANGLEUNIT,
|
| 29 |
+
DYNAMICVISCOSITYUNIT, HEATFLUXDENSITYUNIT, INTEGERCOUNTRATEUNIT, ISOTHERMALMOISTURECAPACITYUNIT,
|
| 30 |
+
KINEMATICVISCOSITYUNIT, LINEARVELOCITYUNIT, MASSDENSITYUNIT, MASSFLOWRATEUNIT, MOISTUREDIFFUSIVITYUNIT,
|
| 31 |
+
MOLECULARWEIGHTUNIT, SPECIFICHEATCAPACITYUNIT, THERMALADMITTANCEUNIT, THERMALCONDUCTANCEUNIT,
|
| 32 |
+
THERMALRESISTANCEUNIT, THERMALTRANSMITTANCEUNIT, VAPORPERMEABILITYUNIT, VOLUMETRICFLOWRATEUNIT,
|
| 33 |
+
ROTATIONALFREQUENCYUNIT, TORQUEUNIT, MOMENTOFINERTIAUNIT, LINEARMOMENTUNIT, LINEARFORCEUNIT,
|
| 34 |
+
PLANARFORCEUNIT, MODULUSOFELASTICITYUNIT, SHEARMODULUSUNIT, LINEARSTIFFNESSUNIT, ROTATIONALSTIFFNESSUNIT,
|
| 35 |
+
MODULUSOFSUBGRADEREACTIONUNIT, ACCELERATIONUNIT, CURVATUREUNIT, HEATINGVALUEUNIT, IONCONCENTRATIONUNIT,
|
| 36 |
+
LUMINOUSINTENSITYDISTRIBUTIONUNIT, MASSPERLENGTHUNIT, MODULUSOFLINEARSUBGRADEREACTIONUNIT,
|
| 37 |
+
MODULUSOFROTATIONALSUBGRADEREACTIONUNIT, PHUNIT, ROTATIONALMASSUNIT, SECTIONAREAINTEGRALUNIT,
|
| 38 |
+
SECTIONMODULUSUNIT, SOUNDPOWERLEVELUNIT, SOUNDPOWERUNIT, SOUNDPRESSURELEVELUNIT, SOUNDPRESSUREUNIT,
|
| 39 |
+
TEMPERATUREGRADIENTUNIT, TEMPERATURERATEOFCHANGEUNIT, THERMALEXPANSIONCOEFFICIENTUNIT, WARPINGCONSTANTUNIT,
|
| 40 |
+
WARPINGMOMENTUNIT, USERDEFINED.
|
| 41 |
+
|
| 42 |
+
In case of choosing USERDEFINED, the UserDefinedType parameter needs to be provided
|
| 43 |
+
|
| 44 |
+
:param unit_type: A type of unit chosen from the list above. For
|
| 45 |
+
example, choosing THERMALCONDUCTANCEUNIT will give you a Thermal conductance.
|
| 46 |
+
:param userdefinedtype: The user defined type in case of choosing USERDEFINED, or None for no
|
| 47 |
+
user defined type.
|
| 48 |
+
:param attributes: a dictionary of attribute names and values.
|
| 49 |
+
:return: The newly created IfcDerivedUnit
|
| 50 |
+
|
| 51 |
+
Example:
|
| 52 |
+
|
| 53 |
+
.. code:: python
|
| 54 |
+
|
| 55 |
+
# Linear velocity in m/s
|
| 56 |
+
length = ifcopenshell.api.unit.add_si_unit(model, unit_type="LENGTHUNIT")
|
| 57 |
+
#2=IfcSIUnit(*,.LENGTHUNIT.,$,.METRE.)
|
| 58 |
+
|
| 59 |
+
time = ifcopenshell.api.unit.add_si_unit(model, unit_type="TIMEUNIT")
|
| 60 |
+
#4=IfcSIUnit(*,.TIMEUNIT.,$,.SECOND.)
|
| 61 |
+
|
| 62 |
+
linear_velocity = ifcopenshell.api.unit.add_derived_unit(model, 'LINEARVELOCITY', None, {length : 1, time : -1})
|
| 63 |
+
#10=IfcDerivedUnitElement(#2, 1)
|
| 64 |
+
#11=IfcDerivedUnitElement(#4, -1)
|
| 65 |
+
#12=IfcDerivedUnit((#10,#11),.LINEARVELOCITY.,$)
|
| 66 |
+
|
| 67 |
+
"""
|
| 68 |
+
derive_unit_elements = []
|
| 69 |
+
|
| 70 |
+
for named_unit in attributes:
|
| 71 |
+
derive_unit_elements.append(
|
| 72 |
+
file.create_entity("IfcDerivedUnitElement", Unit=named_unit, Exponent=attributes[named_unit])
|
| 73 |
+
)
|
| 74 |
+
|
| 75 |
+
return file.create_entity(
|
| 76 |
+
"IfcDerivedUnit", Elements=derive_unit_elements, UnitType=unit_type, UserDefinedType=userdefinedtype
|
| 77 |
+
)
|
data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/unit/add_monetary_unit.py
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# IfcOpenShell - IFC toolkit and geometry engine
|
| 2 |
+
# Copyright (C) 2021 Dion Moult <dion@thinkmoult.com>
|
| 3 |
+
#
|
| 4 |
+
# This file is part of IfcOpenShell.
|
| 5 |
+
#
|
| 6 |
+
# IfcOpenShell is free software: you can redistribute it and/or modify
|
| 7 |
+
# it under the terms of the GNU Lesser General Public License as published by
|
| 8 |
+
# the Free Software Foundation, either version 3 of the License, or
|
| 9 |
+
# (at your option) any later version.
|
| 10 |
+
#
|
| 11 |
+
# IfcOpenShell is distributed in the hope that it will be useful,
|
| 12 |
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 13 |
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 14 |
+
# GNU Lesser General Public License for more details.
|
| 15 |
+
#
|
| 16 |
+
# You should have received a copy of the GNU Lesser General Public License
|
| 17 |
+
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
|
| 18 |
+
import ifcopenshell
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
def add_monetary_unit(file: ifcopenshell.file, currency: str = "DOLLARYDOO") -> ifcopenshell.entity_instance:
|
| 22 |
+
"""Add a new currency
|
| 23 |
+
|
| 24 |
+
Currency units are useful in cost plans to know in what currency the
|
| 25 |
+
costs are calculated in. The currencies should follow ISO 4217, like
|
| 26 |
+
USD, GBP, AUD, MYR, etc.
|
| 27 |
+
|
| 28 |
+
:param currency: The currency code
|
| 29 |
+
:return: The newly created IfcMonetaryUnit
|
| 30 |
+
|
| 31 |
+
Example:
|
| 32 |
+
|
| 33 |
+
.. code:: python
|
| 34 |
+
|
| 35 |
+
# If you do all your cost plans in Zimbabwean dollars then nobody
|
| 36 |
+
# knows how accurate the numbers are.
|
| 37 |
+
zwl = ifcopenshell.api.unit.add_monetary_unit(model, currency="ZWL")
|
| 38 |
+
|
| 39 |
+
# Make it our default currency
|
| 40 |
+
ifcopenshell.api.unit.assign_unit(model, units=[zwl])
|
| 41 |
+
"""
|
| 42 |
+
return file.create_entity("IfcMonetaryUnit", currency)
|
data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/unit/add_si_unit.py
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# IfcOpenShell - IFC toolkit and geometry engine
|
| 2 |
+
# Copyright (C) 2021 Dion Moult <dion@thinkmoult.com>
|
| 3 |
+
#
|
| 4 |
+
# This file is part of IfcOpenShell.
|
| 5 |
+
#
|
| 6 |
+
# IfcOpenShell is free software: you can redistribute it and/or modify
|
| 7 |
+
# it under the terms of the GNU Lesser General Public License as published by
|
| 8 |
+
# the Free Software Foundation, either version 3 of the License, or
|
| 9 |
+
# (at your option) any later version.
|
| 10 |
+
#
|
| 11 |
+
# IfcOpenShell is distributed in the hope that it will be useful,
|
| 12 |
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 13 |
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 14 |
+
# GNU Lesser General Public License for more details.
|
| 15 |
+
#
|
| 16 |
+
# You should have received a copy of the GNU Lesser General Public License
|
| 17 |
+
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
|
| 18 |
+
|
| 19 |
+
import ifcopenshell.util.unit
|
| 20 |
+
from typing import Optional
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
def add_si_unit(
|
| 24 |
+
file: ifcopenshell.file, unit_type: str = "LENGTHUNIT", prefix: Optional[str] = None
|
| 25 |
+
) -> ifcopenshell.entity_instance:
|
| 26 |
+
"""Add a new SI unit
|
| 27 |
+
|
| 28 |
+
The supported types are ABSORBEDDOSEUNIT, AMOUNTOFSUBSTANCEUNIT,
|
| 29 |
+
AREAUNIT, DOSEEQUIVALENTUNIT, ELECTRICCAPACITANCEUNIT,
|
| 30 |
+
ELECTRICCHARGEUNIT, ELECTRICCONDUCTANCEUNIT, ELECTRICCURRENTUNIT,
|
| 31 |
+
ELECTRICRESISTANCEUNIT, ELECTRICVOLTAGEUNIT, ENERGYUNIT, FORCEUNIT,
|
| 32 |
+
FREQUENCYUNIT, ILLUMINANCEUNIT, INDUCTANCEUNIT, LENGTHUNIT,
|
| 33 |
+
LUMINOUSFLUXUNIT, LUMINOUSINTENSITYUNIT, MAGNETICFLUXDENSITYUNIT,
|
| 34 |
+
MAGNETICFLUXUNIT, MASSUNIT, PLANEANGLEUNIT, POWERUNIT, PRESSUREUNIT,
|
| 35 |
+
RADIOACTIVITYUNIT, SOLIDANGLEUNIT, THERMODYNAMICTEMPERATUREUNIT,
|
| 36 |
+
TIMEUNIT, VOLUMEUNIT.
|
| 37 |
+
|
| 38 |
+
Prefixes supported are ATTO, CENTI, DECA, DECI, EXA, FEMTO, GIGA, HECTO,
|
| 39 |
+
KILO, MEGA, MICRO, MILLI, NANO, PETA, PICO, TERA.
|
| 40 |
+
|
| 41 |
+
:param unit_type: A type of unit chosen from the list above. For
|
| 42 |
+
example, choosing LENGTHUNIT will give you a metre.
|
| 43 |
+
:param prefix: A prefix chosen from the list above, or None for no
|
| 44 |
+
prefix.
|
| 45 |
+
:return: The newly created IfcSIUnit
|
| 46 |
+
|
| 47 |
+
Example:
|
| 48 |
+
|
| 49 |
+
.. code:: python
|
| 50 |
+
|
| 51 |
+
# Millimeters and square meters
|
| 52 |
+
length = ifcopenshell.api.unit.add_si_unit(model, unit_type="LENGTHUNIT", prefix="MILLI")
|
| 53 |
+
area = ifcopenshell.api.unit.add_si_unit(model, unit_type="AREAUNIT")
|
| 54 |
+
|
| 55 |
+
# Make it our default units, if we are doing a metric building
|
| 56 |
+
ifcopenshell.api.unit.assign_unit(model, units=[length, area])
|
| 57 |
+
"""
|
| 58 |
+
name = ifcopenshell.util.unit.si_type_names.get(unit_type, None)
|
| 59 |
+
return file.create_entity("IfcSIUnit", UnitType=unit_type, Name=name, Prefix=prefix)
|
data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/unit/assign_unit.py
ADDED
|
@@ -0,0 +1,162 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# IfcOpenShell - IFC toolkit and geometry engine
|
| 2 |
+
# Copyright (C) 2021 Dion Moult <dion@thinkmoult.com>
|
| 3 |
+
#
|
| 4 |
+
# This file is part of IfcOpenShell.
|
| 5 |
+
#
|
| 6 |
+
# IfcOpenShell is free software: you can redistribute it and/or modify
|
| 7 |
+
# it under the terms of the GNU Lesser General Public License as published by
|
| 8 |
+
# the Free Software Foundation, either version 3 of the License, or
|
| 9 |
+
# (at your option) any later version.
|
| 10 |
+
#
|
| 11 |
+
# IfcOpenShell is distributed in the hope that it will be useful,
|
| 12 |
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 13 |
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 14 |
+
# GNU Lesser General Public License for more details.
|
| 15 |
+
#
|
| 16 |
+
# You should have received a copy of the GNU Lesser General Public License
|
| 17 |
+
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
|
| 18 |
+
|
| 19 |
+
import ifcopenshell
|
| 20 |
+
import ifcopenshell.util.unit
|
| 21 |
+
from typing import Optional, Any
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
def assign_unit(
|
| 25 |
+
file: ifcopenshell.file,
|
| 26 |
+
units: Optional[list[ifcopenshell.entity_instance]] = None,
|
| 27 |
+
length: Optional[dict] = None,
|
| 28 |
+
area: Optional[dict] = None,
|
| 29 |
+
volume: Optional[dict] = None,
|
| 30 |
+
) -> ifcopenshell.entity_instance:
|
| 31 |
+
"""Assign default project units
|
| 32 |
+
|
| 33 |
+
Whenever a unitised quantity is specified, such as a length, area,
|
| 34 |
+
voltage, pressure, etc, these project units are used by default.
|
| 35 |
+
|
| 36 |
+
It is also possible to override units for specific properties. For
|
| 37 |
+
example, generally you might want square metres for area measurements,
|
| 38 |
+
but you might want square millimeters for the measurements of the cross
|
| 39 |
+
sectional area of cables in cable trays. However, this function only
|
| 40 |
+
deals with the default project units.
|
| 41 |
+
|
| 42 |
+
:param units: A list of units to assign as project defaults. See
|
| 43 |
+
ifcopenshell.api.unit.add_si_unit, unit.add_conversion_based_unit,
|
| 44 |
+
and unit.add_monetary_unit for information on how to create units.
|
| 45 |
+
:return: The IfcUnitAssignment element
|
| 46 |
+
|
| 47 |
+
Example:
|
| 48 |
+
|
| 49 |
+
.. code:: python
|
| 50 |
+
|
| 51 |
+
# You need a project before you can assign units.
|
| 52 |
+
ifcopenshell.api.root.create_entity(model, ifc_class="IfcProject")
|
| 53 |
+
|
| 54 |
+
# Millimeters and square meters
|
| 55 |
+
length = ifcopenshell.api.unit.add_si_unit(model, unit_type="LENGTHUNIT", prefix="MILLI")
|
| 56 |
+
area = ifcopenshell.api.unit.add_si_unit(model, unit_type="AREAUNIT")
|
| 57 |
+
|
| 58 |
+
# Make it our default units, if we are doing a metric building
|
| 59 |
+
ifcopenshell.api.unit.assign_unit(model, units=[length, area])
|
| 60 |
+
|
| 61 |
+
# Alternatively, you may specify without any arguments to
|
| 62 |
+
# automatically create millimeters, square meters, and cubic meters
|
| 63 |
+
# as a convenience for testing purposes. Sorry imperial folks, we
|
| 64 |
+
# prioritise metric here.
|
| 65 |
+
ifcopenshell.api.unit.assign_unit(model)
|
| 66 |
+
"""
|
| 67 |
+
usecase = Usecase()
|
| 68 |
+
usecase.file = file
|
| 69 |
+
usecase.settings = {"units": units}
|
| 70 |
+
# This is a convenience function, likely to be deprecated in the future.
|
| 71 |
+
usecase.settings["length"] = length or {"is_metric": True, "raw": "MILLIMETERS"}
|
| 72 |
+
usecase.settings["area"] = area or {"is_metric": True, "raw": "METERS"}
|
| 73 |
+
usecase.settings["volume"] = volume or {"is_metric": True, "raw": "METERS"}
|
| 74 |
+
return usecase.execute()
|
| 75 |
+
|
| 76 |
+
|
| 77 |
+
class Usecase:
|
| 78 |
+
file: ifcopenshell.file
|
| 79 |
+
settings: dict[str, Any]
|
| 80 |
+
|
| 81 |
+
def execute(self):
|
| 82 |
+
# We're going to refactor this to split unit creation and assignment
|
| 83 |
+
if self.settings["units"]:
|
| 84 |
+
units = self.settings["units"]
|
| 85 |
+
else:
|
| 86 |
+
del self.settings["units"] # TODO refactor
|
| 87 |
+
units = []
|
| 88 |
+
for unit_type, data in self.settings.items():
|
| 89 |
+
if data["is_metric"]:
|
| 90 |
+
units.append(self.create_metric_unit(unit_type, data))
|
| 91 |
+
else:
|
| 92 |
+
units.append(self.create_imperial_unit(unit_type, data))
|
| 93 |
+
|
| 94 |
+
unit_assignment = self.get_unit_assignment()
|
| 95 |
+
self.assign_units(unit_assignment, units)
|
| 96 |
+
return unit_assignment
|
| 97 |
+
|
| 98 |
+
def get_unit_assignment(self) -> ifcopenshell.entity_instance:
|
| 99 |
+
if not (unit_assignment := ifcopenshell.util.unit.get_unit_assignment(self.file)):
|
| 100 |
+
unit_assignment = self.file.createIfcUnitAssignment()
|
| 101 |
+
self.file.by_type("IfcProject")[0].UnitsInContext = unit_assignment
|
| 102 |
+
return unit_assignment
|
| 103 |
+
|
| 104 |
+
def assign_units(
|
| 105 |
+
self, unit_assignment: ifcopenshell.entity_instance, new_units: list[ifcopenshell.entity_instance]
|
| 106 |
+
) -> None:
|
| 107 |
+
new_unit_types = [u.UnitType if not u.is_a("IfcMonetaryUnit") else u.is_a() for u in new_units]
|
| 108 |
+
units = set(
|
| 109 |
+
[
|
| 110 |
+
u
|
| 111 |
+
for u in (unit_assignment.Units or [])
|
| 112 |
+
if u.is_a() not in new_unit_types and getattr(u, "UnitType", None) not in new_unit_types
|
| 113 |
+
]
|
| 114 |
+
)
|
| 115 |
+
for unit in new_units:
|
| 116 |
+
units.add(unit)
|
| 117 |
+
unit_assignment.Units = list(units)
|
| 118 |
+
|
| 119 |
+
def create_metric_unit(self, unit_type: str, data: dict) -> ifcopenshell.entity_instance:
|
| 120 |
+
type_prefix = ""
|
| 121 |
+
if unit_type == "area":
|
| 122 |
+
type_prefix = "SQUARE_"
|
| 123 |
+
elif unit_type == "volume":
|
| 124 |
+
type_prefix = "CUBIC_"
|
| 125 |
+
return self.file.createIfcSIUnit(
|
| 126 |
+
None,
|
| 127 |
+
"{}UNIT".format(unit_type.upper()),
|
| 128 |
+
ifcopenshell.util.unit.get_prefix(data["raw"]),
|
| 129 |
+
type_prefix + ifcopenshell.util.unit.get_unit_name(data["raw"]),
|
| 130 |
+
)
|
| 131 |
+
|
| 132 |
+
def create_imperial_unit(self, unit_type: str, data: dict) -> ifcopenshell.entity_instance:
|
| 133 |
+
if unit_type == "length":
|
| 134 |
+
dimensional_exponents = self.file.createIfcDimensionalExponents(1, 0, 0, 0, 0, 0, 0)
|
| 135 |
+
name_prefix = ""
|
| 136 |
+
elif unit_type == "area":
|
| 137 |
+
dimensional_exponents = self.file.createIfcDimensionalExponents(2, 0, 0, 0, 0, 0, 0)
|
| 138 |
+
name_prefix = "square"
|
| 139 |
+
elif unit_type == "volume":
|
| 140 |
+
dimensional_exponents = self.file.createIfcDimensionalExponents(3, 0, 0, 0, 0, 0, 0)
|
| 141 |
+
name_prefix = "cubic"
|
| 142 |
+
si_unit = self.file.createIfcSIUnit(
|
| 143 |
+
None,
|
| 144 |
+
"{}UNIT".format(unit_type.upper()),
|
| 145 |
+
None,
|
| 146 |
+
"{}METRE".format(name_prefix.upper() + "_" if name_prefix else ""),
|
| 147 |
+
)
|
| 148 |
+
if data["raw"] == "INCHES":
|
| 149 |
+
name = "{}inch".format(name_prefix + " " if name_prefix else "")
|
| 150 |
+
elif data["raw"] == "FEET":
|
| 151 |
+
name = "{}foot".format(name_prefix + " " if name_prefix else "")
|
| 152 |
+
elif data["raw"] == "MILES":
|
| 153 |
+
name = "{}mile".format(name_prefix + " " if name_prefix else "")
|
| 154 |
+
elif data["raw"] == "THOU":
|
| 155 |
+
name = "{}thou".format(name_prefix + " " if name_prefix else "")
|
| 156 |
+
value_component = self.file.create_entity(
|
| 157 |
+
"IfcReal", **{"wrappedValue": ifcopenshell.util.unit.si_conversions[name]}
|
| 158 |
+
)
|
| 159 |
+
conversion_factor = self.file.createIfcMeasureWithUnit(value_component, si_unit)
|
| 160 |
+
return self.file.createIfcConversionBasedUnit(
|
| 161 |
+
dimensional_exponents, "{}UNIT".format(unit_type.upper()), name, conversion_factor
|
| 162 |
+
)
|
data/miniconda3/lib/python3.13/site-packages/ifcopenshell/api/unit/edit_derived_unit.py
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# IfcOpenShell - IFC toolkit and geometry engine
|
| 2 |
+
# Copyright (C) 2021 Dion Moult <dion@thinkmoult.com>
|
| 3 |
+
#
|
| 4 |
+
# This file is part of IfcOpenShell.
|
| 5 |
+
#
|
| 6 |
+
# IfcOpenShell is free software: you can redistribute it and/or modify
|
| 7 |
+
# it under the terms of the GNU Lesser General Public License as published by
|
| 8 |
+
# the Free Software Foundation, either version 3 of the License, or
|
| 9 |
+
# (at your option) any later version.
|
| 10 |
+
#
|
| 11 |
+
# IfcOpenShell is distributed in the hope that it will be useful,
|
| 12 |
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 13 |
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 14 |
+
# GNU Lesser General Public License for more details.
|
| 15 |
+
#
|
| 16 |
+
# You should have received a copy of the GNU Lesser General Public License
|
| 17 |
+
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
|
| 18 |
+
import ifcopenshell
|
| 19 |
+
from typing import Any
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
def edit_derived_unit(file: ifcopenshell.file, unit: ifcopenshell.entity_instance, attributes: dict[str, Any]) -> None:
|
| 23 |
+
"""Edits the attributes of an IfcDerivedUnit
|
| 24 |
+
|
| 25 |
+
For more information about the attributes and data types of an
|
| 26 |
+
IfcDerivedUnit, consult the IFC documentation.
|
| 27 |
+
|
| 28 |
+
:param unit: The IfcDerivedUnit entity you want to edit
|
| 29 |
+
:param attributes: a dictionary of attribute names and values.
|
| 30 |
+
:return: None
|
| 31 |
+
"""
|
| 32 |
+
for name, value in attributes.items():
|
| 33 |
+
setattr(unit, name, value)
|