Appearance
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.
| Value | Description |
|---|---|
"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.
| Property | Type | Description |
|---|---|---|
type | PUnitType | The unit type to set as the project unit |
PluginUnitsConvertArgs
Arguments for convert.
| Property | Type | Description |
|---|---|---|
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 |
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—trueif applied;falseiftypeis 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 convertfrom:PUnitType— Source unit typeto:PUnitType— Target unit typedegree:1 | 2 | 3(optional, default1) — 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:
| Degree | Use | Example |
|---|---|---|
1 (default) | Length / distance | 5 meters → babylon units |
2 | Area | 25 m² → babylon area units |
3 | Volume | 125 m³ → babylon volume |
Errors
Failed calls reject with a typed PluginError — see Error Handling. Conditions specific to this namespace:
| Code | Thrown by | When | details |
|---|---|---|---|
PRECONDITION_FAILED | getType | The 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.