Node Child & Setting Parameters in Python

   4996   3   2
User Avatar
Member
767 posts
Joined: April 2014
Offline
I'm hoping someone can help. I want to create a scatter node which is the child of the parent node although it won't have a connection to the parent node but is the child of variable theNode ?

I also want to set some parameters for the variable theNode ?

Neither of the two is working without an error.

for n in hou.selectedNodes():
    print("the list is" + n.name())
    
theNode = hou.node('/obj/sphere/sphere2')
print(theNode.path())
theNode.setName("theSphere")
ColorNode = hou.Color(1,0.8,1.7)
theNode.setColor(ColorNode)
theNode.createNode("scatter1","theScatter")
theNode("scatter1").children()
theNode.setParms({"radx":2.2,"radz":1.2})
if theNode.name():
    print("the node is selected")
else:
    print("couldn't make the node selected")
【T】【C】【S】
User Avatar
Member
8184 posts
Joined: Sept. 2011
Offline
http://www.sidefx.com/docs/houdini/hom/intro [www.sidefx.com]
There's very thorough documentation on each of the classes and their functions in the Houdini object module.

I'm not sure what you are after, but there are some basic problems with the code you have as entered.
the createNode() function takes a node type name as an argument, and the rest as keyword arguments. There is no such type as “scatter1” unless you have defined such a type yourself. ‘theNode’ is an instance of a hou.SopNode object (“theSphere” if it exists), and cannot be called as a function, so calling .children() does not make sense here either.

Perhaps something like this is what you are after:
theNode = hou.node("/obj/sphere/sphere2")
if theNode:
    print("the node is selected")
    theNode.setName("theSphere")
    ColorNode = hou.Color(1,0.8,1.7)
    theNode.setColor(ColorNode)
    theParent = theNode.parent()
    theScatter = theParent.createNode("scatter",node_name="theScatter")
    theNode.setParms({"radx":2.2,"radz":1.2})
else:
    print("couldn't make the node selected")
User Avatar
Staff
3465 posts
Joined: July 2005
Offline
in the Python Shell you can try:

myNode = (drag and drop your node here) then press enter

print myNode.asCode()



this will show you how Houdini makes nodes and sets their parameters…
Michael Goldfarb | www.odforce.net
Training Lead
SideFX
www.sidefx.com
User Avatar
Member
767 posts
Joined: April 2014
Offline
@jsmack - I knew there was problems with the code Your code helps to correct mistakes. And thanks @arctor for the command
Edited by _Christopher_ - Sept. 24, 2017 19:58:57
【T】【C】【S】
  • Quick Links