This commit is contained in:
Andrej730
2025-03-14 10:43:47 +05:00
parent 10ecac33b8
commit 0e8810c1f5
118 changed files with 869 additions and 1203 deletions
@@ -40,11 +40,8 @@ def add_list_item(
:param material_list: The IfcMaterialList the material should be added
to.
:type material_list: ifcopenshell.entity_instance
:param material: The IfcMaterial to add to the list
:type material: ifcopenshell.entity_instance
:return: None
:rtype: None
Example:
@@ -80,8 +77,6 @@ def add_list_item(
# aluminium and glass.
ifcopenshell.api.material.assign_material(model, products=[window_type], material=material_set)
"""
settings = {"material_list": material_list, "material": material}
materials = list(settings["material_list"].Materials or [])
materials.append(settings["material"])
settings["material_list"].Materials = materials
materials = list(material_list.Materials or [])
materials.append(material)
material_list.Materials = materials
@@ -58,13 +58,9 @@ def add_material(
:param name: The name of the material, typically tagged in a finishes
drawing or schedule.
:type name: str, optional
:param category: The category of the material.
:type category: str, optional
:param description: A description of the material.
:type description: str, optional
:return: The newly created IfcMaterial
:rtype: ifcopenshell.entity_instance
Example:
@@ -81,11 +77,9 @@ def add_material(
# "Style" has been specified.
ifcopenshell.api.material.assign_material(model, products=[concrete_bench], material=concrete)
"""
settings = {"name": name or "Unnamed", "category": category, "description": description}
material = file.create_entity("IfcMaterial", **{"Name": settings["name"] or "Unnamed"})
if settings["category"]:
material.Category = settings["category"]
if settings["description"]:
material.Description = settings["description"]
material = file.create_entity("IfcMaterial", **{"Name": name or "Unnamed"})
if category:
material.Category = category
if description:
material.Description = description
return material
@@ -68,14 +68,11 @@ def add_material_set(
:param name: The name of the material set, which may be purely
descriptive or annotated in drawings. Defaults to "Unnamed".
:type name: str, optional
:param set_type: What type of set you want to create, chosen from
IfcMaterialLayerSet, IfcMaterialProfileSet,
IfcMaterialConstituentSet, or IfcMaterialList. Defaults to
IfcMaterialConstituentSet.
:type set_type: str, optional
:return: The newly created material set element
:rtype: ifcopenshell.entity_instance
Example:
@@ -113,10 +110,8 @@ def add_material_set(
# Great! Let's assign our material set to our wall type.
ifcopenshell.api.material.assign_material(model, products=[wall_type], material=material_set)
"""
settings = {"name": name or "Unnamed", "set_type": set_type}
if settings["set_type"] == "IfcMaterialLayerSet":
return file.create_entity("IfcMaterialLayerSet", LayerSetName=settings["name"] or "Unnamed")
elif settings["set_type"] == "IfcMaterialList":
if set_type == "IfcMaterialLayerSet":
return file.create_entity("IfcMaterialLayerSet", LayerSetName=name or "Unnamed")
elif set_type == "IfcMaterialList":
return file.create_entity("IfcMaterialList")
return file.create_entity(settings["set_type"], Name=settings["name"] or "Unnamed")
return file.create_entity(set_type, Name=name or "Unnamed")
@@ -29,9 +29,7 @@ def remove_material(file: ifcopenshell.file, material: ifcopenshell.entity_insta
take care of this situation themselves.
:param material: The IfcMaterial entity you want to remove
:type material: ifcopenshell.entity_instance
:return: None
:rtype: None
Example:
@@ -43,10 +41,8 @@ def remove_material(file: ifcopenshell.file, material: ifcopenshell.entity_insta
# ... and remove it
ifcopenshell.api.material.remove_material(model, material=aluminium)
"""
settings = {"material": material}
inverse_elements = file.get_inverse(settings["material"])
file.remove(settings["material"])
inverse_elements = file.get_inverse(material)
file.remove(material)
# TODO: Right now, we we choose only to delete set items (e.g. a layer) but not the material set
# This can lead to invalid material sets, but we assume the user will deal with it
for inverse in inverse_elements:
@@ -29,9 +29,7 @@ def remove_material_set(file: ifcopenshell.file, material: ifcopenshell.entity_i
:param material: The IfcMaterialLayerSet, IfcMaterialConstituentSet,
IfcMaterialProfileSet entity you want to remove.
:type material: ifcopenshell.entity_instance
:return: None
:rtype: None
Example:
@@ -55,20 +53,18 @@ def remove_material_set(file: ifcopenshell.file, material: ifcopenshell.entity_i
ifcopenshell.api.material.remove_material_set(model, material=material_set)
"""
settings = {"material": material}
inverse_elements = file.get_inverse(settings["material"])
if settings["material"].is_a("IfcMaterialLayerSet"):
set_items = settings["material"].MaterialLayers or []
elif settings["material"].is_a("IfcMaterialProfileSet"):
set_items = settings["material"].MaterialProfiles or []
elif settings["material"].is_a("IfcMaterialConstituentSet"):
set_items = settings["material"].MaterialConstituents or []
elif settings["material"].is_a("IfcMaterialList"):
inverse_elements = file.get_inverse(material)
if material.is_a("IfcMaterialLayerSet"):
set_items = material.MaterialLayers or []
elif material.is_a("IfcMaterialProfileSet"):
set_items = material.MaterialProfiles or []
elif material.is_a("IfcMaterialConstituentSet"):
set_items = material.MaterialConstituents or []
elif material.is_a("IfcMaterialList"):
set_items = []
for set_item in set_items:
file.remove(set_item)
file.remove(settings["material"])
file.remove(material)
for inverse in inverse_elements:
if inverse.is_a("IfcRelAssociatesMaterial"):
history = inverse.OwnerHistory