Generate functions for all API usecases for better static code features. See #2693.

This commit is contained in:
Dion Moult
2024-05-06 14:35:39 +10:00
parent 10f894e2ea
commit d11ec67129
330 changed files with 13283 additions and 13751 deletions
@@ -19,78 +19,81 @@
import ifcopenshell.util.representation
def assign_profile(file, material_profile=None, profile=None) -> 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
profile curve used in any body representation extrusions.
:param material_profile: The IfcMaterialProfile to change the profile
curve of. See ifcopenshell.api.material.add_profile to see how to
create profiles.
:type material_profile: ifcopenshell.entity_instance
:param profile: The IfcProfileDef to set the profile item's curve to.
:type profile: ifcopenshell.entity_instance
:return: None
:rtype: None
Example:
.. code:: python
# Let's imagine we have a steel I-beam. Notice we are assigning to
# the type only, as all occurrences of that type will automatically
# inherit the material.
beam_type = ifcopenshell.api.run("root.create_entity", model, ifc_class="IfcBeamType", name="B1")
# First, let's create a material set. This will later be assigned
# to our beam type element.
material_set = ifcopenshell.api.run("material.add_profile_set", model,
name="B1", set_type="IfcMaterialProfileSet")
# Create a steel material.
steel = ifcopenshell.api.run("material.add_material", model, name="ST01", category="steel")
# Create an I-beam profile curve. Notice how we name our profiles
# based on standardised steel profile names.
hea100 = usecase.file.create_entity(
"IfcIShapeProfileDef", ProfileName="HEA100", ProfileType="AREA",
OverallWidth=100, OverallDepth=96, WebThickness=5, FlangeThickness=8, FilletRadius=12,
)
# Define that steel material and cross section as a single profile
# item. If this were a composite beam, we might add multiple profile
# items instead, but this is rarely the case in most construction.
profile_item = ifcopenshell.api.run("material.add_profile", model,
profile_set=material_set, material=steel, profile=hea100)
# Great! Let's assign our material set to our beam type.
ifcopenshell.api.run("material.assign_material", model, products=[beam_type], material=material_set)
# Let's create an occurrence of this beam.
beam = ifcopenshell.api.run("root.create_entity", model, ifc_class="IfcBeam", name="B1.01")
ifcopenshell.api.run("material.assign_material", model,
products=[beam], type="IfcMaterialProfileSetUsage")
# Let's give a 1000mm long beam body representation.
body = ifcopenshell.api.run("geometry.add_profile_representation",
context=body_context, profile=hea100, depth=1000)
ifcopenshell.api.run("geometry.assign_representation", model, product=beam, representation=body)
ifcopenshell.api.run("geometry.edit_object_placement", model, product=beam)
# Now let's change the profile to a HEA200 standard profile instead.
# This will automatically change the body representation that we
# just added as well to a HEA200 profile.
hea200 = usecase.file.create_entity(
"IfcIShapeProfileDef", ProfileName="HEA200", ProfileType="AREA",
OverallWidth=200, OverallDepth=190, WebThickness=6.5, FlangeThickness=10, FilletRadius=18,
)
ifcopenshell.api.run("material.assign_profile", model, material_profile=profile_item, profile=hea200)
"""
usecase = Usecase()
usecase.file = file
usecase.settings = {"material_profile": material_profile, "profile": profile}
return usecase.execute()
class Usecase:
def __init__(self, file, material_profile=None, profile=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
profile curve used in any body representation extrusions.
:param material_profile: The IfcMaterialProfile to change the profile
curve of. See ifcopenshell.api.material.add_profile to see how to
create profiles.
:type material_profile: ifcopenshell.entity_instance
:param profile: The IfcProfileDef to set the profile item's curve to.
:type profile: ifcopenshell.entity_instance
:return: None
:rtype: None
Example:
.. code:: python
# Let's imagine we have a steel I-beam. Notice we are assigning to
# the type only, as all occurrences of that type will automatically
# inherit the material.
beam_type = ifcopenshell.api.run("root.create_entity", model, ifc_class="IfcBeamType", name="B1")
# First, let's create a material set. This will later be assigned
# to our beam type element.
material_set = ifcopenshell.api.run("material.add_profile_set", model,
name="B1", set_type="IfcMaterialProfileSet")
# Create a steel material.
steel = ifcopenshell.api.run("material.add_material", model, name="ST01", category="steel")
# Create an I-beam profile curve. Notice how we name our profiles
# based on standardised steel profile names.
hea100 = self.file.create_entity(
"IfcIShapeProfileDef", ProfileName="HEA100", ProfileType="AREA",
OverallWidth=100, OverallDepth=96, WebThickness=5, FlangeThickness=8, FilletRadius=12,
)
# Define that steel material and cross section as a single profile
# item. If this were a composite beam, we might add multiple profile
# items instead, but this is rarely the case in most construction.
profile_item = ifcopenshell.api.run("material.add_profile", model,
profile_set=material_set, material=steel, profile=hea100)
# Great! Let's assign our material set to our beam type.
ifcopenshell.api.run("material.assign_material", model, products=[beam_type], material=material_set)
# Let's create an occurrence of this beam.
beam = ifcopenshell.api.run("root.create_entity", model, ifc_class="IfcBeam", name="B1.01")
ifcopenshell.api.run("material.assign_material", model,
products=[beam], type="IfcMaterialProfileSetUsage")
# Let's give a 1000mm long beam body representation.
body = ifcopenshell.api.run("geometry.add_profile_representation",
context=body_context, profile=hea100, depth=1000)
ifcopenshell.api.run("geometry.assign_representation", model, product=beam, representation=body)
ifcopenshell.api.run("geometry.edit_object_placement", model, product=beam)
# Now let's change the profile to a HEA200 standard profile instead.
# This will automatically change the body representation that we
# just added as well to a HEA200 profile.
hea200 = self.file.create_entity(
"IfcIShapeProfileDef", ProfileName="HEA200", ProfileType="AREA",
OverallWidth=200, OverallDepth=190, WebThickness=6.5, FlangeThickness=10, FilletRadius=18,
)
ifcopenshell.api.run("material.assign_profile", model, material_profile=profile_item, profile=hea200)
"""
self.file = file
self.settings = {"material_profile": material_profile, "profile": profile}
def execute(self):
# TODO: handle composite profiles
old_profile = self.settings["material_profile"].Profile