'Node' object has no attribute 'geometry'

   6386   5   0
User Avatar
Member
75 posts
Joined: Oct. 2018
Offline
I'm just starting learning Python in Houdini and trying the python scripts in document to get the geometry of a node, it looks simple and straightforward but I got the error saying ‘Node’ object has no attribute ‘geometry’. Please see the output from the Python Shell window:

>>> node = hou.pwd()
>>> geo = node.geometry()
Traceback (most recent call last):
File “<console>”, line 1, in <module>
AttributeError: ‘Node’ object has no attribute ‘geometry’
>>>

What I'm I doing wrong here, and how can I fix it?
User Avatar
Member
8170 posts
Joined: Sept. 2011
Online
Only SOPNodes have geometry. What node are asking geometry from?
User Avatar
Member
75 posts
Joined: Oct. 2018
Offline
I was trying the code samples from C:\Program Files\Side Effects Software\Houdini 17.5.173\houdini\PythonScripts.txt.
Here are part of it:

# Python SOP

Sop/pythonscript/python
Default Script
node = hou.pwd()
geo = node.geometry()

# Add code to modify contents of geo.
# Use drop down menu to select examples.

Sop/pythonscript/python
Move Points Up
node = hou.pwd()
geo = node.geometry()

# Add code to modify contents of geo.
for point in geo.points():
pos = point.position()
pos += hou.Vector3(0, 1, 0)
point.setPosition(pos)


So yeah you're right @jsmack only Sop nodes have geometry, thank you! And indeed I want to create a Sop node for my usd file, with usd plugin installed of course. I could use hou.Geometry.loadFromFile to load the my usd successfully but I don't know how to create a sop node for it. Sorry for the newbie question, and any help is welcome!
User Avatar
Member
9236 posts
Joined: July 2007
Online
that code is intended for Python SOP node, which is the only one that can actually modify geometry using python
so create Python SOP, and put your code there
Tomas Slancik
CG Supervisor
Framestore, NY
User Avatar
Member
8170 posts
Joined: Sept. 2011
Online
I think what you want to do is more or less this:

create an object
create a file sop
tell the file sop to load a file

You don't do any of that with the geometry module, which is for directly editing geometry.

In python that would be something like:

myfile = "/path/to/foo.usd"
fname = "foo"
geo = hou.node("/obj").createNode("geo", fname)
fi = geo.createNode('file')
fi.parm('file').set(myfile)
User Avatar
Member
75 posts
Joined: Oct. 2018
Offline
This is exactly what I want, thank you so much jsmack!
So the lesson here is that I need to create my own node network by first creating a geo node, then a file node under it, and giving the file node my file path. Thanks again!
  • Quick Links