Jump to content

Python SOP


Nerox

Recommended Posts

I'm planning on implementing a A* path finding algorithm in a python SOP, ironically I get stuck on the first simple thing and thats creating an attribute on the Geometry :P.

This is what I do:

geo = hou.node('/obj/grid/attribcreate1').geometry()

>>> geo

<hou.Geometry in /obj/grid/attribcreate1>

>>> geo.addAttrib(hou.attribType.Point, "test", 1)

Traceback (most recent call last):

File "<console>", line 1, in <module>

File "/Users/prisms/builder-new/Nightly11.0/dev/hfs/houdini/python2.6libs/houpythonportion.py", line 605, in addAttrib

create_local_variable)

File "/Users/prisms/builder-new/Nightly11.0/dev/hfs/houdini/python2.6libs/hou.py", line 15228, in addAttrib

return _hou.Geometry_addAttrib(*args)

GeometryPermissionError: Geometry is read-only.

Link to comment
Share on other sites

You can only modify hou.Geometry objects from inside the Code section of a Python SOP. Anywhere else the geometry is read-only.

Alright, well that makes sense :-). I also found the problem, it's rather embarrassing, there was a 'return this command' halfway a function which I missed :unsure: . That's the reason it wasn't working :P. So I tried it in the shell which didn't work due to what's said above :P. I love trouble shooting, not the shit you have to go through but the rush when you 'conquer' the problem :P.

@Graham Thanks dude :D, as always

Edited by Nerox
Link to comment
Share on other sites

Nope, only from something within the cooking section. You can use external modules or scripts, called from within the section, but unless your hou.Geometry object comes from in there it will not be writable.

Link to comment
Share on other sites

Nope, only from something within the cooking section. You can use external modules or scripts, called from within the section, but unless your hou.Geometry object comes from in there it will not be writable.

thanks for the insight Graham

Link to comment
Share on other sites

  • 1 month later...

I am having similar issues and am somewhat confused about the logic. I have a large SOP network. Amongst it is an edit node....

Now from my understanding of the above, I can NOT edit a point attrib here -yet if I open the spreadsheet, click on the attrib for that point, I can use the ladder and on release the attrib sets and I see the result as expected i nthe viewport. The edit node automatically becomes locked, which i am fine with. Now I want to build up an interface on the HDA to do the same. The edit node is white listed to editable and still behaves the same when attempting the alteration via the spreadsheet as above.

Now I try the same via a callback py on the HDA button... something like ...

mygeo = mysop.geometry()

mypoints = mygeo.iterPoints()

mypt = mypoints[123]

mypt.setAttribValue('smoo', 1)

and it errors...

GeometryPermissionError: Geometry is read-only

So is seetting point attribs in a pysop only --not always the case?

is there a way to replicate this behavior other wise?

am I just confused on the matter? or is this just totally inconsistant?

Thank to anyone who has experiance with this.

Link to comment
Share on other sites

Your callback does not work because it is just that, a callback. As mentioned above, you can only modify geometry with Python from within the Code section of a Python SOP.

You can get the same type of effect you are looking for with something like this: http://houdinitoolbox.com/houdini.php?asset=2

It allows you to be able to change any attribute value you want by using the parameter dialog and selecting the components in the viewer. Unfortunately there is no support for spreadsheet dialogs in Houdini. If you wanted to do a programmatic method of setting values you could do it quite easily with this operator as long as you have an understanding of how it stores its data.

Link to comment
Share on other sites

Your callback does not work because it is just that, a callback. As mentioned above, you can only modify geometry with Python from within the Code section of a Python SOP.

You can get the same type of effect you are looking for with something like this: http://houdinitoolbox.com/houdini.php?asset=2

It allows you to be able to change any attribute value you want by using the parameter dialog and selecting the components in the viewer. Unfortunately there is no support for spreadsheet dialogs in Houdini. If you wanted to do a programmatic method of setting values you could do it quite easily with this operator as long as you have an understanding of how it stores its data.

Thanks for pointing me to your HDA, it looks useful but I am using py2.5 currently. Interestingly enough after posting this I started prototyping something similar but much narrower as I only need to deal with points of known attrib types/names and utilizing multiparms. I have a certain amount of concerns about speed as the amount of attrib change stack up, but Im going to have to go with somehting like it for now becuase of time constraints.

I still lfind it odd, that it would seem that the spreadsheet used as I orinally was-- was acting on the points attrib from outside the cook method although it is possibe I misunderstand the underpinnings of the spreadsheet.....

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...