How can I import a usd/usda file into the scene with Python script?

   4564   4   0
User Avatar
Member
75 posts
Joined: Oct. 2018
Offline
I'm with Houdini 17.5 and when I import a usd/usda file, I can go through the menu , and select the usd/usda file I would like to open in the Choose Geometry dialog. My question is how can I import through a Python script, to do the same thing and not to bother the UI operations?

I tried this and it didn't work:

import hou

sceneRoot = hou.node('/obj')

# Import file to the scene
sceneRoot.loadChildrenFromFile('DUSD/USD_build_Hou17.5/out7.usda')


Any ideas to achieve this?
Edited by quchen - April 23, 2019 11:18:50
User Avatar
Member
75 posts
Joined: Oct. 2018
Offline
Looks like hou.Node.loadChildrenFromFile can load files saved with hou.Node.saveItemsToFile()only. So it may not be the right API to call.

Searching and waiting for inputs/suggestions. Thanks!
User Avatar
Member
75 posts
Joined: Oct. 2018
Offline
I did more tries today, and still no luck. Here is what I did.

I have a out7.usda file and I imported it into Houdini through menu. It could be imported successfully and here is the parm for the file printed from Python Shell:
>>> out7 = hou.node('/obj/out7')
>>> out7.evalParm('out7/file')
'DTechSupport/USD/USD_build_Hou17.5/out7.usda'

So, I tried to set up such a parm in another usd file, out8.usda, to load it up, but I couldn't find the ‘out7/file’ parm. Please see the pictures.




As you can see, for node out8, there is no equivalent parm named ‘out8’ like ‘out7’ for out7.
So next I tried to add such a parm but failed:

>>> out8.setParms({'out8/file':'DTechSupport/USD/USD_build_Hou17.5/usd8.usda'})
Traceback (most recent call last):
File “<console>”, line 1, in <module>
File “CPROGRA~1/SIDEEF~1/HOUDIN~1.173/houdini/python2.7libs\houpythonportion\Nod
e.py”, line 235, in setParms
raise hou.OperationFailed(“Invalid parameter name: ” + parm_name)
OperationFailed: The attempted operation failed.
Invalid parameter name: out8/file

I know this is a rude manner and it's normal that it failed. But can anyone please tell me how could I do it correctly?
Thank you!

Attachments:
out7-parm1.jpg (125.0 KB)
out7-parm-file.jpg (124.0 KB)
out8.jpg (114.1 KB)

User Avatar
Member
75 posts
Joined: Oct. 2018
Offline
More tries. I could load usd file through hou.Geometry:

>>> geoFile = hou.Geometry()
>>> geoFile.loadFromFile('DTechSupport/USD/USD_build_Hou17.5/out7.usda')
>>> geoFile
>>> geoFile.boundingBox()
<hou.BoundingBox >

But this didn't insert the geometry into the scene. Searching how to add this geometry as a node…
Any comment is welcome!
Edited by quchen - April 25, 2019 10:41:57
User Avatar
Member
1 posts
Joined: Aug. 2014
Offline
Hey there, quchen,

This is late, but have you ever checked out Varomix's video on setting up USD in Houdini?



This may be helpful.

I managed to get the Woodville Pixar Renderman Challenge File setup in Houdini 17.5.

Best of luck!
  • Quick Links