Getting prim metadata type in Python

I’m trying to list all the metadata of a UsdPrim in Python, but can’t see any API that will let me find the type of a metadata entry. You can get the value using GetMetadata(), and in C++, you get a VtValue back with a type, but in Python, VtValue just gets converted to a Python type. SdfSchema doesn’t seem to have python bindings, so I can’t go that route.

Is this just a hole in the API, or is there a way?

Thanks,

Jerry

Hi Jerry. There is a somewhat roundabout way to getting this–

>>> from pxr import Usd
>>> s = Usd.Stage.CreateInMemory()
>>> p = s.DefinePrim('/a')
>>> p.GetPrimStack()[0].GetTypeForInfo('documentation')
Tf.Type.FindByName('string')
>>> p.GetPrimStack()[0].GetTypeForInfo('kind')
Tf.Type.FindByName('TfToken')

Because the set of allowable metadata fields are the same for every spec type, you should be able to just query any spec of the relevant type.

It’s unfortunate that there’s no call in python that allows you query this without a spec instance. It seems like it could easily be made a @classmethod since the implementation doesn’t depend on the state of the spec: OpenUSD/pxr/usd/sdf/spec.cpp at dev · PixarAnimationStudios/OpenUSD

Hope that helps,
Matt

Many thanks for that. I’d started going down the p.GetPrimStack() route but got lost in a maze of twisty APIs.

Jerry