> 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

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

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
