how to query the currently selected nodes in python?

   8504   4   1
User Avatar
Member
82 posts
Joined: Oct. 2007
Offline
Hi,
All in the title ! BTW it is possible to use a hscript command( bonealigncapture…not sure if there is a python version of this command) in a python context?
I am new to houdini…I must learn python but I dont want to spend to much time with hscript .
I have try the hou.Node.setSelected function but can't find the good arguments…I am not a programmer.

Tky !
User Avatar
Member
1926 posts
Joined: Nov. 2006
Offline
There currently is no single command that will give you the currently selected nodes in Houdini. What you have to do is basically iterate over all the nodes at the current level checking if they are selected. The easiest way to do that is something like:


import toolutils

cwd = toolutils.sceneViewer().pwd()
selected =


Also, you can use hscript commands using hou.hscript() and hou.hscriptExpression()

hou.hscript('chwrite tx test.chan')
hou.hscriptExpression('stamp('../copy1', something, 0)
Graham Thompson, Technical Artist @ Rockstar Games
User Avatar
Member
82 posts
Joined: Oct. 2007
Offline
hi grahamt,
tks for your answer and sorry for the long delay…I am learning python and oop…
I have a question for you. If I do this :

typecwd = type(cwd)

I am getting this result (at the obj level ):

<class ‘hou.Node’> ( which is the scene level or the world level …not sure if I should call this like that… )

Now if I try something like this:

cwd.type ( based on the hou.Node.type method )

I get this result:

<bound method Node.type of <hou.Node at /obj>>

Can you explain me the result?
tky
User Avatar
Member
119 posts
Joined:
Offline
That's python telling you that ‘type’ is a function.

print cwd.type().name() would tell you the actual type.

Please someone correct anything that's not right here because I'm learning this stuff too.

Added to grahamt's example:


import toolutils

cwd = toolutils.sceneViewer().pwd()
selected =

for node in selected:
print node.type().name()
User Avatar
Member
82 posts
Joined: Oct. 2007
Offline
No correction so this should be right Tks photex
  • Quick Links