Skip to content

Unit Symbols

Christopher Short edited this page Sep 1, 2026 · 1 revision

Unit Symbols

Query.UnitSymbol returns the engineer-facing display symbol for a BH.oM.Units unit member — e.g. LengthUnit.Millimeter"mm", AreaMomentOfInertiaUnit.CentimeterToTheFourth"cm⁴". It's a one-way lookup, unit → symbol, meant for labelling values in UI or reports. It does not parse a symbol string back into a unit.

Quick example

using BH.Engine.Units;
using BH.oM.Units;

string mm = LengthUnit.Millimeter.UnitSymbol();              // "mm"
string cm4 = AreaMomentOfInertiaUnit.CentimeterToTheFourth.UnitSymbol(); // "cm⁴"
string none = LengthUnit.Undefined.UnitSymbol();              // "" - Undefined has no symbol

Where the symbol comes from

BH.oM.Units enum members carry no symbol of their own — UnitsNet is the only thing in the stack that publishes one. UnitSymbol.cs bridges to it:

  1. The BHoM unit's declared type name (e.g. LengthUnit) is matched, by name, to the UnitsNet type of the same name in UnitsNet.Units. This bridge is by name rather than by value because the two enums' underlying integer values don't agree for several quantities (LengthUnit, AngleUnit, PressureUnit, and others) — a numeric cast would silently hand back the wrong unit.
  2. If the member's name isn't defined on the UnitsNet side — Undefined, or anything BHoM has added since (e.g. WarpingMomentOfInertiaUnit, which UnitsNet does define, so this only bites genuinely BHoM-only members) — the lookup fails.
  3. Otherwise, UnitsNet's abbreviation table is asked for every symbol registered for that unit, and the first (default) one is returned.

If the unit isn't found, or UnitsNet has registered no abbreviation for it, UnitSymbol returns "" and records an error — it never throws.

Reverse direction

There is currently no supported way to go from a symbol string back to a unit — ToUnit/FromUnit (see Unit Conversion) take a BH.oM.Units enum member directly rather than a symbol.

Clone this wiki locally