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?
How can I import a usd/usda file into the scene with Python script?
4602 4 0- quchen
- Member
- 75 posts
- Joined: 10月 2018
- Offline
- quchen
- Member
- 75 posts
- Joined: 10月 2018
- Offline
- quchen
- Member
- 75 posts
- Joined: 10月 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!
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!
- quchen
- Member
- 75 posts
- Joined: 10月 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!
>>> 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 - 2019年4月25日 10:41:57
- Paris Hall
- Member
- 1 posts
- Joined: 8月 2014
- Offline
-
- Quick Links