ifcopenshell.api.layer

Submodules

Package Contents

ifcopenshell.api.layer.add_layer(file, Name=None) None

Adds a new layer

An IFC layer is like a CAD layer. Portions of an object’s geometry (typically portions of its 2D linework) can be assigned to layers, which can provide stylistic information such as line weights, colours, or simply be used for filtering.

Layers have historically been used to organise CAD data and included in ISO standards such as ISO 13567 or by the AIA. This alllows IFC data to be compatible with older, 2D-oriented, layer-based workflows.

Some software that are still based on layers, such as Tekla or ArchiCAD may also use this layer information for filtering.

Parameters:

Name (str, optional) – The name of the layer. Defaults to “Unnamed”.

Returns:

The newly created IfcPresentationLayerAssignment element

Return type:

ifcopenshell.entity_instance

Example:

ifcopenshell.api.run(“layer.add_layer”, model, Name=”AI-WALL-FULL-DIMS-N”)

ifcopenshell.api.layer.assign_layer(file: ifcopenshell.file, items: list[ifcopenshell.entity_instance], layer: ifcopenshell.entity_instance) None

Assigns representation items to a layer

In IFC, instead of objects being assigned to layers, representation items are assigned to layers. Representation items are portions of the object’s representation. For example, this allows a single IFC Window element to have portions of its 2D linework (e.g. the cross section of its frame) assigned to one layer, and another portion (e.g. the glazing panels) assigned to another layer.

Parameters:
  • items (list[ifcopenshell.entity_instance]) – The list of IfcRepresentationItems to assign to the layer. This should be the items from the object’s IfcShapeRepresentation.

  • layer (ifcopenshell.entity_instance) – The IfcPresentationLayerAssignment layer to assign the item to.

Returns:

None

Return type:

None

Example:

# Remember, all geometry needs to specify the context it is part of first.
# See ifcopenshell.api.context.add_context for details.
model = ifcopenshell.api.run("context.add_context", model, context_type="Model")
body = ifcopenshell.api.run("context.add_context", model,
    context_type="Model", context_identifier="Body", target_view="MODEL_VIEW", parent=model
)

wall = ifcopenshell.api.run("root.create_entity", model, ifc_class="IfcWall")
representation = ifcopenshell.api.run("geometry.add_wall_representation", model,
    context=body, length=5, height=3, thickness=0.2)
ifcopenshell.api.run("geometry.assign_representation", model,
    product=wall, representation=representation)
ifcopenshell.api.run("geometry.edit_object_placement", model, product=wall)

# Now let's create a layer that contains walls
layer = ifcopenshell.api.run("layer.add_layer", model, Name="AI-WALL")

# And assign our wall representation item (in this example, there is
# only one item) to the layer.
ifcopenshell.api.run("layer.assign_layer", model, items=[representation.Items[0]], layer=layer)
ifcopenshell.api.layer.edit_layer(file, layer=None, attributes=None) None

Edits the attributes of an IfcPresentationLayerAssignment

For more information about the attributes and data types of an IfcPresentationLayerAssignment, consult the IFC documentation.

Parameters:
  • layer (ifcopenshell.entity_instance) – The IfcPresentationLayerAssignment entity you want to edit

  • attributes (dict, optional) – a dictionary of attribute names and values.

Returns:

None

Return type:

None

Example:

layer = ifcopenshell.api.run("layer.add_layer", model, Name="AI-WALL")
ifcopenshell.api.run("layer.edit_layer", model,
    layer=layer, attributes={"Description": "All walls, based on the AIA standard."})
ifcopenshell.api.layer.remove_layer(file, layer=None) None

Removes a layer

All representation items assigned to the layer will remain, but the relationship to the layer will be removed.

Parameters:

layer (ifcopenshell.entity_instance) – The IfcPresentationLayerAssignment entity to remove

Returns:

None

Return type:

None

Example:

layer = ifcopenshell.api.run("layer.add_layer", model, Name="AI-WALL")
ifcopenshell.api.run("layer.remove_layer", model, layer=layer)
ifcopenshell.api.layer.unassign_layer(file: ifcopenshell.file, items: list[ifcopenshell.entity_instance], layer: ifcopenshell.entity_instance) None

Unassigns representation items from a layer

If the representation item isn’t assigned to the layer, nothing will happen. If after unassignment layer won’t have any assigned items it will be removed to keep IFC valid.

Parameters:
Returns:

None

Return type:

None

Example:

# Remember, all geometry needs to specify the context it is part of first.
# See ifcopenshell.api.context.add_context for details.
model = ifcopenshell.api.run("context.add_context", model, context_type="Model")
body = ifcopenshell.api.run("context.add_context", model,
    context_type="Model", context_identifier="Body", target_view="MODEL_VIEW", parent=model
)

wall = ifcopenshell.api.run("root.create_entity", model, ifc_class="IfcWall")
representation = ifcopenshell.api.run("geometry.add_wall_representation", model,
    context=body, length=5, height=3, thickness=0.2)
ifcopenshell.api.run("geometry.assign_representation", model,
    product=wall, representation=representation)
ifcopenshell.api.run("geometry.edit_object_placement", model, product=wall)

# Now let's create a layer that contains walls
layer = ifcopenshell.api.run("layer.add_layer", model, Name="AI-WALL")

# And assign our wall representation item (in this example, there is
# only one item) to the layer.
ifcopenshell.api.run("layer.assign_layer", model, items=[representation.Items[0]], layer=layer)

# Let's undo it!
ifcopenshell.api.run("layer.unassign_layer", model, items=[representation.Items[0]], layer=layer)