OpenSite/Guides/Quantities and profiles

From BathAfrica Documentation
Revision as of 14:00, 29 October 2026 by BathAfrica (talk | contribs) (Add rewritten practical lesson with steps, code and expected results)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
OpenSite 0.0.1 · DevelopmentSource scope and availability


Add quantities written in different units and change their display profile without changing their physical values.

Stable identifier
opensite.help.quantities-and-profiles

Prerequisites

Embedded OpenSite Python. This lesson does not require a document or a development authorization policy.

Steps

Enter units explicitly

Use parse_quantity or Q rather than assuming that 450 means millimetres. The example combines 3.2 m with 450 mm.

Add compatible quantities

The units engine converts compatible lengths to canonical SI before adding them. Expected total: 3.65 m, or 3650 mm.

Change presentation

Switch to engineering_metric and format the same quantity. Store and compare its SI value before and after. Displaying millimetres must not scale the model.

Handle a rejected unit

Check the unit spelling, physical dimension and quantity kind. Pressure is not a length; absolute temperature differs from a temperature difference.

Expected result

The script prints 3650 mm. Its assertions confirm an SI total of 3.65 m and unchanged SI after selecting the display profile.

Limitations

Profiles affect presentation. They do not choose a national design standard. The script changes the current profile for this session; return to your preferred profile afterwards.

Complete example

import opensite

span = opensite.parse_quantity("3.2 m")
extension = opensite.parse_quantity("450 mm")
total = opensite.add(span, extension)
print(f"Total: {total.value_in('mm'):.0f} mm")
assert abs(total.si_value - 3.65) < 1e-12

before = total.si_value
opensite.execute("units.set_profile", {"profile": "engineering_metric"})
print("Display:", opensite.format_quantity(total, "engineering_metric"))
assert total.si_value == before