How do i create an attribute inside Python Sop?

   18990   4   0
User Avatar
Member
12 posts
Joined: Sept. 2016
Offline
node = hou.node('/obj/surface/file')
geo = node.geometry()
geo.addAttrib(hou.attribType.Global,“test”,1)

this gives me

return _hou.Geometry_addAttrib(*args)
GeometryPermissionError: Geometry is read-only

And the error code is not much helpful.


thanks
User Avatar
Member
8509 posts
Joined: July 2007
Online
in Python SOP you can only modify current geometry, it doesn't have permissions to change geometry of other nodes like in your example
so you can only do this:

node = hou.pwd()
geo = node.geometry()
geo.addAttrib(hou.attribType.Global, "test", 1)

and connect your /obj/surface/file as a first input of Python SOP
Edited by tamte - Sept. 25, 2016 14:34:23
Tomas Slancik
FX Supervisor
Method Studios, NY
User Avatar
Member
12 posts
Joined: Sept. 2016
Offline
@tamte

Thanks, that makes perfect sense and your solution works. However I have couple issues with adding attr in Python .

- It also creates “varmap” along with what I am trying to create. I understand that this must be the local vairable name but why does not create with the name I gave it? How do I access that “varmap” to change the name.

- It also does not set the value I give in the command, if the given value is a text entry (the entry in the spreadsheet is empty. For instance
geo.addAttrib(hou.attribType.Global, "test", "string test")

I have to add another command to modify the value for the actual thing with this
geo.setGlobalAttribValue("test", "string test")


Not a big deal but I wonder if it is a bug or the initial command parsing cant decide on the type of the variable (unlike what the doc says about it)



tamte
in Python SOP you can only modify current geometry, it doesn't have permissions to change geometry of other nodes like in your example
so you can only do this:

node = hou.pwd()
geo = node.geometry()
geo.addAttrib(hou.attribType.Global, "test", 1)

and connect your /obj/surface/file as a first input of Python SOP
Edited by veritasone - Sept. 25, 2016 18:41:39
User Avatar
Member
1 posts
Joined: Jan. 2010
Offline
I am also trying to add an attribute using the python node.
Eventually I want to load in some values via Json, and set them to the "Cd" values for the primitives of my geo.
But first I thought I'd simply try adding an attribute via the python node.

I have:

node = hou.pwd()
geo = node.geometry()

geo.addAttrib(hou.attribType.Prim, "Cd", hou.Vector3(1.0,0.0,0.0))

But it does nothing, I have a geometry spreadsheet open but I don't see any attributes appearing underneath the primitives tab or any other.

I am not getting an error, so it seems to be evaluating the code fine, but nothing happens.

Any idea? The geometry is connected to the first input.
User Avatar
Member
2527 posts
Joined: June 2008
Offline
Here's two ways to do it. One using an attribute and the other fetching from a parameter on the python node.

Attachments:
Untitled-1.jpg (254.6 KB)
ap_Get_OS_Time.hipnc (276.7 KB)

Using Houdini Indie 20.0
Ubuntu 64GB Ryzen 16 core.
nVidia 3050RTX 8BG RAM.
  • Quick Links