Skip to content

Materials

The collection of all materials in the model.

Retrieve the materials collection with model.getMaterials(). It provides the full list via values and fast lookups by name or ID. Because it’s a snapshot, call refresh() if the model’s materials may have changed since you fetched it.

See the Materials Examples for more ways to use this class.

let model = await SketchUpApi.getActiveModel();
let materials = await model.getMaterials();
console.log(materials.values.length);
// => number of materials in the model
// Look up a material by name
let brick = materials.findMaterialByName(
'Brick_Antique'
);
if (brick) {
console.log(brick.color.toHex());
}

readonly values: readonly Material[]

All materials in the model, in no particular order.

findMaterialById(id): Material | undefined

Finds a material by its persistent numeric ID. Returns undefined if no material with that ID exists.

Parameter Type Description

id

number

‐

Material | undefined


findMaterialByName(name): Material | undefined

Finds a material by its internal name (case-sensitive). Returns undefined if no material with that name exists.

Parameter Type Description

name

string

‐

Material | undefined


refresh(): Promise<Materials>

Re-fetches the material list from SketchUp to pick up any materials created or deleted since this snapshot was taken.

Promise<Materials>