This commit is contained in:
Andrej730
2025-03-25 12:05:55 +05:00
parent 244320dd49
commit d35a2dcf5b
22 changed files with 688 additions and 329 deletions
@@ -65,28 +65,22 @@ def assign_material(
:param products: The list of IfcProducts to assign the material or material set
to.
:type products: list[ifcopenshell.entity_instance]
:param type: Choose from "IfcMaterial", "IfcMaterialConstituentSet",
"IfcMaterialLayerSet", "IfcMaterialLayerSetUsage",
"IfcMaterialProfileSet", "IfcMaterialProfileSetUsage", or
"IfcMaterialList". Note that "Set Usages" may only be assigned to
occurrences, not types. Defaults to "IfcMaterial".
:type type: str
:param material: The IfcMaterial or material set you are assigning here.
If type is Usage then no need to provide `material`, it will be deduced
from the element type automatically.
If IfcMaterial is provided as material and type is not IfcMaterial,
provided material will be ignored except for IfcMaterialList
where it will be used as part of the list.
:type material: ifcopenshell.entity_instance, optional
:return: IfcRelAssociatesMaterial entity
or a list of IfcRelAssociatesMaterial entities
(possible if `type` is Usage
and `products` require different Usages)
or `None` if `products` was empty list.
:rtype: Union[
ifcopenshell.entity_instance,
list[ifcopenshell.entity_instance], None]
Example:
@@ -62,6 +62,8 @@ def remove_material_set(file: ifcopenshell.file, material: ifcopenshell.entity_i
set_items = material.MaterialConstituents or []
elif material.is_a("IfcMaterialList"):
set_items = []
else:
raise ValueError(f"Unknown material set type: {material.is_a()}")
for set_item in set_items:
file.remove(set_item)
file.remove(material)
@@ -32,9 +32,7 @@ def unassign_material(file: ifcopenshell.file, products: list[ifcopenshell.entit
If the product does not have a material, nothing happens.
:param products: The list IfcProducts that may or may not have a material
:type product: list[ifcopenshell.entity_instance]
:return: None
:rtype: None
Example:
@@ -54,18 +52,16 @@ def unassign_material(file: ifcopenshell.file, products: list[ifcopenshell.entit
"""
usecase = Usecase()
usecase.file = file
usecase.settings = {"products": products}
return usecase.execute()
return usecase.execute(products)
class Usecase:
file: ifcopenshell.file
settings: dict[str, Any]
def execute(self):
self.products = set(self.settings["products"])
if not self.products:
def execute(self, products: list[ifcopenshell.entity_instance]) -> None:
if not products:
return
self.products = set(products)
self.remove_material_usages_from_types()
self.unassign_materials()