ifcopenshell.api.project.append_asset

Module Contents

class ifcopenshell.api.project.append_asset.Usecase
add_element(element: ifcopenshell.entity_instance) ifcopenshell.entity_instance | None
add_inverse_element(element: ifcopenshell.entity_instance) None
append_cost_schedule()
append_material()
append_presentation_style()
append_product()
append_profile_def()
append_type_product()
check_inverses(element: ifcopenshell.entity_instance) None
create_equivalent_context(added_context: ifcopenshell.entity_instance) ifcopenshell.entity_instance
execute()
get_equivalent_existing_context(added_context: ifcopenshell.entity_instance) ifcopenshell.entity_instance | None
get_existing_element(element)
has_whitelisted_inverses(element: ifcopenshell.entity_instance) bool
is_another_asset(element: ifcopenshell.entity_instance) bool
reuse_existing_contexts() None
file: ifcopenshell.file
settings: dict[str, Any]
ifcopenshell.api.project.append_asset.append_asset(file: ifcopenshell.file, library: ifcopenshell.file, element: ifcopenshell.entity_instance, reuse_identities: dict[int, ifcopenshell.entity_instance] | None = None) ifcopenshell.entity_instance

Appends an asset from a library into the active project

A BIM library asset may be a type product (e.g. wall type), product (e.g. pump), material, profile, or cost schedule.

This copies the asset from the specified library file into the active project. It handles all details like ensuring that product materials, styles, properties, quantities, and so on are preserved.

If an asset contains geometry, the geometric contexts are also intelligentely transplanted such that existing equivalent contexts are reused.

Do not mix units.

Parameters:
  • library (ifcopenshell.file) – The file object containing the asset.

  • element (ifcopenshell.entity_instance) – An element in the library file of the asset. It may be an IfcTypeProduct, IfcProduct, IfcMaterial, IfcCostSchedule, or IfcProfileDef.

  • reuse_identities (dict[int, ifcopenshell.entity_instance]) – Optional dictionary of mapped entities’ identities to the already created elements. It will be used to avoid creating duplicated inverse elements during multiple project.append_asset calls. If you want to add just 1 asset or if added assets won’t have any shared elements, then it can be left empty.

Returns:

The appended element

Return type:

ifcopenshell.entity_instance

Example:

# Programmatically generate a library. You could do this visually too.
library = ifcopenshell.api.project.create_file()
root = ifcopenshell.api.root.create_entity(library, ifc_class="IfcProject", name="Demo Library")
context = ifcopenshell.api.root.create_entity(library,
    ifc_class="IfcProjectLibrary", name="Demo Library")
ifcopenshell.api.project.assign_declaration(library, definitions=[context], relating_context=root)

# Assign units for our example library
unit = ifcopenshell.api.unit.add_si_unit(library,
    unit_type="LENGTHUNIT", name="METRE", prefix="MILLI")
ifcopenshell.api.unit.assign_unit(library, units=[unit])

# Let's create a single asset of a 200mm thick concrete wall
wall_type = ifcopenshell.api.root.create_entity(library, ifc_class="IfcWallType", name="WAL01")
concrete = ifcopenshell.api.material.add_material(usecase.file, name="CON", category="concrete")
rel = ifcopenshell.api.material.assign_material(library,
    products=[wall_type], type="IfcMaterialLayerSet")
layer = ifcopenshell.api.material.add_layer(library,
    layer_set=rel.RelatingMaterial, material=concrete)
layer.Name = "Structure"
layer.LayerThickness = 200

# Mark our wall type as a reusable asset in our library.
ifcopenshell.api.project.assign_declaration(library,
    definitions=[wall_type], relating_context=context)

# Let's imagine we're starting a new project
model = ifcopenshell.api.project.create_file()
project = ifcopenshell.api.root.create_entity(model, ifc_class="IfcProject", name="Test")

# Now we can easily append our wall type from our libary
wall_type = ifcopenshell.api.project.append_asset(model, library=library, element=wall_type)

Example of adding multiple assets and avoiding duplicated inverses:

# since occurrences of IfcWindow of the same type
# might have shared inverses (e.g. IfcStyledItem)
# we provide a dictionary that will be populated with newly created items
# and reused to avoid duplicated elements
reuse_identities = dict()

for element in ifcopenshell.util.selector.filter_elements(model, "IfcWindow"):
    ifcopenshell.api.project.append_asset(
        model, library=library,
        element=wall_type
        reuse_identities=reuse_identities
    )
ifcopenshell.api.project.append_asset.APPENDABLE_ASSET
ifcopenshell.api.project.append_asset.APPENDABLE_ASSET_TYPES