# Get Value from Root and Session Layer

**URL:** <https://forum.aousd.org/t/get-value-from-root-and-session-layer/2113>\
**Category:** USD\
**Tags:** cpp\
**Created:** [January 2, 2025, 6:38am UTC](https://forum.aousd.org/t/get-value-from-root-and-session-layer/2113 "2025-01-02T06:38:40Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Steven9988](https://avatars.discourse-cdn.com/v4/letter/s/f4b2a3/32.png) [@Steven9988](https://forum.aousd.org/u/Steven9988)\
**Post date:** [January 2, 2025, 6:38am UTC](https://forum.aousd.org/t/get-value-from-root-and-session-layer/2113/1 "2025-01-02T06:38:40Z")

</div>

Hi,

Happy new year !

I’m trying to get values of attribute, from both root and session layers in an efficient way.

For example, root layer and session layer

```auto
#sdf 1.4.32

def "test"
{
    def Xform "a"
    {
        double3 xformOp:translate = (0, 0, 0)
        uniform token[] xformOpOrder = ["xformOp:translate"]
    }
}

```

```auto
#usda 1.0

over "test"
{
    over "a"
    {
        double3 xformOp:translate = (1, -2, 3)
    }
}

```

If UsdAttribute API is being used, only override value (1, -2, 3) will be retrieved, the only way I figured out to get (0, 0, 0) from root layer will be like

```auto
auto tmp_stage = pxr::UsdStage::Open(stage->GetRootLayer());
auto attr = tmp_stage ->GetAttributeAtPath(_attr.GetPath());
pxr::VtValue value;
attr.Get(&value);

```

It has to re-open the root layer again to get rid of session layer, is there any better way to get the actual value at root layer ?

Thank you very much

---

<div class="post-metadata">

**Author:** ![dhruvgovil](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.aousd.org/dhruvgovil/32/3_2.png) [@dhruvgovil](https://forum.aousd.org/u/dhruvgovil)\
**Post date:** [January 3, 2025, 4:05pm UTC](https://forum.aousd.org/t/get-value-from-root-and-session-layer/2113/2 "2025-01-03T16:05:32Z")

</div>

You could use the GetPropertyStack method to find all the specs that contribute to the attribute

[https://openusd.org/dev/api/class\_usd\_property.html#a2159d3d651cd66e4fb1c724be90ed5e0](https://openusd.org/dev/api/class_usd_property.html#a2159d3d651cd66e4fb1c724be90ed5e0)

---

<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:** [January 3, 2025, 10:25pm UTC](https://forum.aousd.org/t/get-value-from-root-and-session-layer/2113/3 "2025-01-03T22:25:53Z")

</div>

Unfortunately, PropertyStacks are not a robust means of fetching attribute values, except possibly in the case where all data is authored in `defaults`. If an attribute possess timeSamples or Value Clips, the PropertyStack will not provide you with the time-mapping information you’d need to correctly resolve a value. And once [sparse array overrides](https://github.com/PixarAnimationStudios/OpenUSD-proposals/pull/76) are implemented, it will no longer be safe even to use PropertyStacks for resolving `defaults`, if the attribute is array valued.

The desired solution here is something I think we’ve filed, but have not yet scheduled, is the ability to provide an optional `UsdEditTarget` to `UsdAttribute::Get()`, which would be the layer/site to begin value resolution with.

In the meantime, the only thing I can suggest that is more efficient than reopening the stage is to **mute** the stage’s session layer, perform your necessary queries (better if you can batch them up to avoid needing to do this too many times), and then unmute it.

---

<div class="post-metadata">

**Author:** ![Steven9988](https://avatars.discourse-cdn.com/v4/letter/s/f4b2a3/32.png) [@Steven9988](https://forum.aousd.org/u/Steven9988)\
**Post date:** [January 6, 2025, 4:44am UTC](https://forum.aousd.org/t/get-value-from-root-and-session-layer/2113/4 "2025-01-06T04:44:00Z")

</div>

Still many thanks to you 🙂

---

<div class="post-metadata">

**Author:** ![Steven9988](https://avatars.discourse-cdn.com/v4/letter/s/f4b2a3/32.png) [@Steven9988](https://forum.aousd.org/u/Steven9988)\
**Post date:** [January 6, 2025, 4:45am UTC](https://forum.aousd.org/t/get-value-from-root-and-session-layer/2113/5 "2025-01-06T04:45:23Z")

</div>

Understood, I used to assume that the UsdEditTarget should work, and tried it to specify the session layer only but the API still returned override value.

Wish this could be solved in a more better way.
