Length
Represents a length in the standard SketchUp unit (inches).
Usage of this class is highly encouraged when dealing with non-default units in SketchUp, as it reduces the chance of mistakes and ambiguity.
Provides utilities for parsing and formatting a length based on the context of a model.
Example
Section titled “Example”let model = await SketchUpApi.getActiveModel();let length = SketchUpApi.Length.meters(1);let formatted = length.format(model);console.log(formatted);console.log(SketchUpApi.Length.parse(formatted, model).meters);SDK 2.38.0
Constructor
Section titled “Constructor”Constructor
Section titled “Constructor”new Length(
inches):Length
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
|
|
|
The number of inches that this length represents (the natural unit that SketchUp supports) |
Returns
Section titled “Returns”Length
Properties
Section titled “Properties”centimeters
Section titled “centimeters”
readonlycentimeters:number
Get the length in millimeters
SDK 2.38.0
readonlyfeet:number
Get the length in feet
SDK 2.38.0
inches
Section titled “inches”
readonlyinches:number
The number of inches that this length represents (the natural unit that SketchUp supports)
kilometers
Section titled “kilometers”
readonlykilometers:number
Get the length in kilometers
SDK 2.38.0
meters
Section titled “meters”
readonlymeters:number
Get the length in meters
SDK 2.38.0
readonlymiles:number
Get the length in miles
SDK 2.38.0
millimeters
Section titled “millimeters”
readonlymillimeters:number
Get the length in millimeters
SDK 2.38.0
readonlytype:"length"='length'
readonlyyards:number
Get the length in yards
SDK 2.38.0
Methods
Section titled “Methods”format()
Section titled “format()”format(
options?):string
Formats this length according to supplied length options
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
|
|
|
the options |
Returns
Section titled “Returns”string
Example
Section titled “Example”let { Length, LengthFormat, LengthUnit } = SketchUpApi;let length = Length.feet(5.5);
// Decimal, in a chosen unitconsole.log(length.format({ lengthFormat: LengthFormat.Decimal, lengthUnit: LengthUnit.Meter, lengthPrecision: 3,}));
// Feet and inches, to the nearest 1/16 inchconsole.log(length.format({ lengthFormat: LengthFormat.Architectural, lengthPrecision: 16,}));
// Decimal feetconsole.log(length.format({ lengthFormat: LengthFormat.Engineering,}));
// Inches with a fractionconsole.log(length.format({ lengthFormat: LengthFormat.Fractional,}));
// Or use the units configured in the modellet model = await SketchUpApi.getActiveModel();console.log(length.format(model));SDK 2.38.0
toString()
Section titled “toString()”toString():
string
Returns
Section titled “Returns”string
centimeters()
Section titled “centimeters()”
staticcentimeters(length):Length
Construct a length instance from centimeters
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
|
|
|
Returns
Section titled “Returns”Length
SDK 2.38.0
feet()
Section titled “feet()”
staticfeet(length):Length
Construct a length instance from feet
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
|
|
|
Returns
Section titled “Returns”Length
SDK 2.38.0
inches()
Section titled “inches()”
staticinches(length):Length
Construct a length instance from inches
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
|
|
|
Returns
Section titled “Returns”Length
SDK 2.38.0
kilometers()
Section titled “kilometers()”
statickilometers(length):Length
Construct a length instance from kilometers
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
|
|
|
Returns
Section titled “Returns”Length
SDK 2.38.0
meters()
Section titled “meters()”
staticmeters(length):Length
Construct a length instance from meters
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
|
|
|
Returns
Section titled “Returns”Length
SDK 2.38.0
miles()
Section titled “miles()”
staticmiles(length):Length
Construct a length instance from miles
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
|
|
|
Returns
Section titled “Returns”Length
SDK 2.38.0
millimeters()
Section titled “millimeters()”
staticmillimeters(length):Length
Construct a length instance from millimeters
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
|
|
|
Returns
Section titled “Returns”Length
SDK 2.38.0
parse()
Section titled “parse()”
staticparse(string,options?):Length|undefined
Parses a length from a formatted length string.
On an invalid input this returns undefined
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
|
|
|
the length string |
|
|
|
setup defaults if the string is unit-less. |
Returns
Section titled “Returns”Length | undefined
Example
Section titled “Example”let { Length, LengthUnit } = SketchUpApi;
// Feet and inches are understoodlet a = Length.parse("5' 6\"");console.log(a.inches);
// Metric units are understoodlet b = Length.parse("2.5m");console.log(b.millimeters);
// Unit-less input uses the supplied default unitlet c = Length.parse("12", { lengthUnit: LengthUnit.Centimeter,});console.log(c.centimeters);
// Invalid input returns undefinedconsole.log(Length.parse("not a length"));
// Or defer to the units configured in the modellet model = await SketchUpApi.getActiveModel();console.log(Length.parse("10", model).inches);SDK 2.38.0 If not supplied inches are assumed
yards()
Section titled “yards()”
staticyards(length):Length
Construct a length instance from yards
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
|
|
|
Returns
Section titled “Returns”Length
SDK 2.38.0