tas3d
2021年4月29日 16:27:52
Hi,
Can I get some help to get started with Python in LOPs.
I would like to create Volume Prim with Python Script LOP and assign it some fields( VDB paths).
I found this method in USD API docs, but not sure who to translate it to python
https://graphics.pixar.com/usd/docs/api/class_usd_vol_volume.html#af88d8076106e2b55bcc5bdcec3fc5e23 [
graphics.pixar.com]
This is failing miserably on the last line.
node = hou.pwd()
stage = node.editableStage()
vol = stage.DefinePrim('/vol', 'Volume')
vol.CreateFieldRelationship('somename', 'somepath')
AttributeError: 'Prim' object has no attribute 'CreateFieldRelationship'
mtucker
2021年4月29日 16:52:46
DefinePrim returns a Usd.Prim, which, as the error says, doesn't have a CreateFieldRelationship method.
You need a line in between those two that does `vol = UsdVol.Volume(vol)` to create a UsdVol.Volume object based on the Usd.Prim. This is a very common idiom in USD's python (and C++) APIs. This is because, I think, the base Usd.Prim object can be "interpreted" as a bunch of different object types at the same time. So there is no single class type that can encapsulate everything that a given Usd.Prim can do.
tas3d
2021年4月29日 22:44:22
Thanks a lot! I think I got a hang of it now.
Here is snippet for creating Volume with VDB fields inside.
from pxr import UsdVol
node = hou.pwd()
stage = node.editableStage()
volume = stage.DefinePrim('/volume', 'Volume')
volume = UsdVol.Volume(volume)
density = stage.DefinePrim('/volume/density', 'OpenVDBAsset')
density.GetAttribute('filePath').Set('Y:/eggsplosion.$F4.vdb')
density.GetAttribute('fieldName').Set('density')
volume.CreateFieldRelationship('density', density.GetPath())
mtucker
2021年4月30日 11:55:05
Of course there's also the Volume LOP for this

But I assume you have your reasons.
tas3d
2021年5月30日 22:19:43
Hey Mark,
Volumes work fine, now I would like to programmatically reference multiple USD files.
Pretty much what Reference/Sublayer LOPs do.
Any pointers for classes and methods from API that will do the job?
https://graphics.pixar.com/usd/docs/api/index.html [
graphics.pixar.com]
tas3d
2021年5月30日 23:17:28
I asked too early.
Found these and learned about importance of Default Primitive
node = hou.pwd()
stage = node.editableStage()
prim = stage.OverridePrim('/test')
prim.GetReferences().AddReference(filePath)