ifcopenshell.api.unit.assign_unit

Module Contents

class ifcopenshell.api.unit.assign_unit.UnitDict

Bases: TypedDict

dict() -> new empty dictionary dict(mapping) -> new dictionary initialized from a mapping object’s

(key, value) pairs

dict(iterable) -> new dictionary initialized as if via:

d = {} for k, v in iterable:

d[k] = v

dict(**kwargs) -> new dictionary initialized with the name=value pairs

in the keyword argument list. For example: dict(one=1, two=2)

Initialize self. See help(type(self)) for accurate signature.

is_metric: bool
raw: str
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: UnitDict) → ifcopenshell.entity_instance
create_metric_unit(unit_type: str, data: UnitDict) → ifcopenshell.entity_instance
execute(units: list[ifcopenshell.entity_instance] | None, length: UnitDict | None, area: UnitDict | None, volume: UnitDict | None) → ifcopenshell.entity_instance
get_unit_assignment() → ifcopenshell.entity_instance
file: ifcopenshell.file
ifcopenshell.api.unit.assign_unit.assign_unit(file: ifcopenshell.file, units: list[ifcopenshell.entity_instance] | None = None, length: UnitDict | None = None, area: UnitDict | None = None, volume: UnitDict | 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 – 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.

  • length – Only used if units is not provided. A dict like {"is_metric": True, "raw": "MILLIMETERS"} to create the default length unit. Imperial raw values are INCHES, FEET, MILES, or THOU. Defaults to millimeters.

  • area – Same as length, for the area unit. Defaults to square meters.

  • volume – Same as length, for the volume unit. Defaults to cubic meters.

Returns:

The IfcUnitAssignment element

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")

# Optionally, add mass and time units
mass = ifcopenshell.api.unit.add_si_unit(model, unit_type="MASSUNIT", prefix="KILO")
time = ifcopenshell.api.unit.add_si_unit(model, unit_type="TIMEUNIT")

# Make these the default units for the project
ifcopenshell.api.unit.assign_unit(model, units=[length, area, mass, time])

# 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)