ifcopenshell.api.unit.assign_unit

Module Contents

class ifcopenshell.api.unit.assign_unit.Usecase
assign_units(unit_assignment: ifcopenshell.entity_instance, new_units: list[ifcopenshell.entity_instance]) None
create_imperial_unit(unit_type: str, data: dict) ifcopenshell.entity_instance
create_metric_unit(unit_type: str, data: dict) ifcopenshell.entity_instance
execute()
get_unit_assignment() ifcopenshell.entity_instance
ifcopenshell.api.unit.assign_unit.assign_unit(file: ifcopenshell.file, units: list[ifcopenshell.entity_instance] | None = None, length: dict | None = None, area: dict | None = None, volume: dict | None = None) ifcopenshell.entity_instance

Assign default project units

Whenever a unitised quantity is specified, such as a length, area, voltage, pressure, etc, these project units are used by default.

It is also possible to override units for specific properties. For example, generally you might want square metres for area measurements, but you might want square millimeters for the measurements of the cross sectional area of cables in cable trays. However, this function only deals with the default project units.

Parameters:

units (list[ifcopenshell.entity_instance],optional) – A list of units to assign as project defaults. See ifcopenshell.api.unit.add_si_unit, unit.add_conversion_based_unit, and unit.add_monetary_unit for information on how to create units.

Returns:

The IfcUnitAssignment element

Return type:

ifcopenshell.entity_instance

Example:

# You need a project before you can assign units.
ifcopenshell.api.root.create_entity(model, ifc_class="IfcProject")

# Millimeters and square meters
length = ifcopenshell.api.unit.add_si_unit(model, unit_type="LENGTHUNIT", prefix="MILLI")
area = ifcopenshell.api.unit.add_si_unit(model, unit_type="AREAUNIT")

# Make it our default units, if we are doing a metric building
ifcopenshell.api.unit.assign_unit(model, units=[length, area])

# Alternatively, you may specify without any arguments to
# automatically create millimeters, square meters, and cubic meters
# as a convenience for testing purposes. Sorry imperial folks, we
# prioritise metric here.
ifcopenshell.api.unit.assign_unit(model)