getting a wild card matched list of nodes with python

   8903   6   1
User Avatar
Member
120 posts
Joined: Feb. 2008
Offline
Hello,


I have 10 box_objects in my scene. I'd like to get them as a list in python.
I know how to get a list of parameters of a node, but I would like to know how to get a list of nodes matching a name-string.
Something like (this is totally wrong pseudo-code but this is the general idea):


nodeorigin = hou.node('/obj')
boxlist =

Thanks!


———————————————————–

found this in the help… not exactly what I need but we're getting closer…

for n in hou.node(“/obj”).children():
print n.name()

I need this to be a list, and take out all objects without “box_object*” in the name…
User Avatar
Member
1926 posts
Joined: Nov. 2006
Offline
Depending on exactly how your objects are named and whatnot you could go:

obj = hou.node('/obj')

For when the node name starts with your main string, so box_object*
boxes =

or for anything, *box_object*
boxes =
Graham Thompson, Technical Artist @ Rockstar Games
User Avatar
Member
120 posts
Joined: Feb. 2008
Offline
Thanks graham, that's awesome. Now I'm trying to accomplish the next part of the task… I've got this so far:

>>> boxes =
>>> boxes
[<hou.ObjNode of type geo at /obj/box_object1>,
<hou.ObjNode of type geo at /obj/box_object2>,
<hou.ObjNode of type geo at /obj/box_object3>,
<hou.ObjNode of type geo at /obj/box_object4>
]

————–
I would like to set, for example, the tx of all nodes in the list to 1.

(Here I tried to set all parms to 1 just to try, but I'd really just like to affect one or more parameters at a time)

>>> for theparm in boxes.parms():
… theparm.set(1)

Traceback (most recent call last):
File “<console>”, line 1, in <module>
AttributeError: ‘list’ object has no attribute ‘parms’

I am thinking I might need to use nested for loops here but can't quite get my head around the syntax yet…
User Avatar
Member
1926 posts
Joined: Nov. 2006
Offline
To set tx to 1 on each box:

for box in boxes:
box.parm('tx').set(1)


To set all parms to 1:

for box in boxes:
for parm in box.parms():
parm.set(1)

Here's some other, more advanced ones.

Set multiple parms to the same value:

parms = ('tx', ‘ry’, ‘sz’)
value = 4
for box in boxes:
for parmname in parms:
box.parm(parmname),set(value)

Setting multiple parts with unique values:

parmdict = { ‘tx’: 4,
‘ry’: 50,
‘sz’: 2 }

for box in boxes:
for key in parmdict:
box.parm(key),set(parmdict.get(key)


Setting groups of parms with a similar value:

valdict = {5: ('tx', ‘rx’, ‘sx’),
7: ('ty', ‘ry’, ‘sy’),
19: ('tz', ‘rz’, ‘sz’),

for box in boxes:
for key in valdict:
for parm in valdict.get(key)
box.parm(parm).set(key)
Graham Thompson, Technical Artist @ Rockstar Games
User Avatar
Member
120 posts
Joined: Feb. 2008
Offline
really fantastic… You guys might want to consider adding some more of these beginner level notes to the HOM help, they might seem simple but for non-programmers it could be essential…



Another question, how to select a node in the network view using a python command?
User Avatar
Member
77 posts
Joined: Nov. 2007
Online
Use:
hou.node(“/path/to/your/node”).setCurrent(1,1)
to select the target node and deselect everything else that is already selected.

hou.node(“/path/to/your/node”).setCurrent(1,0)
to select the target node while keeping the current selection.

Assuming your Houdini doc server is using the default port, go to:
http://localhost:48626/hom/hou/Node [localhost]

and search for setCurrent() for more details.
User Avatar
Member
120 posts
Joined: Feb. 2008
Offline
Excellent, thanks for your response!
  • Quick Links