Jump to content

Add Name Attribute Via Python


cgartashish

Recommended Posts

Hi,

How to add a name attribute to each point in a selected geometry via the python sop?

Suppose I have a box with 4 points and I want each point to be named as piece0, piece1 and so on where the number is its point number. I have written a code, it adds the attribute to the spreadsheet but is unable to add the value. The value is added only when it is not a string. Please Help.

 

The code that I tried:

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

geo.addAttrib(hou.attribType.Point, "name", "piece")

 

Please also add how to add the respective point numbers to the string piece.

Thanks

Link to comment
Share on other sites

Wow, Thanks it works like charm.

Hey can you please help me with python for houdini. Because the documentation for python in Houdini is very wierd. I cannot get enough examples and all the functions are very hard to find. So can you point me to some documentation elsewhere or tutorial? Or can you please tell me how to follow the documentation because I always feel lost in it. Like finding some examples or some function name, etc. 

Link to comment
Share on other sites

The documentation is the first thing I look through. But I agree, it does kinda lack in the way of examples.
Next I also google stuff, where the results are usually from this forum, or at Sidefx.
For general python syntax and functions, I still use google. :D

Lastly, if I have an issue and all of the above is still lacking.. I would try and post a thread to hopefully get some answers.

As for examples, I try and check out built-in HDA's and peek inside the Scripts tab, sometimes it contains python code.
Also if you explore the Shelf Tools, most of those uses a module in the form of 'tools' that you can find at $HFS\houdini\python2.7libs
They have lots of functions there with descriptions.

I'm also still just learning as I go with my day to day Houdini adventure. Wishing you the best of luck!

  • Like 2
Link to comment
Share on other sites

On 11/22/2017 at 10:31 PM, galagast said:

The documentation is the first thing I look through. But I agree, it does kinda lack in the way of examples.
Next I also google stuff, where the results are usually from this forum, or at Sidefx.
For general python syntax and functions, I still use google. :D

Lastly, if I have an issue and all of the above is still lacking.. I would try and post a thread to hopefully get some answers.

As for examples, I try and check out built-in HDA's and peek inside the Scripts tab, sometimes it contains python code.
Also if you explore the Shelf Tools, most of those uses a module in the form of 'tools' that you can find at $HFS\houdini\python2.7libs
They have lots of functions there with descriptions.

I'm also still just learning as I go with my day to day Houdini adventure. Wishing you the best of luck!

Thanks alottttt. :)

Link to comment
Share on other sites

  • 2 years later...
On 2017-11-17 at 3:38 AM, galagast said:

Something like this?


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

geo.addAttrib(hou.attribType.Point, "name", "")
for point in geo.points():
    point.setAttribValue("name", "piece" + str(point.number()))

Then look at this post by Graham explaining why string types does not have a default value.

Hello, after going through this thread, I tried these lines in my script, I have a question that how you added points in "geo.points()"?

I have created my point attributes already in Houdini, but I think by using "for point in geo.points()", I need to add my created points into geo.points()? Otherwise it is a empty object by default?

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...