Point attrib to Node name set. ( Python)

   1531   3   0
User Avatar
Member
25 posts
Joined: 1月 2014
Offline
Hey there.

I have a question

1.) I am trying to take a pointcloud with a string name attribute, and then I want to create a geo node per point,
2.) extract the path attribute from the point and feed it into a parm on that newly created node
3.) set node name to the name in the attribute as well
3.) in python.

import hou

sel = hou.selectedNodes()

createWorkArea = hou.node("/obj").createNode("subnet", "workArea")

for node in sel:
    geo = node.geometry()
    points = geo.iterPoints()


    for point in geo.points():

        Path = geo.findPointAttrib("name")
        FullPathAttrib = point.attribValue(Path)
        
        createGeoNode = createWorkArea.createNode("geo", "geoNode")
        
        #############The line below is causing issues.
        createGeoNode.setName(FullPathAttrib)

        AttribParm = createGeoNode.parm("some parm here")
        AttribParm.set(FullPathAttrib)

So I got the parm set portion working, the creation of the nodes is ok. but the setting the names of the nodes not so much.

What am I doing wrong?

EDIT: I also tried this in the problematic node. didn't work either.

createGeoNode.setName('' + str(FullPathAttrib))


Any help would be appreciated.
Edited by Martin Krol - 2022年6月1日 15:22:21
User Avatar
Member
35 posts
Joined: 6月 2019
Offline
createNode allows you to set node name, so I guess you can set the name there instead of writing another line to set name?

    for point in geo.points():

        Path = geo.findPointAttrib("name")
        FullPathAttrib = point.attribValue(Path)
        
        createGeoNode = createWorkArea.createNode("geo", FullPathAttrib) ##########TRY THIS?
        
        #############The line below is causing issues.
        ####createGeoNode.setName(FullPathAttrib)
User Avatar
Member
8785 posts
Joined: 7月 2007
Online
"is causing issues" and "not working" is a very vague description
are you getting any specific error?

if your are for example getting "Invalid Name" error make sure that the name attribute on all the points is a valid name, so no invalid characters like space or / etc...
Tomas Slancik
FX Supervisor
Method Studios, NY
User Avatar
Member
25 posts
Joined: 1月 2014
Offline
Thanks guys.

So, for whatever reason using node.setName(str(someDeclaredVariable))
was giving me the following error:

hou.NetworkMovableItem_setName(self, name, unique_name)
OperationFailed:the attempted operation failed.

However, I did as hinsunlee suggested. I wrote str(someDeclaredVariable)) into the name section when creating the node and not as a separate line, and it worked out .

so what worked was changing this line

createGeoNode = createWorkArea.createNode("geo", "geoNode")

into this

createGeoNode = createWorkArea.createNode("geo", str(fullPathAttrib))

Cheers.
  • Quick Links