# Question regarding AllowedTokens

**URL:** https://forum.aousd.org/t/question-regarding-allowedtokens/1857
**Category:** USD
**Tags:** cpp
**Created:** [September 12, 2024, 1:01pm UTC](https://forum.aousd.org/t/question-regarding-allowedtokens/1857 "2024-09-12T13:01:05Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![hamed](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.aousd.org/hamed/32/677_2.png) [@hamed](https://forum.aousd.org/u/hamed)
#### Post date: [September 12, 2024, 1:01pm UTC](https://forum.aousd.org/t/question-regarding-allowedtokens/1857/1 "2024-09-12T13:01:05Z")

</div>

Hi,

Is there a significant difference between getting the allowedTokens meta data through UsdPrimDefinition vs directly from the attribute itself? If there is, when should I choose one over the other?

```auto
PXR_NS::VtTokenArray allowedTokens;
const PXR_NS::UsdPrimDefinition& primDef = prim.GetPrimDefinition();
primDef.GetPropertyMetadata(attr->GetName(),PXR_NS::SdfFieldKeys->AllowedTokens,&allowedTokens)

```

VS

```auto
 PXR_NS::VtTokenArray allowedTokens;
 attr.GetMetadata(PXR_NS::SdfFieldKeys->AllowedTokens,&allowedTokens)

```

---

<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: [September 19, 2024, 5:17am UTC](https://forum.aousd.org/t/question-regarding-allowedtokens/1857/2 "2024-09-19T05:17:42Z")

</div>

AllowedTokens on schema properties ideally would not be over rideable in scenes, since they are tied to coded schema behavior. So I’d recommend going to the PrimDefinition.

---

<div class="post-metadata">

### Author: ![hamed](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.aousd.org/hamed/32/677_2.png) [@hamed](https://forum.aousd.org/u/hamed)
#### Post date: [September 24, 2024, 8:34pm UTC](https://forum.aousd.org/t/question-regarding-allowedtokens/1857/3 "2024-09-24T20:34:16Z")

</div>

To be more clear, we do have some properties that are tied to our custom schema.

e.g

```auto
#usda 1.0

def Xform "root"
{
    def Xform "dummy"
    {
        token foo:flags:preset = "Default" (
            allowedTokens = ["Default", "A", "B", "C", "D"]
        )
    }
}

```

In my original approach ( code below ) I was only asking PrimDefinition to give me allowedTokens but in the case of above example, GetPropertyMetadata returns false.

```auto
PXR_NS::VtTokenArray allowedTokens;
const PXR_NS::UsdPrimDefinition& primDef = attrWrapper->usdPrim().GetPrimDefinition();

// returns true if a fallback value is defined for the given metadata
if (primDef.GetPropertyMetadata(attrWrapper->name(),PXR_NS::SdfFieldKeys->AllowedTokens,&allowedTokens)) {
    // create an Enum Attribute from a list of allowed tokens
} else {
    // create an Enum Attribute from the current value only
}

```

I think if I understand this correctly, I should first ask PrimDefinition and if that fails, then ask the metadata on the attribute to retrieve the allowedTokens. something like this:

```auto
    PXR_NS::VtTokenArray allowedTokens;
    const PXR_NS::UsdPrimDefinition& primDef = attrWrapper->usdPrim().GetPrimDefinition();
    if (primDef.GetPropertyMetadata(attrWrapper->name(),PXR_NS::SdfFieldKeys->AllowedTokens,&allowedTokens)) {
        // create an Enum Attribute from a list of allowed tokens
    } else if (attrWrapper->usdAttribute().GetMetadata(PXR_NS::SdfFieldKeys->AllowedTokens, &allowedTokens)) {
        // create an Enum Attribute from a list of allowed tokens tied to certain schema
    }
    else {
        // create an Enum Attribute from current value if both cases above fails
    }

```

---

<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: [September 28, 2024, 12:09am UTC](https://forum.aousd.org/t/question-regarding-allowedtokens/1857/4 "2024-09-28T00:09:25Z")

</div>

SchemRegistry Prim/Property definitions will only contain metadata fallbacks that were defined as part of the schema in the `schema.usda` source file - **not** anything authored in a particular scene.

Querying the UsdProperty directly will always consult both sources - you just won’t be able to tell which one it came from unless you consult the UsdPropertyStack for the property, or additionionally using your first batch of code.
