Python coding problems

   2280   3   1
User Avatar
Member
8 posts
Joined: Feb. 2013
Offline
Hi all !

I'm trying to make an asset whereby a user can generate a simple game platform by pressing buttons which I'm creating to extend the platform to a direction, however I came across a few problems.
Firstly, I would like to know is it possible to do a similar way of “ copy parameter & paste copied relative references ” in python coding.

And is there a way where I'm able to attach the newly created node from pressing the button to the previously created node ? I know right now I'm just linking to the null node that has the buttons.



def onButtonPress():
import hou

b = hou.node(“/obj/grid_object1/DIRECTION”)
a = hou.node(“/obj/grid_object1/”).createNode(“duplicate”,“LEFT”)
a.parm(“newg”).set(1)
a.parm(“tx”).set(5)
a.parm(“sourceGrp”).set(“copyGroup1”)
a.inputs()
a.setNextInput(b)
a.inputs()
a.moveToGoodPosition()
User Avatar
Member
1908 posts
Joined: Nov. 2006
Offline
You can make easy channel references by setting one hou.Parm to another hou.Parm.
>>> p1=hou.parm('/obj/geo1/tx')
>>> p2=hou.parm('/obj/geo1/xform1/tx')
>>> p2.set(p1)
>>> p2.expression()
'ch(“../tx”)

You can create a node connected to the most recently created node in a network by asking the network for the last child node and calling createOutputNode() on it. The children list should be sorted based on creation order.
>>> geo = hou.node(“/obj/geo1”)
>>> n1 = geo.createNode(“null”)
>>> n1
<hou.SopNode of type null at /obj/geo1/null3>
>>> n2 = geo.children().createOutputNode(“null”)
>>> n2.inputs()
(<hou.SopNode of type null at /obj/geo1/null3>,)
Graham Thompson, Technical Artist @ Rockstar Games
User Avatar
Member
8 posts
Joined: Feb. 2013
Offline
Thank you graham for the help ! I don't really understand the way to use this codeas this still connects to my main null which has the button when i press several times.


>>> geo = hou.node(“/obj/geo1”)
>>> n1 = geo.createNode(“null”)
>>> n1
<hou.SopNode of type null at /obj/geo1/null3>
>>> n2 = geo.children().createOutputNode(“null”)
>>> n2.inputs()
(<hou.SopNode of type null at /obj/geo1/null3>,)


Furthermore, is there a way to increase the node digit by one every time I click the button as the code,


p2=hou.parm('/obj/geo1/xform1/tx')


will have problems when I create another one due to the naming being xform1 . If i am not wrong, python does not allow string parameter expressions.
User Avatar
Member
106 posts
Joined: June 2011
Offline
I'm not sure where exactly you have your callbacks to add. If you could give an example file, it'll be helpful. But something like this should give what you want. You can change the expression and values accordingly for other directions as well.


def onButtonPress():
import hou
grid = hou.node(“/obj/grid_object1/grid1”)

b = hou.node(“/obj/grid_object1”).children()
if b.type().name() != ‘duplicate’:
a = b.createOutputNode('duplicate', ‘RIGHT’)
a.parm(“tx”).set(grid.parm('sizex'))
a.parm(“sourceGrp”).set(“copyGroup1”)
a.parm(“newg”).set(1)
a.moveToGoodPosition()
else:
a = b
ncy = a.parm(“ncy”).eval()
a.parm('ncy').set(ncy + 1)



Hope this helps

Cheers
-J
  • Quick Links