Skip to content

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.

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

new Length(inches): Length

Parameter Type Description

inches

number

The number of inches that this length represents (the natural unit that SketchUp supports)

Length

readonly centimeters: number

Get the length in millimeters

SDK 2.38.0


readonly feet: number

Get the length in feet

SDK 2.38.0


readonly inches: number

The number of inches that this length represents (the natural unit that SketchUp supports)


readonly kilometers: number

Get the length in kilometers

SDK 2.38.0


readonly meters: number

Get the length in meters

SDK 2.38.0


readonly miles: number

Get the length in miles

SDK 2.38.0


readonly millimeters: number

Get the length in millimeters

SDK 2.38.0


readonly type: "length" = 'length'


readonly yards: number

Get the length in yards

SDK 2.38.0

format(options?): string

Formats this length according to supplied length options

Parameter Type Description

options?

Model | { forceInchDisplay?: boolean; forceShowFraction?: boolean; lengthFormat?: LengthFormat; lengthPrecision?: number; lengthUnit: LengthUnit; suppressUnitsDisplay?: boolean; }

the options

string

let { Length, LengthFormat, LengthUnit } = SketchUpApi;
let length = Length.feet(5.5);
// Decimal, in a chosen unit
console.log(length.format({
lengthFormat: LengthFormat.Decimal,
lengthUnit: LengthUnit.Meter,
lengthPrecision: 3,
}));
// Feet and inches, to the nearest 1/16 inch
console.log(length.format({
lengthFormat: LengthFormat.Architectural,
lengthPrecision: 16,
}));
// Decimal feet
console.log(length.format({
lengthFormat: LengthFormat.Engineering,
}));
// Inches with a fraction
console.log(length.format({
lengthFormat: LengthFormat.Fractional,
}));
// Or use the units configured in the model
let model = await SketchUpApi.getActiveModel();
console.log(length.format(model));

SDK 2.38.0


toString(): string

string


static centimeters(length): Length

Construct a length instance from centimeters

Parameter Type

length

number

Length

SDK 2.38.0


static feet(length): Length

Construct a length instance from feet

Parameter Type

length

number

Length

SDK 2.38.0


static inches(length): Length

Construct a length instance from inches

Parameter Type

length

number

Length

SDK 2.38.0


static kilometers(length): Length

Construct a length instance from kilometers

Parameter Type

length

number

Length

SDK 2.38.0


static meters(length): Length

Construct a length instance from meters

Parameter Type

length

number

Length

SDK 2.38.0


static miles(length): Length

Construct a length instance from miles

Parameter Type

length

number

Length

SDK 2.38.0


static millimeters(length): Length

Construct a length instance from millimeters

Parameter Type

length

number

Length

SDK 2.38.0


static parse(string, options?): Length | undefined

Parses a length from a formatted length string.

On an invalid input this returns undefined

Parameter Type Description

string

string

the length string

options?

Model | { lengthFormat?: LengthFormat; lengthUnit?: LengthUnit; }

setup defaults if the string is unit-less.

Length | undefined

let { Length, LengthUnit } = SketchUpApi;
// Feet and inches are understood
let a = Length.parse("5' 6\"");
console.log(a.inches);
// Metric units are understood
let b = Length.parse("2.5m");
console.log(b.millimeters);
// Unit-less input uses the supplied default unit
let c = Length.parse("12", {
lengthUnit: LengthUnit.Centimeter,
});
console.log(c.centimeters);
// Invalid input returns undefined
console.log(Length.parse("not a length"));
// Or defer to the units configured in the model
let model = await SketchUpApi.getActiveModel();
console.log(Length.parse("10", model).inches);

SDK 2.38.0 If not supplied inches are assumed


static yards(length): Length

Construct a length instance from yards

Parameter Type

length

number

Length

SDK 2.38.0

readonly data: number