cgartashish Posted November 17, 2017 Share Posted November 17, 2017 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 Quote Link to comment Share on other sites More sharing options...
galagast Posted November 17, 2017 Share Posted November 17, 2017 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. 1 Quote Link to comment Share on other sites More sharing options...
Parboil Posted November 17, 2017 Share Posted November 17, 2017 Another method of string concatenation is to use the format() function. name = "piece{0}".format(point.number()) 2 1 Quote Link to comment Share on other sites More sharing options...
cgartashish Posted November 21, 2017 Author Share Posted November 21, 2017 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. Quote Link to comment Share on other sites More sharing options...
galagast Posted November 22, 2017 Share Posted November 22, 2017 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. 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! 2 Quote Link to comment Share on other sites More sharing options...
cgartashish Posted November 23, 2017 Author Share Posted November 23, 2017 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. 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. Quote Link to comment Share on other sites More sharing options...
CatherineKan Posted June 8, 2020 Share Posted June 8, 2020 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? Quote Link to comment Share on other sites More sharing options...
bunker Posted June 8, 2020 Share Posted June 8, 2020 (edited) or use VEX, much simpler and a lot faster to compute. attribWrangle: s@name="piece"+itoa(@ptnum); Edited June 8, 2020 by bunker 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.