# HdContainerDataSourceEditor example

**URL:** <https://forum.aousd.org/t/hdcontainerdatasourceeditor-example/1089>\
**Category:** Hydra\
**Tags:** cpp\
**Created:** [January 3, 2024, 9:16pm UTC](https://forum.aousd.org/t/hdcontainerdatasourceeditor-example/1089 "2024-01-03T21:16:18Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ashwin.bhat](https://avatars.discourse-cdn.com/v4/letter/a/8c91f0/32.png) [@ashwin.bhat](https://forum.aousd.org/u/ashwin.bhat)\
**Post date:** [January 3, 2024, 9:16pm UTC](https://forum.aousd.org/t/hdcontainerdatasourceeditor-example/1089/1 "2024-01-03T21:16:18Z")

</div>

Hi  
I’m looking for a way to edit the material binding on a datasource. Can someone help with some pointers on how to do this?  
Thanks

---

<div class="post-metadata">

**Author:** ![ashwin.bhat](https://avatars.discourse-cdn.com/v4/letter/a/8c91f0/32.png) [@ashwin.bhat](https://forum.aousd.org/u/ashwin.bhat)\
**Post date:** [January 16, 2024, 8:02pm UTC](https://forum.aousd.org/t/hdcontainerdatasourceeditor-example/1089/2 "2024-01-16T20:02:46Z")

</div>

I was hoping if you could give me some pointers on how material datasources can be edited using `HdContainerDataSourceEditor`? I haven’t to able to find any examples/tests so far.  
Basically I’m trying two things:

1. Editing a mesh data source to assign a new material (`HdMaterialBindingSchema`)
2. Editing a terminal value of a material in a datasource.

---

<div class="post-metadata">

**Author:** ![tomc](https://avatars.discourse-cdn.com/v4/letter/t/8dc957/32.png) [@tomc](https://forum.aousd.org/u/tomc)\
**Post date:** [January 25, 2024, 12:23am UTC](https://forum.aousd.org/t/hdcontainerdatasourceeditor-example/1089/3 "2024-01-25T00:23:10Z")

</div>

Hi Ashwin,

You can find some examples of the container data source editor here: [OpenUSD/pxr/imaging/hd/testenv/testHdContainerDataSourceUtils.cpp at release · PixarAnimationStudios/OpenUSD · GitHub](https://github.com/PixarAnimationStudios/OpenUSD/blob/release/pxr/imaging/hd/testenv/testHdContainerDataSourceUtils.cpp#L124) …

If you want to override the material binding of a prim to “/Foo”, you could do:

```auto
HdSceneIndexPrim prim = sceneIndex.GetPrim("/Bar");
HdContainerDataSourceEditor edit(prim.dataSource);
edit.Set(HdMaterialBindingsSchema::GetDefaultLocator(),
  HdMaterialBindingsSchema::BuildRetained(1, {HdMaterialBindingsSchemaTokens->allPurpose},
    HdMaterialBindingSchema::BuildRetained(HdCreateTypedRetainedDataSource(SdfPath("/Foo")), nullptr)));
prim.dataSource = edit.Finish();

```

If you’re trying to modify a material network in particular, we have a specialization of the container data source editor for editing material networks:

> <https://github.com/PixarAnimationStudios/OpenUSD/blob/release/pxr/imaging/hd/dataSourceMaterialNetworkInterface.h>

Hope that helps!  
Tom
