# MaterialBindingAPI Bind Mesh to Material prim

**URL:** <https://forum.aousd.org/t/materialbindingapi-bind-mesh-to-material-prim/845>\
**Category:** USD\
**Tags:** python\
**Created:** [October 25, 2023, 1:42pm UTC](https://forum.aousd.org/t/materialbindingapi-bind-mesh-to-material-prim/845 "2023-10-25T13:42:38Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![moa.hunt](https://avatars.discourse-cdn.com/v4/letter/m/cab0a1/32.png) [@moa.hunt](https://forum.aousd.org/u/moa.hunt)\
**Post date:** [October 25, 2023, 1:42pm UTC](https://forum.aousd.org/t/materialbindingapi-bind-mesh-to-material-prim/845/1 "2023-10-25T13:42:38Z")

</div>

Hello.

When referencing a ‘Mesh’ and a ‘Material’ prim onto a Stage,  
how do I MaterialBindingAPI Bind the ‘Mesh’ to the ‘Material’ ?  
Below is a simple example of what I currently have but the last line is wrong.  
Do I first need to Get or Apply a Material API to the material\_prim ?  
Thanks for any suggestions.

```auto
stage = Usd.Stage.CreateNew('foo.usda')

geo_prim = stage.OverridePrim('/geo')
geo_prim.GetReferences().AddReference('geo.usda')

material_prim = stage.OverridePrim('/material')
material_prim.GetReferences().AddReference('material.usda')

geo_prim.ApplyAPI(UsdShade.MaterialBindingAPI)
UsdShade.MaterialBindingAPI(geo_prim).Bind(material_prim)

```

---

<div class="post-metadata">

**Author:** ![jackohoeg](https://avatars.discourse-cdn.com/v4/letter/j/5e9695/32.png) [@jackohoeg](https://forum.aousd.org/u/jackohoeg)\
**Post date:** [October 25, 2023, 2:42pm UTC](https://forum.aousd.org/t/materialbindingapi-bind-mesh-to-material-prim/845/2 "2023-10-25T14:42:44Z")

</div>

Hey there!

Good questions. The code snippet you provided is very close to working, you just need to pass `Bind` a `UsdShade.Material` object rather than a `Usd.Prim`.

```auto
UsdShade.MaterialBindingAPI(geo_prim).Bind(UsdShade.Material(material_prim))

```

I would also recommend getting and applying the `MaterialBindingAPI` using a single call like this:

```auto
mat_binding_api = UsdShade.MaterialBindingAPI.Apply(geo_prim)
mat_binding_api.Bind(UsdShade.Material(material_prim))

```

Hope this helps!

---

<div class="post-metadata">

**Author:** ![moa.hunt](https://avatars.discourse-cdn.com/v4/letter/m/cab0a1/32.png) [@moa.hunt](https://forum.aousd.org/u/moa.hunt)\
**Post date:** [October 25, 2023, 5:34pm UTC](https://forum.aousd.org/t/materialbindingapi-bind-mesh-to-material-prim/845/3 "2023-10-25T17:34:39Z")

</div>

@jackohoeg  
Thanks for your prompt response explaining I needed the UsdShade.Material object  
and also kindly offering the cleaner MaterialBindingAPI single call.  
Much appreciated.
