diff --git a/src/ifcopenshell-python/ifcopenshell/api/material/add_constituent.py b/src/ifcopenshell-python/ifcopenshell/api/material/add_constituent.py index 046710d557..3a2dad4ba2 100644 --- a/src/ifcopenshell-python/ifcopenshell/api/material/add_constituent.py +++ b/src/ifcopenshell-python/ifcopenshell/api/material/add_constituent.py @@ -16,10 +16,14 @@ # You should have received a copy of the GNU Lesser General Public License # along with IfcOpenShell. If not, see . import ifcopenshell +from typing import Optional def add_constituent( - file: ifcopenshell.file, constituent_set: ifcopenshell.entity_instance, material: ifcopenshell.entity_instance + file: ifcopenshell.file, + constituent_set: ifcopenshell.entity_instance, + material: ifcopenshell.entity_instance, + name: Optional[str] = None, ) -> ifcopenshell.entity_instance: """Adds a new constituent to a constituent set @@ -40,11 +44,9 @@ def add_constituent( constituent is part of. The constituent set represents a group of constituents. See ifcopenshell.api.material.add_material_set for information on how to add a constituent set. - :type constituent_set: ifcopenshell.entity_instance :param material: The IfcMaterial that the constituent is made out of. - :type material: ifcopenshell.entity_instance + :param name: An optional name of the constituent. :return: The newly created IfcMaterialConstituent - :rtype: ifcopenshell.entity_instance Example: @@ -71,9 +73,9 @@ def add_constituent( # Now let's use those materials as two constituents in our set. ifcopenshell.api.material.add_constituent(model, - constituent_set=material_set, material=aluminium) + constituent_set=material_set, material=aluminium, name="Framing") ifcopenshell.api.material.add_constituent(model, - constituent_set=material_set, material=glass) + constituent_set=material_set, material=glass, name="Glazing") # Great! Let's assign our material set to our window type. # We're technically not done here, we might want to add geometry to @@ -82,10 +84,8 @@ def add_constituent( # aluminium and glass. ifcopenshell.api.material.assign_material(model, products=[window_type], material=material_set) """ - settings = {"constituent_set": constituent_set, "material": material} - - constituents = list(settings["constituent_set"].MaterialConstituents or []) - constituent = file.create_entity("IfcMaterialConstituent", **{"Material": settings["material"]}) + constituents = list(constituent_set.MaterialConstituents or []) + constituent = file.create_entity("IfcMaterialConstituent", Material=material, Name=name) constituents.append(constituent) - settings["constituent_set"].MaterialConstituents = constituents + constituent_set.MaterialConstituents = constituents return constituent diff --git a/src/ifcopenshell-python/ifcopenshell/api/material/add_layer.py b/src/ifcopenshell-python/ifcopenshell/api/material/add_layer.py index 37bdac03bc..8284d641f2 100644 --- a/src/ifcopenshell-python/ifcopenshell/api/material/add_layer.py +++ b/src/ifcopenshell-python/ifcopenshell/api/material/add_layer.py @@ -17,10 +17,14 @@ # along with IfcOpenShell. If not, see . import ifcopenshell import ifcopenshell.util.unit +from typing import Optional def add_layer( - file: ifcopenshell.file, layer_set: ifcopenshell.entity_instance, material: ifcopenshell.entity_instance + file: ifcopenshell.file, + layer_set: ifcopenshell.entity_instance, + material: ifcopenshell.entity_instance, + name: Optional[str] = None, ) -> ifcopenshell.entity_instance: """Adds a new layer to a layer set @@ -39,11 +43,9 @@ def add_layer( layer set represents a group of layers. See ifcopenshell.api.material.add_material_set for more information on how to add a layer set. - :type layer_set: ifcopenshell.entity_instance :param material: The IfcMaterial that the layer is made out of. - :type material: ifcopenshell.entity_instance + :param name: An optional name of the layer. :return: The newly created IfcMaterialLayer - :rtype: ifcopenshell.entity_instance Example: @@ -82,12 +84,8 @@ def add_layer( ifcopenshell.api.material.assign_material(model, products=[wall_type], material=material_set) """ unit_scale = ifcopenshell.util.unit.calculate_unit_scale(file) - settings = {"layer_set": layer_set, "material": material} - - layers = list(settings["layer_set"].MaterialLayers or []) - layer = file.create_entity( - "IfcMaterialLayer", **{"Material": settings["material"], "LayerThickness": 0.1 / unit_scale} - ) + layers = list(layer_set.MaterialLayers or []) + layer = file.create_entity("IfcMaterialLayer", Material=material, LayerThickness=0.1 / unit_scale, Name=name) layers.append(layer) - settings["layer_set"].MaterialLayers = layers + layer_set.MaterialLayers = layers return layer diff --git a/src/ifcopenshell-python/ifcopenshell/api/material/add_profile.py b/src/ifcopenshell-python/ifcopenshell/api/material/add_profile.py index efc345ef37..b62d5e2ef3 100644 --- a/src/ifcopenshell-python/ifcopenshell/api/material/add_profile.py +++ b/src/ifcopenshell-python/ifcopenshell/api/material/add_profile.py @@ -24,6 +24,7 @@ def add_profile( profile_set: ifcopenshell.entity_instance, material: Optional[ifcopenshell.entity_instance] = None, profile: Optional[ifcopenshell.entity_instance] = None, + name: Optional[str] = None, ) -> ifcopenshell.entity_instance: """Add a new profile item to a profile set @@ -48,14 +49,12 @@ def add_profile( profile set represents a group of profile items. See ifcopenshell.api.material.add_material_set for more information on how to add a profile set. - :type profile_set: ifcopenshell.entity_instance :param material: The IfcMaterial that the profile item is made out of. - :type material: ifcopenshell.entity_instance, optional :param profile: The IfcProfileDef that represents the 2D cross section of the the profile item. - :type profile: ifcopenshell.entity_instance, optional + :param name: An optional name of the material profile (not the geometric + profile). :return: The newly created IfcMaterialProfile - :rtype: ifcopenshell.entity_instance Example: @@ -90,14 +89,12 @@ def add_profile( # Great! Let's assign our material set to our beam type. ifcopenshell.api.material.assign_material(model, products=[beam_type], material=material_set) """ - settings = {"profile_set": profile_set, "material": material, "profile": profile} - - profiles = list(settings["profile_set"].MaterialProfiles or []) - profile = file.create_entity("IfcMaterialProfile") - if settings["material"]: - profile.Material = settings["material"] - if settings["profile"]: - profile.Profile = settings["profile"] - profiles.append(profile) - settings["profile_set"].MaterialProfiles = profiles - return profile + profiles = list(profile_set.MaterialProfiles or []) + mat_profile = file.create_entity("IfcMaterialProfile", Name=name) + if material: + mat_profile.Material = material + if profile: + mat_profile.Profile = profile + profiles.append(mat_profile) + profile_set.MaterialProfiles = profiles + return mat_profile