Creating Prims with Python in LOP
2587
5
2
tas3d
Member
120 posts
Joined: Jan. 2012
Offline
April 29, 2021 4:27 p.m.
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'
Edited by tas3d - April 29, 2021 16:28:30
Michal Tas Maciejewski @
www.vfxtricks.com
mtucker
Staff
4438 posts
Joined: July 2005
Offline
April 29, 2021 4:52 p.m.
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
Member
120 posts
Joined: Jan. 2012
Offline
April 29, 2021 10:44 p.m.
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 ())
Edited by tas3d - April 29, 2021 22:45:14
Michal Tas Maciejewski @
www.vfxtricks.com
mtucker
Staff
4438 posts
Joined: July 2005
Offline
April 30, 2021 11:55 a.m.
Of course there's also the Volume LOP for this
But I assume you have your reasons.
tas3d
Member
120 posts
Joined: Jan. 2012
Offline
May 30, 2021 11:17 p.m.
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)
Michal Tas Maciejewski @
www.vfxtricks.com