Hi all,
Here is my context
I try “auto path = stage->ResolveIdentifierToEditTarget(”…/Marble.usda");"
but it return absolute path!
How should I set the relative path of the reference correctly?
Thank!
Hi all,
Here is my context
I try “auto path = stage->ResolveIdentifierToEditTarget(”…/Marble.usda");"
but it return absolute path!
How should I set the relative path of the reference correctly?
Thank!
I believe anchoring occurs with a single .
at the beginning of that path.
So (python example):
from pxr import Usd
filepath = "E:/test.usda"
stage = Usd.Stage.CreateInMemory(filepath)
prim = stage.DefinePrim("/Hello")
references = prim.GetReferences()
references.AddReference("./aa.usda")
print(stage.GetRootLayer().ExportToString())
Results in:
#usda 1.0
def "Hello" (
prepend references = @./aa.usda@
)
{
}
Which would be a relatively anchored path to the layer.
Do note that printing the stage wouldn’t show anything:
print(stage.ExportToString())
Prints:
#usda 1.0
(
doc = """Generated from Composed Stage of root layer
"""
)
def "Hello"
{
}
I initially thought this is because the stage is the composed result - the relative file did not exist for me, and hence it didn’t “compose” to anything and gets dropped. But if I author a path that does exist relatively it still didn’t work. Even though I set the identifier for the in-memory stage it didn’t seem to resolve the relative reference… whereas when I did:
from pxr import Usd
filepath = "E:/test.usda"
del stage
stage = Usd.Stage.CreateNew(filepath)
prim = stage.DefinePrim("/Hello")
references = prim.GetReferences()
references.AddReference("./aa.usda")
print(stage.ExportToString())
Note the use of Usd.Stage.CreateNew
it suddenly did work.
Hence, it may be that your in-memory stage may just be incapable of composing relative anchors and that’s why you were having a hard time?
Just using aa.usda
without the dot seemed to also work to relatively anchor - so take my “must start with a dot .
” as a grain of salt. Someone else may need to confirm the intended behavior.
UsdStage::Export()
and ExportToString()
will both output the composed (i.e. “flattened”) stage, so no references will ever show up (nor variants, etc). If you want to see the contents of the root layer, you can print out the layer itself by doing stage.GetRootLayer().ExportToString()
Thanks for your answer!
My main question is how to add a relative path reference to the Anonymous/InMemory layer.
Thanks for your answer!
Is there any way to add a relative path reference to the Anonymous/InMemory layer?
I saw some suggestions that you should first add an absolute path reference and then replace it with a relative path when exporting.