Skip to content

Units ​

Unit-type queries and conversion. Snaptrude stores all geometry in an internal babylon unit. These methods read the available unit types, the internal (babylon) type, and the current project type; set the current project type; and convert values between any two unit types. Accessed via snaptrude.core.units.

Types ​

PUnitType ​

Supported unit types. babylon is Snaptrude's internal storage unit; the rest are real-world units.

ValueDescription
"meters"Metric meters
"feet-inches"Imperial feet and inches
"inches"Imperial inches
"centimeters"Metric centimeters
"millimeters"Metric millimeters
"kilometers"Metric kilometers
"miles"Imperial miles
"babylon"Snaptrude's internal storage unit

PluginUnitsSetTypeArgs ​

Arguments for setType.

PropertyTypeDescription
typePUnitTypeThe unit type to set as the project unit

PluginUnitsConvertArgs ​

Arguments for convert.

PropertyTypeDescription
valuenumberThe numeric value to convert
fromPUnitTypeSource unit type
toPUnitTypeTarget unit type
degree1 | 2 | 3(optional, default 1) 1 = length, 2 = area, 3 = volume

Functions ​

listTypes() ​

List the selectable real-world unit types (excludes the internal babylon storage type, which is read via getBabylonType).

  • Returns: PUnitType[] — The selectable real-world unit types.

getBabylonType() ​

The internal storage unit type all geometry is stored in ("babylon").

  • Returns: PUnitType — Always "babylon".

getType() ​

The current project's unit type. Paired with setType.

  • Returns: PUnitType — The current project unit type.

setType(type) ​

Set the current project's unit type. Paired with getType.

  • Parameters:
    • type: PUnitType — The unit type to set as the project unit
  • Returns: boolean — true if applied; false if type is not a settable project unit (e.g. kilometers, miles, babylon).
ts
await snaptrude.core.units.setType("meters");

convert(value, from, to, degree?) ​

Convert a value between two unit types.

  • Parameters:
    • value: number — The numeric value to convert
    • from: PUnitType — Source unit type
    • to: PUnitType — Target unit type
    • degree: 1 | 2 | 3 (optional, default 1) — 1 = length, 2 = area, 3 = volume
  • Returns: number — The converted numeric value.
ts
// 5 meters → internal babylon units
const b = await snaptrude.core.units.convert(5, "meters", "babylon");
// an internal area → square metres
const m2 = await snaptrude.core.units.convert(area, "babylon", "meters", 2);

Degree Parameter ​

The degree parameter controls how the conversion factor is applied:

DegreeUseExample
1 (default)Length / distance5 meters → babylon units
2Area25 m² → babylon area units
3Volume125 m³ → babylon volume

Errors ​

Failed calls reject with a typed PluginError — see Error Handling. Conditions specific to this namespace:

CodeThrown byWhendetails
PRECONDITION_FAILEDgetTypeThe current project unit is not yet available (no project open, or still loading)—

setType never throws for a non-settable unit type — it returns false by contract.