# Generating relative asset paths?

**URL:** <https://forum.aousd.org/t/generating-relative-asset-paths/1654>\
**Category:** USD\
**Created:** [July 3, 2024, 2:02am UTC](https://forum.aousd.org/t/generating-relative-asset-paths/1654 "2024-07-03T02:02:26Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![patricknagle](https://avatars.discourse-cdn.com/v4/letter/p/f17d59/32.png) [@patricknagle](https://forum.aousd.org/u/patricknagle)\
**Post date:** [July 3, 2024, 2:02am UTC](https://forum.aousd.org/t/generating-relative-asset-paths/1654/1 "2024-07-03T02:02:26Z")

</div>

Hi,

Is there a correct way to generate relative file paths using native usd api’s? I see that Sdf.Path has a `MakeRelatviePath`, but this doesn’t seem correct as I am trying to may relative paths for asset paths, sublayers etc. This fails when you have a path with a digit in it for example: /some/file/system/path/2048x1156/.

Or would it be better to just fall back to using python’s pathlib to generate these?

---

<div class="post-metadata">

**Author:** ![spiff](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.aousd.org/spiff/32/22_2.png) [@spiff](https://forum.aousd.org/u/spiff)\
**Post date:** [July 3, 2024, 5:04am UTC](https://forum.aousd.org/t/generating-relative-asset-paths/1654/2 "2024-07-03T05:04:09Z")

</div>

Yeah, Sdf.Path is about scenegraph paths, not assetPaths. I don’t believe we provide any such functionality, so pathlib sounds like a good way to go.

---

<div class="post-metadata">

**Author:** ![patricknagle](https://avatars.discourse-cdn.com/v4/letter/p/f17d59/32.png) [@patricknagle](https://forum.aousd.org/u/patricknagle)\
**Post date:** [July 8, 2024, 5:41am UTC](https://forum.aousd.org/t/generating-relative-asset-paths/1654/3 "2024-07-08T05:41:46Z")

</div>

Thanks @spiff! I am glad I wasn’t overlooking something obvious!

Out of curiosity where would you use a relative path in a usd file? Its not possible to do this with composition arcs right (I am pretty sure I tried and it said it must be an absolute path)…

---

<div class="post-metadata">

**Author:** ![spiff](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.aousd.org/spiff/32/22_2.png) [@spiff](https://forum.aousd.org/u/spiff)\
**Post date:** [July 9, 2024, 10:24pm UTC](https://forum.aousd.org/t/generating-relative-asset-paths/1654/4 "2024-07-09T22:24:57Z")

</div>

Relative paths can be used in any asset-path, so long as the resolver knows how to resolve them. So in the ArDefaultResolver, a path like `references = @ceramicMaterialsLibrary.usd@` would be perfectly fine, and would trigger a search through all of the directories listed in the configured searchPath.

You’d use this style anytime you want to have the flexibility to reorganize such assets without needing to touch your existing documents.

---

<div class="post-metadata">

**Author:** ![patricknagle](https://avatars.discourse-cdn.com/v4/letter/p/f17d59/32.png) [@patricknagle](https://forum.aousd.org/u/patricknagle)\
**Post date:** [July 10, 2024, 1:07am UTC](https://forum.aousd.org/t/generating-relative-asset-paths/1654/5 "2024-07-10T01:07:55Z")

</div>

Sorry I meant a relative prim path’s…i.e what is the purpose of the Sdf.Path().MakeRelativePath() within the scene graph?

---

<div class="post-metadata">

**Author:** ![spiff](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.aousd.org/spiff/32/22_2.png) [@spiff](https://forum.aousd.org/u/spiff)\
**Post date:** [July 10, 2024, 11:48pm UTC](https://forum.aousd.org/t/generating-relative-asset-paths/1654/6 "2024-07-10T23:48:31Z")

</div>

It’s not really a necessary thing… SdfLayer absolutizes paths as they are authored, and as they are read from usda files (which _can_ be hand-edited to contain relative paths). We have a few pieces of internal code that make use of it either for display purposes (a common scenario is for a prim to target lots of its descendant prims, and relativizing the paths for display reduces clutter), and I saw a site that uses it before sticking paths as keys into a map, though I’m not sure really why that’s advantageous.
