Layer attributes from VEX

   3365   5   1
User Avatar
Member
321 posts
Joined:
オンライン
How do I get layer info with VEX?

I want the layer's scale info, so I tried this:

float unitscale = usd_metadata(0, '/', 'metersPerUnit');

But I get a zero instead of the right unit. Is this wrong? Sorry if I'm spamming the forum with obvious questions…
User Avatar
Member
3 posts
Joined: 10月 2016
オフライン
I'm not sure about vex but you can easily get anything with a python node and the pxr USD API. For example

from pxr import Usd

stage = Usd.Stage.Open(<usd file path>)
unitscale = stage.GetMetadata("metersPerUnit")

There is already a stage variable when you create a python lop which is the conne ted stage so you can possibly skip the whole Usd.Open() line.

I might have syntax errors but hope it paints a picture. Documentation for the USD python API is a bit tricky but it's worth looking into it.
User Avatar
スタッフ
1470 posts
Joined: 7月 2005
オフライン
It should work. Looks like a bug. Quick check shows that USD API method `UsdStage::GetObjectAtPath(“/”)` does not return the pseudo-root object for some reason.
User Avatar
Member
321 posts
Joined:
オンライン
I see, I also just tried to get the information with Python and got this error:
>>> stage.GetObjectAtPath('/').GetAllMetadata()
Traceback (most recent call last):
  File "<console>", line 1, in <module>
RuntimeError: Accessed <pxr.Usd.Object object at 0x7f234d02b2f8>

while something like this works in a parameter expression:

pwd().inputs()[0].stage().GetMetadata('metersPerUnit')
Edited by jparker - 2020年11月23日 14:22:29
User Avatar
Member
321 posts
Joined:
オンライン
I'll file a bug and send an example scene (and reference this thread).
User Avatar
Member
321 posts
Joined:
オンライン
Bug #109661
  • Quick Links