mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-10 09:48:32 +00:00
system.assign_system - support batching #4474
This commit is contained in:
@@ -79,6 +79,9 @@ ARGUMENTS_DEPRECATION = {
|
||||
"type.unassign_type": partial(
|
||||
batching_argument_deprecation, prev_argument="related_object", new_argument="related_objects"
|
||||
),
|
||||
"system.assign_system": partial(
|
||||
batching_argument_deprecation, prev_argument="product", new_argument="products"
|
||||
),
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
|
||||
import ifcopenshell
|
||||
import ifcopenshell.api
|
||||
from typing import Union
|
||||
|
||||
|
||||
class Usecase:
|
||||
@@ -34,7 +35,8 @@ class Usecase:
|
||||
:param group: The IfcGroup to assign the products to
|
||||
:type group: ifcopenshell.entity_instance.entity_instance
|
||||
:return: The IfcRelAssignsToGroup relationship
|
||||
:rtype: ifcopenshell.entity_instance.entity_instance
|
||||
or `None` if `products` was empty list.
|
||||
:rtype: Union[ifcopenshell.entity_instance.entity_instance, None]
|
||||
|
||||
Example:
|
||||
|
||||
@@ -50,7 +52,10 @@ class Usecase:
|
||||
"group": group,
|
||||
}
|
||||
|
||||
def execute(self) -> ifcopenshell.entity_instance:
|
||||
def execute(self) -> Union[ifcopenshell.entity_instance, None]:
|
||||
if not self.settings["products"]:
|
||||
return
|
||||
|
||||
if not self.settings["group"].IsGroupedBy:
|
||||
return self.file.create_entity(
|
||||
"IfcRelAssignsToGroup",
|
||||
|
||||
@@ -22,17 +22,23 @@ import ifcopenshell.util.system
|
||||
|
||||
|
||||
class Usecase:
|
||||
def __init__(self, file, product=None, system=None):
|
||||
"""Assigns a distribution element to a system
|
||||
def __init__(
|
||||
self,
|
||||
file: ifcopenshell.file,
|
||||
products: list[ifcopenshell.entity_instance],
|
||||
system: ifcopenshell.entity_instance,
|
||||
):
|
||||
"""Assigns distribution elements to a system
|
||||
|
||||
Note that it is not necessary to assign distribution ports to a system.
|
||||
|
||||
:param product: The IfcDistributionElement to assign to the system.
|
||||
:type product: ifcopenshell.entity_instance.entity_instance
|
||||
:param products: The list of IfcDistributionElements to assign to the system.
|
||||
:type products: list[ifcopenshell.entity_instance.entity_instance]
|
||||
:param system: The IfcSystem you want to assign the element to.
|
||||
:type system: ifcopenshell.entity_instance.entity_instance
|
||||
:return: The IfcRelAssignsToGroup relationship
|
||||
:rtype: ifcopenshell.entity_instance.entity_instance
|
||||
or `None` if `products` was empty list.
|
||||
:rtype: [ifcopenshell.entity_instance.entity_instance, None]
|
||||
|
||||
Example:
|
||||
|
||||
@@ -46,32 +52,20 @@ class Usecase:
|
||||
ifc_class="IfcDuctSegment", predefined_type="RIGIDSEGMENT")
|
||||
|
||||
# This duct is part of the system
|
||||
ifcopenshell.api.run("system.assign_system", model, product=duct, system=system)
|
||||
ifcopenshell.api.run("system.assign_system", model, products=[duct], system=system)
|
||||
"""
|
||||
self.file = file
|
||||
self.settings = {
|
||||
"product": product,
|
||||
"products": products,
|
||||
"system": system,
|
||||
}
|
||||
|
||||
def execute(self):
|
||||
system = self.settings["system"]
|
||||
product = self.settings["product"]
|
||||
if not ifcopenshell.util.system.is_assignable(product, system):
|
||||
raise TypeError(f"You cannot assign an {product.is_a()} to an {system.is_a()}")
|
||||
products = self.settings["products"]
|
||||
|
||||
if not self.settings["system"].IsGroupedBy:
|
||||
return self.file.create_entity(
|
||||
"IfcRelAssignsToGroup",
|
||||
**{
|
||||
"GlobalId": ifcopenshell.guid.new(),
|
||||
"OwnerHistory": ifcopenshell.api.run("owner.create_owner_history", self.file),
|
||||
"RelatedObjects": [self.settings["product"]],
|
||||
"RelatingGroup": self.settings["system"],
|
||||
},
|
||||
)
|
||||
rel = self.settings["system"].IsGroupedBy[0]
|
||||
related_objects = set(rel.RelatedObjects) or set()
|
||||
related_objects.add(self.settings["product"])
|
||||
rel.RelatedObjects = list(related_objects)
|
||||
ifcopenshell.api.run("owner.update_owner_history", self.file, **{"element": rel})
|
||||
if not all(ifcopenshell.util.system.is_assignable(failed_product := product, system) for product in products):
|
||||
raise TypeError(f"You cannot assign an {failed_product.is_a()} to an {system.is_a()}")
|
||||
|
||||
rel = ifcopenshell.api.run("group.assign_group", self.file, products=products, group=system)
|
||||
return rel
|
||||
|
||||
@@ -77,8 +77,8 @@ class Usecase:
|
||||
ifc_class="IfcDuctFitting", predefined_type="BEND")
|
||||
|
||||
# The duct and fitting is part of the system
|
||||
ifcopenshell.api.run("system.assign_system", model, product=duct, system=system)
|
||||
ifcopenshell.api.run("system.assign_system", model, product=fitting, system=system)
|
||||
ifcopenshell.api.run("system.assign_system", model, products=[duct], system=system)
|
||||
ifcopenshell.api.run("system.assign_system", model, products=[fitting], system=system)
|
||||
|
||||
# Create 2 ports, one for either end of both the duct and fitting.
|
||||
duct_port1 = ifcopenshell.api.run("system.add_port", model, element=duct)
|
||||
|
||||
@@ -47,8 +47,8 @@ class Usecase:
|
||||
ifc_class="IfcDuctFitting", predefined_type="BEND")
|
||||
|
||||
# The duct and fitting is part of the system
|
||||
ifcopenshell.api.run("system.assign_system", model, product=duct, system=system)
|
||||
ifcopenshell.api.run("system.assign_system", model, product=fitting, system=system)
|
||||
ifcopenshell.api.run("system.assign_system", model, products=[duct], system=system)
|
||||
ifcopenshell.api.run("system.assign_system", model, products=[fitting], system=system)
|
||||
|
||||
# Create 2 ports, one for either end of both the duct and fitting.
|
||||
duct_port1 = ifcopenshell.api.run("system.add_port", model, element=duct)
|
||||
|
||||
@@ -44,7 +44,7 @@ class Usecase:
|
||||
ifc_class="IfcDuctSegment", predefined_type="RIGIDSEGMENT")
|
||||
|
||||
# This duct is part of the system
|
||||
ifcopenshell.api.run("system.assign_system", model, product=duct, system=system)
|
||||
ifcopenshell.api.run("system.assign_system", model, products=[duct], system=system)
|
||||
|
||||
# Not anymore!
|
||||
ifcopenshell.api.run("system.unassign_system", model, product=duct, system=system)
|
||||
|
||||
Reference in New Issue
Block a user