> For the complete documentation index, see [llms.txt](https://help.vectary.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://help.vectary.com/api/model-api/api-reference/addoreditmaterial.md).

# addOrEditMaterial

#### addOrEditMaterial

Adds a new material to an object or edits an existing one.

#### Signature

```typescript
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](/api/model-api/api-reference.md#material) in Common Types.

#### Returns

`Promise<Material>` — The created or updated material with all properties.

#### Usage

```javascript
// 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 `name` exists on the object, it will be updated
* If the material doesn't exist, it will be created and assigned
* By default (`isActive=true`), the new/edited material becomes active
* Use `isActive: false` to add without changing the active material
* Color values use RGB in range 0-255


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://help.vectary.com/api/model-api/api-reference/addoreditmaterial.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
