This commit is contained in:
Andrej730
2024-05-13 12:27:53 +05:00
parent c3bfd7354f
commit ebd03e9290
56 changed files with 244 additions and 127 deletions
@@ -15,9 +15,11 @@
#
# You should have received a copy of the GNU Lesser General Public License
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
import ifcopenshell
from typing import Optional
def add_layer(file, Name=None) -> None:
def add_layer(file: ifcopenshell.file, Name: Optional[str] = None) -> ifcopenshell.entity_instance:
"""Adds a new layer
An IFC layer is like a CAD layer. Portions of an object's geometry
@@ -41,6 +43,4 @@ def add_layer(file, Name=None) -> None:
ifcopenshell.api.run("layer.add_layer", model, Name="AI-WALL-FULL-DIMS-N")
"""
settings = {"Name": Name or "Unnamed"}
return file.create_entity("IfcPresentationLayerAssignment", Name=settings["Name"])
return file.create_entity("IfcPresentationLayerAssignment", Name=Name)
@@ -15,9 +15,11 @@
#
# You should have received a copy of the GNU Lesser General Public License
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
import ifcopenshell
from typing import Any
def edit_layer(file, layer=None, attributes=None) -> None:
def edit_layer(file: ifcopenshell.file, layer: ifcopenshell.entity_instance, attributes: dict[str, Any]) -> None:
"""Edits the attributes of an IfcPresentationLayerAssignment
For more information about the attributes and data types of an
@@ -26,7 +28,7 @@ def edit_layer(file, layer=None, attributes=None) -> None:
:param layer: The IfcPresentationLayerAssignment entity you want to edit
:type layer: ifcopenshell.entity_instance
:param attributes: a dictionary of attribute names and values.
:type attributes: dict, optional
:type attributes: dict
:return: None
:rtype: None
@@ -38,7 +40,7 @@ def edit_layer(file, layer=None, attributes=None) -> None:
ifcopenshell.api.run("layer.edit_layer", model,
layer=layer, attributes={"Description": "All walls, based on the AIA standard."})
"""
settings = {"layer": layer, "attributes": attributes or {}}
settings = {"layer": layer, "attributes": attributes}
for name, value in settings["attributes"].items():
setattr(settings["layer"], name, value)
@@ -15,9 +15,10 @@
#
# You should have received a copy of the GNU Lesser General Public License
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
import ifcopenshell
def remove_layer(file, layer=None) -> None:
def remove_layer(file: ifcopenshell.file, layer: ifcopenshell.entity_instance) -> None:
"""Removes a layer
All representation items assigned to the layer will remain, but the
@@ -35,6 +36,4 @@ def remove_layer(file, layer=None) -> None:
layer = ifcopenshell.api.run("layer.add_layer", model, Name="AI-WALL")
ifcopenshell.api.run("layer.remove_layer", model, layer=layer)
"""
settings = {"layer": layer}
file.remove(settings["layer"])
file.remove(layer)
@@ -21,7 +21,7 @@ import ifcopenshell.util.schema
import ifcopenshell.util.date
def add_library(file, name=None) -> None:
def add_library(file: ifcopenshell.entity_instance, name: str) -> ifcopenshell.entity_instance:
"""Adds a new library to the project
A library is an external data source that is related to the project. It
@@ -60,6 +60,4 @@ def add_library(file, name=None) -> None:
ifcopenshell.api.run("library.add_library", model, name="Brickschema")
"""
settings = {"name": name}
return file.create_entity("IfcLibraryInformation", Name=settings["name"])
return file.create_entity("IfcLibraryInformation", Name=name)
@@ -15,9 +15,11 @@
#
# You should have received a copy of the GNU Lesser General Public License
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
import ifcopenshell
from typing import Any
def edit_library(file, library=None, attributes=None) -> None:
def edit_library(file: ifcopenshell.file, library: ifcopenshell.entity_instance, attributes: dict[str, Any]) -> None:
"""Edits the attributes of an IfcLibraryInformation
For more information about the attributes and data types of an
@@ -26,7 +28,7 @@ def edit_library(file, library=None, attributes=None) -> None:
:param library: The IfcLibraryInformation entity you want to edit
:type library: ifcopenshell.entity_instance
:param attributes: a dictionary of attribute names and values.
:type attributes: dict, optional
:type attributes: dict
:return: None
:rtype: None
@@ -39,7 +41,7 @@ def edit_library(file, library=None, attributes=None) -> None:
attributes={"Description": "A Brickschema TTL including only mechanical distribution systems."})
"""
settings = {"library": library, "attributes": attributes or {}}
settings = {"library": library, "attributes": attributes}
for name, value in settings["attributes"].items():
setattr(settings["library"], name, value)
@@ -15,9 +15,13 @@
#
# You should have received a copy of the GNU Lesser General Public License
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
import ifcopenshell
from typing import Any
def edit_reference(file, reference=None, attributes=None) -> None:
def edit_reference(
file: ifcopenshell.file, reference: ifcopenshell.entity_instance, attributes: dict[str, Any]
) -> None:
"""Edits the attributes of an IfcLibraryReference
For more information about the attributes and data types of an
@@ -26,7 +30,7 @@ def edit_reference(file, reference=None, attributes=None) -> None:
:param reference: The IfcLibraryReference entity you want to edit
:type reference: ifcopenshell.entity_instance
:param attributes: a dictionary of attribute names and values.
:type attributes: dict, optional
:type attributes: dict
:return: None
:rtype: None
@@ -40,7 +44,7 @@ def edit_reference(file, reference=None, attributes=None) -> None:
ifcopenshell.api.run("library.edit_reference", model,
reference=reference, attributes={"Identification": "http://example.org/digitaltwin#AHU01"})
"""
settings = {"reference": reference, "attributes": attributes or {}}
settings = {"reference": reference, "attributes": attributes}
for name, value in settings["attributes"].items():
setattr(settings["reference"], name, value)
@@ -20,7 +20,7 @@ import ifcopenshell
import ifcopenshell.util.element
def remove_library(file, library=None) -> None:
def remove_library(file: ifcopenshell.file, library: ifcopenshell.entity_instance) -> None:
"""Removes a library
All references along with their relationships will also be removed. Any
@@ -15,9 +15,12 @@
#
# You should have received a copy of the GNU Lesser General Public License
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
import ifcopenshell
def add_constituent(file, constituent_set=None, material=None) -> None:
def add_constituent(
file: ifcopenshell.file, constituent_set: ifcopenshell.entity_instance, material: ifcopenshell.entity_instance
) -> ifcopenshell.entity_instance:
"""Adds a new constituent to a constituent set
A constituent describes how a portion of an object is made out of a
@@ -15,9 +15,12 @@
#
# You should have received a copy of the GNU Lesser General Public License
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
import ifcopenshell
def add_layer(file, layer_set=None, material=None) -> None:
def add_layer(
file: ifcopenshell.file, layer_set: ifcopenshell.entity_instance, material: ifcopenshell.entity_instance
) -> ifcopenshell.entity_instance:
"""Adds a new layer to a layer set
A layer represents a portion of material within a layered build up,
@@ -19,7 +19,9 @@
import ifcopenshell
def add_list_item(file, material_list=None, material=None) -> None:
def add_list_item(
file: ifcopenshell.file, material_list: ifcopenshell.entity_instance, material: ifcopenshell.entity_instance
) -> None:
"""Adds a new material in a list of materials
In IFC2X3, if you wanted an object to have multiple materials (i.e. a
@@ -15,9 +15,13 @@
#
# You should have received a copy of the GNU Lesser General Public License
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
import ifcopenshell
from typing import Optional
def add_material(file, name=None, category=None) -> None:
def add_material(
file: ifcopenshell.file, name: Optional[str] = None, category: Optional[str] = None
) -> ifcopenshell.entity_instance:
"""Adds a new material
A material in IFC represents a physical material, such as timber, steel,
@@ -48,7 +52,7 @@ def add_material(file, name=None, category=None) -> None:
:param name: The name of the material, typically tagged in a finishes
drawing or schedule.
:type name: str
:type name: str, optional
:param category: The category of the material.
:type category: str, optional
:return: The newly created IfcMaterial
@@ -15,9 +15,12 @@
#
# You should have received a copy of the GNU Lesser General Public License
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
import ifcopenshell
def add_material_set(file, name="Unnamed", set_type="IfcMaterialConstituentSet") -> None:
def add_material_set(
file: ifcopenshell.file, name: str = "Unnamed", set_type: str = "IfcMaterialConstituentSet"
) -> ifcopenshell.entity_instance:
"""Adds a new material set
IFC allows you to state that objects are made out of multiple materials.
@@ -19,7 +19,9 @@
import ifcopenshell.util.representation
def assign_profile(file, material_profile=None, profile=None) -> None:
def assign_profile(
file: ifcopenshell.file, material_profile: ifcopenshell.entity_instance, profile: ifcopenshell.entity_instance
) -> None:
"""Changes the profile curve of a material profile item in a profile set
In addition to changing the profile curve, it will also change the
@@ -94,7 +96,8 @@ def assign_profile(file, material_profile=None, profile=None) -> None:
class Usecase:
def execute(self):
file: ifcopenshell.file
def execute(self) -> None:
# TODO: handle composite profiles
old_profile = self.settings["material_profile"].Profile
self.settings["material_profile"].Profile = self.settings["profile"]
@@ -117,7 +120,7 @@ class Usecase:
# TODO: check remove deep
self.file.remove(old_profile)
def change_profile(self, element):
def change_profile(self, element: ifcopenshell.entity_instance) -> None:
representation = ifcopenshell.util.representation.get_representation(element, "Model", "Body", "MODEL_VIEW")
if not representation:
return
@@ -20,7 +20,7 @@ import ifcopenshell
import ifcopenshell.util.element
def copy_material(file, material=None) -> None:
def copy_material(file: ifcopenshell.file, material: ifcopenshell.entity_instance) -> ifcopenshell.entity_instance:
"""Copies a material
All material psets and styles are copied. The copied material is not
@@ -15,9 +15,11 @@
#
# You should have received a copy of the GNU Lesser General Public License
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
import ifcopenshell
from typing import Any
def edit_assigned_material(file, element=None, attributes=None) -> None:
def edit_assigned_material(file: ifcopenshell.file, element: ifcopenshell.entity_instance, attributes: dict[str, Any]) -> None:
"""Edits the attributes of an IfcMaterial
For more information about the attributes and data types of an
@@ -26,7 +28,7 @@ def edit_assigned_material(file, element=None, attributes=None) -> None:
:param element: The IfcMaterial entity you want to edit
:type element: ifcopenshell.entity_instance
:param attributes: a dictionary of attribute names and values.
:type attributes: dict, optional
:type attributes: dict
:return: None
:rtype: None
@@ -38,7 +40,7 @@ def edit_assigned_material(file, element=None, attributes=None) -> None:
ifcopenshell.api.run("material.edit_assigned_material", model,
element=concrete, attributes={"Description": "40MPA concrete with broom finish"})
"""
settings = {"element": element, "attributes": attributes or {}}
settings = {"element": element, "attributes": attributes}
for name, value in settings["attributes"].items():
setattr(settings["element"], name, value)
@@ -15,9 +15,16 @@
#
# You should have received a copy of the GNU Lesser General Public License
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
import ifcopenshell
from typing import Optional, Any
def edit_constituent(file, constituent=None, attributes=None, material=None) -> None:
def edit_constituent(
file: ifcopenshell.file,
constituent: ifcopenshell.entity_instance,
attributes: Optional[dict[str, Any]] = None,
material: Optional[ifcopenshell.entity_instance] = None,
) -> None:
"""Edits the attributes of an IfcMaterialConstituent
For more information about the attributes and data types of an
@@ -15,9 +15,16 @@
#
# You should have received a copy of the GNU Lesser General Public License
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
import ifcopenshell
from typing import Optional, Any
def edit_layer(file, layer=None, attributes=None, material=None) -> None:
def edit_layer(
file: ifcopenshell.file,
layer: ifcopenshell.entity_instance,
attributes: Optional[dict[str, Any]] = None,
material: Optional[ifcopenshell.entity_instance] = None,
) -> None:
"""Edits the attributes of an IfcMaterialLayer
For more information about the attributes and data types of an
@@ -15,9 +15,11 @@
#
# You should have received a copy of the GNU Lesser General Public License
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
import ifcopenshell
from typing import Any
def edit_layer_usage(file, usage=None, attributes=None) -> None:
def edit_layer_usage(file: ifcopenshell.file, usage: ifcopenshell.entity_instance, attributes: dict[str, Any]) -> None:
"""Edits the attributes of an IfcMaterialLayerSetUsage
This is typically used to change the offset from the reference line to
@@ -29,7 +31,7 @@ def edit_layer_usage(file, usage=None, attributes=None) -> None:
:param usage: The IfcMaterialLayerSetUsage entity you want to edit
:type usage: ifcopenshell.entity_instance
:param attributes: a dictionary of attribute names and values.
:type attributes: dict, optional
:type attributes: dict
:return: None
:rtype: None
@@ -73,7 +75,7 @@ def edit_layer_usage(file, usage=None, attributes=None) -> None:
ifcopenshell.api.run("material.edit_layer_usage", model,
usage=rel.RelatingMaterial, attributes={"OffsetFromReferenceLine": 200})
"""
settings = {"usage": usage, "attributes": attributes or {}}
settings = {"usage": usage, "attributes": attributes}
for name, value in settings["attributes"].items():
setattr(settings["usage"], name, value)
@@ -15,12 +15,12 @@
#
# You should have received a copy of the GNU Lesser General Public License
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
import ifcopenshell
from typing import Any
def edit_material(file, material=None, attributes=None) -> None:
def edit_material(file: ifcopenshell.file, material: ifcopenshell.entity_instance, attributes: dict[str, Any]) -> None:
"""Edits the attributes of an IfcMaterial"""
settings = {"material": material, "attributes": attributes or {}}
for name, value in settings["attributes"].items():
setattr(settings["material"], name, value)
for name, value in attributes.items():
setattr(material, name, value)
@@ -17,7 +17,17 @@
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
def edit_profile(file, profile=None, attributes=None, profile_def=None, material=None) -> None:
from typing import Any, Optional
import ifcopenshell
def edit_profile(
file: ifcopenshell.file,
profile: ifcopenshell.entity_instance,
attributes: Optional[dict[str, Any]] = None,
profile_def: Optional[ifcopenshell.entity_instance] = None,
material: Optional[ifcopenshell.entity_instance] = None,
) -> None:
"""Edits the attributes of an IfcMaterialProfile
For more information about the attributes and data types of an
@@ -15,12 +15,14 @@
#
# You should have received a copy of the GNU Lesser General Public License
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
import ifcopenshell.geom
import ifcopenshell.util.representation
from typing import Any
def edit_profile_usage(file, usage=None, attributes=None) -> None:
def edit_profile_usage(
file: ifcopenshell.file, usage: ifcopenshell.entity_instance, attributes: dict[str, Any]
) -> None:
"""Edits the attributes of an IfcMaterialProfileSetUsage
This is typically used to change the cardinal point of the profile.
@@ -15,9 +15,10 @@
#
# You should have received a copy of the GNU Lesser General Public License
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
import ifcopenshell
def remove_constituent(file, constituent=None) -> None:
def remove_constituent(file: ifcopenshell.file, constituent: ifcopenshell.entity_instance) -> None:
"""Removes a constituent from a constituent set
Note that it is invalid to have zero items in a set, so you should leave
@@ -15,9 +15,10 @@
#
# You should have received a copy of the GNU Lesser General Public License
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
import ifcopenshell
def remove_layer(file, layer=None) -> None:
def remove_layer(file: ifcopenshell.file, layer: ifcopenshell.entity_instance) -> None:
"""Removes a layer from a layer set
Note that it is invalid to have zero items in a set, so you should leave
@@ -19,7 +19,9 @@
import ifcopenshell
def remove_list_item(file, material_list=None, material_index=0) -> None:
def remove_list_item(
file: ifcopenshell.file, material_list: ifcopenshell.entity_instance, material_index: int = 0
) -> None:
"""Removes an item in an material list
Note that it is invalid to have zero items in a list, so you should leave
@@ -20,7 +20,7 @@ import ifcopenshell
import ifcopenshell.util.element
def remove_material(file, material=None) -> None:
def remove_material(file: ifcopenshell.file, material: ifcopenshell.entity_instance) -> None:
"""Removes a material
If the material is used in a material set, the corresponding layer,
@@ -20,7 +20,7 @@ import ifcopenshell
import ifcopenshell.util.element
def remove_material_set(file, material=None) -> None:
def remove_material_set(file: ifcopenshell.file, material: ifcopenshell.entity_instance) -> None:
"""Removes a material set
All set items, such as layers, profiles, or constituents will also be
@@ -21,7 +21,7 @@ import ifcopenshell
import ifcopenshell.util.element
def remove_profile(file, profile=None) -> None:
def remove_profile(file: ifcopenshell.file, profile: ifcopenshell.entity_instance) -> None:
"""Removes a profile item from a profile set
Note that it is invalid to have zero items in a set, so you should leave
@@ -15,9 +15,12 @@
#
# You should have received a copy of the GNU Lesser General Public License
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
import ifcopenshell
def reorder_set_item(file, material_set=None, old_index=0, new_index=0) -> None:
def reorder_set_item(
file: ifcopenshell.file, material_set: ifcopenshell.entity_instance, old_index: int = 0, new_index: int = 0
) -> None:
"""Reorders an item in a material set
In some material sets, the order have meaning, like in a layer set. In
@@ -21,15 +21,15 @@ import ifcopenshell.api
import ifcopenshell.util.element
def change_nest(file, item=None, new_parent=None) -> None:
def change_nest(
file: ifcopenshell.file, item: ifcopenshell.entity_instance, new_parent: ifcopenshell.entity_instance
) -> None:
"""Assigns a cost item to a new parent cost item"""
settings = {"item": item, "new_parent": new_parent}
if not settings["item"].Nests:
if not item.Nests:
return
nests = settings["item"].Nests[0]
nests = item.Nests[0]
related_objects = list(nests.RelatedObjects)
related_objects.remove(settings["item"])
related_objects.remove(item)
if related_objects:
nests.RelatedObjects = related_objects
ifcopenshell.api.run("owner.update_owner_history", file, **{"element": nests})
@@ -41,6 +41,6 @@ def change_nest(file, item=None, new_parent=None) -> None:
ifcopenshell.api.run(
"nest.assign_object",
file,
related_objects=[settings["item"]],
relating_object=settings["new_parent"],
related_objects=[item],
relating_object=new_parent,
)
@@ -15,19 +15,18 @@
#
# You should have received a copy of the GNU Lesser General Public License
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
import ifcopenshell
def reorder_nesting(file, item=None, old_index=0, new_index=0) -> None:
def reorder_nesting(
file: ifcopenshell.file, item: ifcopenshell.entity_instance, old_index: int = 0, new_index: int = 0
) -> None:
"""Reorders an item in a nesting set"""
settings = {"item": item, "old_index": old_index, "new_index": new_index}
if not settings["item"].Nests:
if not item.Nests:
return
nesting_set = settings["item"].Nests[0]
if not settings["old_index"]:
old_index = nesting_set.RelatedObjects.index(settings["item"])
else:
old_index = settings["old_index"]
nesting_set = item.Nests[0]
if not old_index:
old_index = nesting_set.RelatedObjects.index(item)
items = list(getattr(nesting_set, "RelatedObjects") or [])
items.insert(settings["new_index"], items.pop(old_index))
items.insert(new_index, items.pop(old_index))
setattr(nesting_set, "RelatedObjects", items)
@@ -19,9 +19,14 @@
import ifcopenshell
import ifcopenshell.api
from typing import Literal
def add_actor(file, actor=None, ifc_class="IfcActor") -> None:
def add_actor(
file: ifcopenshell.file,
actor: ifcopenshell.entity_instance,
ifc_class: Literal["IfcActor", "IfcOccupant"] = "IfcActor",
) -> ifcopenshell.entity_instance:
"""Adds a new actor
An actor is a person or an organisation who has a responsibility or role
@@ -15,9 +15,12 @@
#
# You should have received a copy of the GNU Lesser General Public License
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
import ifcopenshell
def add_address(file, assigned_object=None, ifc_class="IfcPostalAddress") -> None:
def add_address(
file: ifcopenshell.file, assigned_object: ifcopenshell.entity_instance, ifc_class: str = "IfcPostalAddress"
) -> ifcopenshell.entity_instance:
"""Add a new telecom or postal address to an organisation or person
A person or organisation may have associated contact details such as
@@ -17,15 +17,16 @@
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
import ifcopenshell.api
from typing import Optional
def add_application(
file,
application_developer=None,
version=None,
application_full_name="IfcOpenShell",
application_identifier="IfcOpenShell",
) -> None:
file: ifcopenshell.file,
application_developer: Optional[ifcopenshell.entity_instance] = None,
version: Optional[str] = None,
application_full_name: str = "IfcOpenShell",
application_identifier: str = "IfcOpenShell",
) -> ifcopenshell.entity_instance:
"""Adds a new application
IFC data may be associated with an authoring application to identify
@@ -46,6 +47,8 @@ def add_application(
:param application_identifier: An identification string for the
application intended for computers to read.
:type application_identifier: str, optional
:return: The newly created IfcApplication
:rtype: ifcopenshell.entity_instance
Example:
@@ -23,7 +23,7 @@ def add_person(
identification: str = "HSeldon",
family_name: str = "Seldon",
given_name: str = "Hari",
) -> None:
) -> ifcopenshell.entity_instance:
"""Adds a new person
Persons are used to identify a legal or liable representative of an
@@ -15,9 +15,10 @@
#
# You should have received a copy of the GNU Lesser General Public License
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
import ifcopenshell
def add_role(file, assigned_object=None, role="ARCHITECT") -> None:
def add_role(file: ifcopenshell.file, assigned_object: ifcopenshell.entity_instance, role: str = "ARCHITECT") -> ifcopenshell.entity_instance:
"""Adds and assigns a new role
People and organisations must play one or more roles on a project. Roles
@@ -32,7 +33,7 @@ def add_role(file, assigned_object=None, role="ARCHITECT") -> None:
be assigned to.
:type assigned_object: ifcopenshell.entity_instance
:param role: The type of role, taken from the IFC documentation for
IfcActorRole, or a custom name.
IfcActorRole, or a custom name. Defaults to "ARCHITECT".
:type role: str, optional
:return: The newly created IfcActorRole
:rtype: ifcopenshell.entity_instance
@@ -21,7 +21,9 @@ import ifcopenshell.api
import ifcopenshell.guid
def assign_actor(file, relating_actor=None, related_object=None) -> None:
def assign_actor(
file: ifcopenshell.file, relating_actor: ifcopenshell.entity_instance, related_object: ifcopenshell.entity_instance
) -> ifcopenshell.entity_instance:
"""Assigns an actor to an object
An actor may be assigned to objects which implies that the actor is
@@ -80,7 +82,7 @@ def assign_actor(file, relating_actor=None, related_object=None) -> None:
if settings["related_object"].HasAssignments:
for rel in settings["related_object"].HasAssignments:
if rel.is_a("IfcRelAssignsToActor") and rel.RelatingActor == settings["relating_actor"]:
return
return rel
rel = None
@@ -15,9 +15,11 @@
#
# You should have received a copy of the GNU Lesser General Public License
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
import ifcopenshell
from typing import Any
def edit_actor(file, actor=None, attributes=None) -> None:
def edit_actor(file: ifcopenshell.file, actor: ifcopenshell.entity_instance, attributes: dict[str, Any]) -> None:
"""Edits the attributes of an IfcActor
For more information about the attributes and data types of an
@@ -26,7 +28,7 @@ def edit_actor(file, actor=None, attributes=None) -> None:
:param actor: The IfcActor entity you want to edit
:type actor: ifcopenshell.entity_instance
:param attributes: a dictionary of attribute names and values.
:type attributes: dict, optional
:type attributes: dict
:return: None
:rtype: None
@@ -47,7 +49,7 @@ def edit_actor(file, actor=None, attributes=None) -> None:
ifcopenshell.api.run("actor.edit_actor", model,
actor=actor, attributes={"Description": "Responsible for buildings A, B, and C."})
"""
settings = {"actor": actor, "attributes": attributes or {}}
settings = {"actor": actor, "attributes": attributes}
for name, value in settings["attributes"].items():
setattr(settings["actor"], name, value)
@@ -15,9 +15,11 @@
#
# You should have received a copy of the GNU Lesser General Public License
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
import ifcopenshell
from typing import Any
def edit_address(file, address=None, attributes=None) -> None:
def edit_address(file: ifcopenshell.file, address: ifcopenshell.entity_instance, attributes: dict[str, Any]) -> None:
"""Edits the attributes of an IfcAddress
For more information about the attributes and data types of an
@@ -26,7 +28,7 @@ def edit_address(file, address=None, attributes=None) -> None:
:param address: The IfcAddress entity you want to edit
:type address: ifcopenshell.entity_instance
:param attributes: a dictionary of attribute names and values.
:type attributes: dict, optional
:type attributes: dict
:return: None
:rtype: None
@@ -49,7 +51,7 @@ def edit_address(file, address=None, attributes=None) -> None:
"ElectronicMailAddresses": ["bobthebuilder@example.com"],
"WWWHomePageURL": "https://thinkmoult.com"})
"""
settings = {"address": address, "attributes": attributes or {}}
settings = {"address": address, "attributes": attributes}
for name, value in settings["attributes"].items():
setattr(settings["address"], name, value)
@@ -15,9 +15,11 @@
#
# You should have received a copy of the GNU Lesser General Public License
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
import ifcopenshell
from typing import Any
def edit_organisation(file, organisation=None, attributes=None) -> None:
def edit_organisation(file: ifcopenshell.file, organisation: ifcopenshell.entity_instance, attributes: dict[str, Any]) -> None:
"""Edits the attributes of an IfcOrganization
For more information about the attributes and data types of an
@@ -26,7 +28,7 @@ def edit_organisation(file, organisation=None, attributes=None) -> None:
:param organisation: The IfcOrganization entity you want to edit
:type organisation: ifcopenshell.entity_instance
:param attributes: a dictionary of attribute names and values.
:type attributes: dict, optional
:type attributes: dict
:return: None
:rtype: None
@@ -39,7 +41,7 @@ def edit_organisation(file, organisation=None, attributes=None) -> None:
ifcopenshell.api.run("owner.edit_organisation", model, organisation=organisation,
attributes={"name": "Architects Without Ballpens"})
"""
settings = {"organisation": organisation, "attributes": attributes or {}}
settings = {"organisation": organisation, "attributes": attributes}
for name, value in settings["attributes"].items():
setattr(settings["organisation"], name, value)
@@ -15,9 +15,11 @@
#
# You should have received a copy of the GNU Lesser General Public License
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
import ifcopenshell
from typing import Any
def edit_person(file, person=None, attributes=None) -> None:
def edit_person(file: ifcopenshell.file, person: ifcopenshell.entity_instance, attributes: dict[str, Any]) -> None:
"""Edits the attributes of an IfcPerson
For more information about the attributes and data types of an
@@ -26,7 +28,7 @@ def edit_person(file, person=None, attributes=None) -> None:
:param person: The IfcPerson entity you want to edit
:type person: ifcopenshell.entity_instance
:param attributes: a dictionary of attribute names and values.
:type attributes: dict, optional
:type attributes: dict
:return: None
:rtype: None
@@ -39,7 +41,7 @@ def edit_person(file, person=None, attributes=None) -> None:
ifcopenshell.api.run("owner.edit_person", model, person=person,
attributes={"MiddleNames": ["The"], "FamilyName": "Builder"})
"""
settings = {"person": person, "attributes": attributes or {}}
settings = {"person": person, "attributes": attributes}
for name, value in settings["attributes"].items():
setattr(settings["person"], name, value)
@@ -15,9 +15,11 @@
#
# You should have received a copy of the GNU Lesser General Public License
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
import ifcopenshell
from typing import Any
def edit_role(file, role=None, attributes=None) -> None:
def edit_role(file: ifcopenshell.file, role: ifcopenshell.entity_instance, attributes: dict[str, Any]) -> None:
"""Edits the attributes of an IfcActorRole
For more information about the attributes and data types of an
@@ -26,7 +28,7 @@ def edit_role(file, role=None, attributes=None) -> None:
:param role: The IfcActorRole entity you want to edit
:type role: ifcopenshell.entity_instance
:param attributes: a dictionary of attribute names and values.
:type attributes: dict, optional
:type attributes: dict
:return: None
:rtype: None
@@ -43,7 +45,7 @@ def edit_role(file, role=None, attributes=None) -> None:
# But Bob is not an architect
ifcopenshell.api.run("owner.edit_role", model, role=role, attributes={"Role": "CONSTRUCTIONMANAGER"})
"""
settings = {"role": role, "attributes": attributes or {}}
settings = {"role": role, "attributes": attributes}
for name, value in settings["attributes"].items():
setattr(settings["role"], name, value)
@@ -20,7 +20,7 @@ import ifcopenshell
import ifcopenshell.util.element
def remove_actor(file, actor=None) -> None:
def remove_actor(file: ifcopenshell.file, actor: ifcopenshell.entity_instance) -> None:
"""Removes an actor
:param actor: The IfcActor to remove.
@@ -15,9 +15,10 @@
#
# You should have received a copy of the GNU Lesser General Public License
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
import ifcopenshell
def remove_address(file, address=None) -> None:
def remove_address(file: ifcopenshell.file, address: ifcopenshell.entity_instance) -> None:
"""Removes an address
Naturally, any organisations or people using that address will have the
@@ -15,9 +15,10 @@
#
# You should have received a copy of the GNU Lesser General Public License
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
import ifcopenshell
def remove_application(file, application=None) -> None:
def remove_application(file: ifcopenshell.file, application: ifcopenshell.entity_instance) -> None:
"""Removes an application
Warning: removing an application may invalidate ownership histories.
@@ -19,7 +19,7 @@
import ifcopenshell.api
def remove_organisation(file, organisation=None) -> None:
def remove_organisation(file: ifcopenshell.file, organisation: ifcopenshell.entity_instance) -> None:
"""Remove an organisation
All roles and addresses assigned to the organisation will also be
@@ -19,7 +19,7 @@
import ifcopenshell.api
def remove_person(file, person=None) -> None:
def remove_person(file: ifcopenshell.file, person: ifcopenshell.entity_instance) -> None:
"""Remove an person
All roles and addresses assigned to the person will also be
@@ -19,7 +19,9 @@
import ifcopenshell.api
def remove_person_and_organisation(file, person_and_organisation=None) -> None:
def remove_person_and_organisation(
file: ifcopenshell.file, person_and_organisation: ifcopenshell.entity_instance
) -> None:
"""Removes a person and organisation
Note that the underlying person and organisation is not removed, only
@@ -15,9 +15,10 @@
#
# You should have received a copy of the GNU Lesser General Public License
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
import ifcopenshell
def remove_role(file, role=None) -> None:
def remove_role(file: ifcopenshell.file, role: ifcopenshell.entity_instance) -> None:
"""Removes a role
People and organisations using the role will be untouched. This may
@@ -21,7 +21,9 @@ import ifcopenshell.api
import ifcopenshell.util.element
def unassign_actor(file, relating_actor=None, related_object=None) -> None:
def unassign_actor(
file: ifcopenshell.file, relating_actor: ifcopenshell.entity_instance, related_object: ifcopenshell.entity_instance
) -> None:
"""Unassigns an actor to an object
This means that the actor is no longer responsible for the object.
@@ -30,9 +32,8 @@ def unassign_actor(file, relating_actor=None, related_object=None) -> None:
:type relating_actor: ifcopenshell.entity_instance
:param related_object: The object the actor is responsible for.
:type related_object: ifcopenshell.entity_instance
:return: The updated IfcRelAssignsToActor relationship or none if there
is no more valid relationship.
:rtype: None, ifcopenshell.entity_instance
:return: None
:rtype: None
Example:
@@ -72,4 +73,3 @@ def unassign_actor(file, relating_actor=None, related_object=None) -> None:
related_objects.remove(settings["related_object"])
rel.RelatedObjects = related_objects
ifcopenshell.api.run("owner.update_owner_history", file, **{"element": rel})
return rel
@@ -17,9 +17,12 @@
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
import ifcopenshell.util.unit
from typing import Optional
def add_arbitrary_profile(file, profile=None, name=None) -> None:
def add_arbitrary_profile(
file: ifcopenshell.file, profile: list[tuple[float, float]], name: Optional[str] = None
) -> ifcopenshell.entity_instance:
"""Adds a new arbitrary polyline-based profile
The profile is represented as a polyline defined by a list of
@@ -30,7 +33,7 @@ def add_arbitrary_profile(file, profile=None, name=None) -> None:
identical.
:param profile: A list of coordinates
:type profile: list[list[float]]
:type profile: list[tuple[float, float]]
:param name: If the profile is semantically significant (i.e. to be
managed and reused by the user) then it must be named. Otherwise,
this may be left as none.
@@ -17,9 +17,15 @@
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
import ifcopenshell.util.unit
from typing import Optional
def add_arbitrary_profile_with_voids(file, outer_profile=None, inner_profiles=None, name=None) -> None:
def add_arbitrary_profile_with_voids(
file: ifcopenshell.file,
outer_profile: list[tuple[float, float]],
inner_profiles: list[list[tuple[float, float]]],
name: Optional[str] = None,
) -> ifcopenshell.entity_instance:
"""Adds a new arbitrary polyline-based profile with voids
The outer profile is represented as a polyline defined by a list of
@@ -35,9 +41,9 @@ def add_arbitrary_profile_with_voids(file, outer_profile=None, inner_profiles=No
provided in SI meters.
:param outer_profile: A list of coordinates
:type profile: list[float]
:type profile: list[tuple[float, float]]
:param inner_profiles: A list of polylines
:type profile: list[list[float]]
:type profile: list[list[tuple[float, float]]]
:param name: If the profile is semantically significant (i.e. to be
managed and reused by the user) then it must be named. Otherwise,
this may be left as none.
@@ -15,9 +15,10 @@
#
# You should have received a copy of the GNU Lesser General Public License
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
import ifcopenshell
def add_parameterized_profile(file, ifc_class=None) -> None:
def add_parameterized_profile(file: ifcopenshell.file, ifc_class: str) -> ifcopenshell.entity_instance:
"""Adds a new parameterised profile
IFC offers parameterised profiles for common standardised hot roll
@@ -15,9 +15,11 @@
#
# You should have received a copy of the GNU Lesser General Public License
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
import ifcopenshell
from typing import Any
def edit_profile(file, profile=None, attributes=None) -> None:
def edit_profile(file: ifcopenshell.file, profile: ifcopenshell.entity_instance, attributes: dict[str, Any]) -> None:
"""Edits the attributes of an IfcProfileDef
For more information about the attributes and data types of an
@@ -26,7 +28,7 @@ def edit_profile(file, profile=None, attributes=None) -> None:
:param profile: The IfcProfileDef entity you want to edit
:type profile: ifcopenshell.entity_instance
:param attributes: a dictionary of attribute names and values.
:type attributes: dict, optional
:type attributes: dict
:return: None
:rtype: None
@@ -41,7 +43,7 @@ def edit_profile(file, profile=None, attributes=None) -> None:
ifcopenshell.api.run("profile.edit_profile", model,
profile=circle, attributes={"ProfileName": "1000mm Dia"})
"""
settings = {"profile": profile, "attributes": attributes or {}}
settings = {"profile": profile, "attributes": attributes}
for name, value in settings["attributes"].items():
setattr(settings["profile"], name, value)
@@ -20,7 +20,7 @@ import ifcopenshell
import ifcopenshell.util.element
def remove_profile(file, profile=None) -> None:
def remove_profile(file: ifcopenshell.file, profile: ifcopenshell.entity_instance) -> None:
"""Removes a profile
:param profile: The IfcProfileDef to remove.
@@ -19,7 +19,8 @@
import ifcopenshell
import ifcopenshell.api
import ifcopenshell.api.owner.settings
from typing import Optional
import ifcopenshell.util.element
from typing import Optional, Any, Union
def append_asset(
@@ -124,6 +125,9 @@ def append_asset(
class Usecase:
file: ifcopenshell.file
settings: dict[str, Any]
def execute(self):
# mapping of old element ids to new elements
self.added_elements: dict[int, ifcopenshell.entity_instance] = {}
@@ -223,7 +227,7 @@ class Usecase:
return element
def add_element(self, element):
def add_element(self, element: ifcopenshell.entity_instance) -> Union[ifcopenshell.entity_instance, None]:
if element.id() == 0:
return
existing_element = self.get_existing_element(element)
@@ -262,7 +266,7 @@ class Usecase:
elif value:
return True
def check_inverses(self, element):
def check_inverses(self, element: ifcopenshell.entity_instance) -> None:
for source_class, attributes in self.whitelisted_inverse_attributes.items():
if not element.is_a(source_class):
continue
@@ -19,6 +19,7 @@
import datetime
from re import findall
from dateutil import parser
from typing import Literal, Union, Any
try:
import isodate
@@ -104,7 +105,18 @@ def readable_ifc_duration(string):
return final_string
def datetime2ifc(dt, ifc_type):
def datetime2ifc(
dt: Union[datetime.date, str],
ifc_type: Literal[
"IfcDuration",
"IfcTimeStamp",
"IfcDateTime",
"IfcDate",
"IfcTime",
"IfcCalendarDate",
"IfcLocalTime",
],
) -> Union[int, str, dict[str, Any]]:
if isinstance(dt, str):
if ifc_type == "IfcDuration":
return dt
@@ -145,6 +157,7 @@ def datetime2ifc(dt, ifc_type):
"MinuteComponent": dt.minute,
"SecondComponent": dt.second,
}
raise TypeError(f"Unsupported ifc_type for conversion from datetime.datetime = {ifc_type}.")
def string_to_date(string):