Get point/primitive/detail attribs from any sop using python

   3317   1   1
User Avatar
Member
6 posts
Joined: July 2022
Offline
New to python scripting,
i was wondering how can i access point/primitive/detail attribs from any sops with python scripting?

image url: https://gyazo.com/ba7c3b65a24c9c103065f08225aeeac6 [gyazo.com]
like here, i need to get detail or point attrib(string type) from attribWrangler8 sop to my python script sop 'python2'
Edited by leibao - Jan. 16, 2023 05:50:37
User Avatar
Member
54 posts
Joined: June 2017
Offline
I'm always dubious of using python nodes for some reason. I prefer doing as much as I can in HDAs or elsewhere.
However, that said, the logic is the same everywhere and functions are found on this page
https://www.sidefx.com/docs/houdini/hom/hou/Geometry.html [www.sidefx.com]
The python node sets up the geo variable to begin with. It's fairly easy to access detail attributes because they're just attached to the geometry itself Something like this would work:
node = hou.pwd()
geo = node.geometry()
value = geo.stringAttribValue("nameOfAttribute")
It's a bit trickier with other attribute types though. The python node doesn't iterate over them by default, so you have to set that up yourself. So if you wanted to access a point attribute for example, you could do something like this instead:
pts = geo.iterPoints()
for pt in pts:
    val = pt.stringAttribValue("nameOfAttribute")
    # To set an attribute
    pt.setAttribValue("nameOfAttribute", "intendedValue")
If you CAN do any of these processes through VEX instead I would encourage it, because Python is much slower by default.
Edited by EJaworenko - Feb. 24, 2023 22:27:51
Houdini TD, I focus on tools for procedural asset creation.

www.jaworenko.design
  • Quick Links