ifcopenshell.api.type.map_type_representations

Module Contents

ifcopenshell.api.type.map_type_representations.map_type_representations(file: ifcopenshell.file, related_object: ifcopenshell.entity_instance, relating_type: ifcopenshell.entity_instance) None

Ensures that all occurrences has the same representation as the type

If a type has a representation, all occurrences must have the same representation. If the type’s representation changes, this function may be used to ensure consistency of the occurrence’s representations.

Parameters:
  • related_object (ifcopenshell.entity_instance) – The IfcElement occurrence.

  • relating_type (ifcopenshell.entity_instance) – The IfcElementType type.

Returns:

None

Return type:

None

Example:

# A furniture type. This would correlate to a particular model in a
# manufacturer's catalogue. Like an Ikea sofa :)
furniture_type = ifcopenshell.api.root.create_entity(model,
    ifc_class="IfcFurnitureType", name="FUN01")

# An individual occurrence of a that sofa.
furniture = ifcopenshell.api.root.create_entity(model, ifc_class="IfcFurniture")

# Place our furniture at the origin
ifcopenshell.api.geometry.edit_object_placement(model, product=furniture)

# Assign the furniture to the furniture type. Right now, the
# furniture type has no representation, so the furniture may also
# have no representation, or any arbitrary representation that may
# vary from occurrence to occurrence.
ifcopenshell.api.type.assign_type(model, related_objects=[furniture], relating_type=furniture_type)

# A bit of preparation, let's create some geometric contexts since
# we want to create some geometry for our furniture type.
model3d = ifcopenshell.api.context.add_context(model, context_type="Model")
body = ifcopenshell.api.context.add_context(model,
    context_type="Model", context_identifier="Body", target_view="MODEL_VIEW", parent=model3d)

# Let's create a mesh representation of an arbitrary 2m cube.
representation = ifcopenshell.api.geometry.add_sverchok_representation(model, context=body,
    vertices=[[(-1.0, -1.0, 0.0), (-1.0, -1.0, 2.0), (-1.0, 1.0, 0.0), (-1.0, 1.0, 2.0),
        (1.0, -1.0, 0.0), (1.0, -1.0, 2.0), (1.0, 1.0, 0.0), (1.0, 1.0, 2.0)]],
    faces=[[[0, 1, 3, 2], [2, 3, 7, 6], [6, 7, 5, 4], [4, 5, 1, 0], [2, 6, 4, 0], [7, 3, 1, 5]]])

# Assign our new body geometry back to our furniture type. In this
# case, since we use the API, all occurrences automatically get the
# representation mapped, so there is nothing more we need to do.
ifcopenshell.api.geometry.assign_representation(model,
    product=furniture_type, representation=representation)

# However, if you were doing some sort of manual IFC patching, like
# assigning furniture_type.RepresentationMaps directly, then you
# might make this call:
# ifcopenshell.api.type.map_type_representations(model,
#     related_object=furniture, relating_type=furniture_type)