addOrEditMaterial
addOrEditMaterial
Adds a new material to an object or edits an existing one.
Signature
addOrEditMaterial(
objectName: string,
material: Material,
isActive?: boolean
): Promise<Material>Parameters
Name
Type
Required
Description
objectName
string
Yes
Name of the object
material
Material
Yes
Material properties (must include name)
isActive
boolean
No
Whether to set as active material. Default: true
See Material in Common Types.
Returns
Promise<Material> — The created or updated material with all properties.
Usage
// Add new material (becomes active by default)
const mat = await api.addOrEditMaterial("Chair", {
name: "Custom Red",
baseColor: { color: { x: 255, y: 0, z: 0 } }
});
// Add material but don't make it active
await api.addOrEditMaterial("Chair", {
name: "Custom Blue",
baseColor: { color: { x: 0, y: 0, z: 255 } }
}, false);
// Edit existing material
await api.addOrEditMaterial("Chair", {
name: "Custom Red", // same name = edit
roughness: { value: 0.8 }
});Notes
If a material with the same
nameexists on the object, it will be updatedIf the material doesn't exist, it will be created and assigned
By default (
isActive=true), the new/edited material becomes activeUse
isActive: falseto add without changing the active materialColor values use RGB in range 0-255
Last updated