Skip to content
Shapemetry

@huukhanhnguyen/model / core/unit

core/unit

convertLaneUnits()

convertLaneUnits(chains, registry, unitType, currentUnit, newUnit, hostRefType): void

Convert unit literals in the RAW-JSON lanes — everything Model.nodes does NOT hold (materials, layers, styles, views, components, textures, tables, cameras, animations). Without this a component body's 600 stayed millimetres while the root graph converted around it.

Arg value types come from the REGISTRY — the same declared type the live NodeCollection pass reads — so an arg typed length converts wherever it is authored, and one typed number is left alone (that is why a mm-valued arg must declare length, not number).

PAPER lanes (sheets) are excluded on purpose: paper millimetres are not the model's length dimension and never rescale with it.

Parameters

chains

LaneChain[]

registry

Registry

unitType

string

currentUnit

string

newUnit

string

hostRefType

(name) => string | null

Returns

void


convertModelUnit()

convertModelUnit(nodes, unit, unitType, currentUnit, newUnit): void

Convert all unit-carrying literal values reachable from nodes from currentUnit to newUnit, then record newUnit on the unit config. Covers parameter inputs + select options (recursing into group entries) and every generator/modifier arg of an applicable type, with dimensional inference for expressions (a reference like width - 18 converts only the literal 18). Standalone (not a Model method) so a UI holding only the NodeCollection + the scope's unit record can run the ONE canonical conversion — Model.convertUnit delegates here.

Parameters

nodes

NodeCollection<any>

unit

UnitConfig

unitType

string

currentUnit

string

newUnit

string

Returns

void


convertUnit()

convertUnit(model, unitType, newUnit): void

Convert all unit-carrying literals on a live Model, then persist newUnit.

Parameters

model

Model

unitType

string

newUnit

string

Returns

void

Last updated: 📖 2 min readEdit on GitHub