# In memory USDA Generation of a UsdShadeMaterial and all of it's children

**URL:** <https://forum.aousd.org/t/in-memory-usda-generation-of-a-usdshadematerial-and-all-of-its-children/2974>\
**Category:** USD\
**Created:** [July 6, 2026, 6:44pm UTC](https://forum.aousd.org/t/in-memory-usda-generation-of-a-usdshadematerial-and-all-of-its-children/2974 "2026-07-06T18:44:12Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![evanburkert](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.aousd.org/evanburkert/32/828_2.png) [@evanburkert](https://forum.aousd.org/u/evanburkert)\
**Post date:** [July 6, 2026, 6:44pm UTC](https://forum.aousd.org/t/in-memory-usda-generation-of-a-usdshadematerial-and-all-of-its-children/2974/1 "2026-07-06T18:44:12Z")

</div>

What is the best way to generate an in memory usda representation of an existing UsdShadeMaterial, all of it’s connectables/attributes/metadata and it’s UsdShadeShader children without creating a new stage and exporting as a usda file to disk?

---

<div class="post-metadata">

**Author:** ![mtucker](https://avatars.discourse-cdn.com/v4/letter/m/54ee81/32.png) [@mtucker](https://forum.aousd.org/u/mtucker)\
**Post date:** [July 7, 2026, 2:20pm UTC](https://forum.aousd.org/t/in-memory-usda-generation-of-a-usdshadematerial-and-all-of-its-children/2974/2 "2026-07-07T14:20:28Z")

</div>

I read your question as “other than the right way to do this, what is the right way to do this” 🙂

I would strongly recommend creating a stage, using the USD APIs to create and set up your prims, and then using UsdStage::ExportToString to generate a string containing the USDA serialization of that stage.

I don’t even know what the second choice would be… Generating the USDA string directly? Maybe that would make sense if you have a template USDA and you just need to search and replace specific tokens, but in the general case of authoring generic shader prims you’d end up just alternative versions of the USD APIs that output USDA text directly.

---

<div class="post-metadata">

**Author:** ![evanburkert](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.aousd.org/evanburkert/32/828_2.png) [@evanburkert](https://forum.aousd.org/u/evanburkert)\
**Post date:** [July 7, 2026, 2:33pm UTC](https://forum.aousd.org/t/in-memory-usda-generation-of-a-usdshadematerial-and-all-of-its-children/2974/3 "2026-07-07T14:33:50Z")

</div>

More so looking for a way to achieve this using the current stage we are operating on and somehow utilize the PrimSpec to do this. I have it working with geometry like UsdGeomXform and Mesh, but materials are not filling out all the connections and attributes.

---

<div class="post-metadata">

**Author:** ![jerry.huxtable](https://avatars.discourse-cdn.com/v4/letter/j/b19c9b/32.png) [@jerry.huxtable](https://forum.aousd.org/u/jerry.huxtable)\
**Post date:** [July 9, 2026, 2:26pm UTC](https://forum.aousd.org/t/in-memory-usda-generation-of-a-usdshadematerial-and-all-of-its-children/2974/4 "2026-07-09T14:26:34Z")

</div>

Create a new stage with the root layer of the original stage and set its population mask to be all the prims you want to include, and call ExportToString. …or just call SetPopulationMask on the original stage and set it back after exporting.

Jerry

---

<div class="post-metadata">

**Author:** ![evanburkert](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.aousd.org/evanburkert/32/828_2.png) [@evanburkert](https://forum.aousd.org/u/evanburkert)\
**Post date:** [July 9, 2026, 3:14pm UTC](https://forum.aousd.org/t/in-memory-usda-generation-of-a-usdshadematerial-and-all-of-its-children/2974/5 "2026-07-09T15:14:45Z")

</div>

That looks promising! I will give it a try. Thanks!
