New hotkey: Display Nearest Node

   4214   11   1
User Avatar
Member
4515 posts
Joined: Feb. 2012
Offline
Not sure if anyone needs it but I wrote a shelf tool that sets the display/render flag to the nearest node to your cursor in the network editor. When you bind it to a hotkey, it boosts your productivity by 2% as you don't have to carefully focus on the display flag of nodes to set them Just hover around with your pen.

If there is a simpler way to get the current cursor position over the network editor, I would love to know. Here is the code:

import ctypes

MOUSEEVENTF_LEFTDOWN = 0x0002 # Left button down
MOUSEEVENTF_LEFTUP = 0x0004 # Left button up
MOUSEEVENTF_CLICK = MOUSEEVENTF_LEFTDOWN + MOUSEEVENTF_LEFTUP

selNodes = hou.selectedNodes ( )
networkEditor = hou.ui.paneTabOfType ( hou.paneTabType.NetworkEditor )
currentPath = networkEditor.pwd ( ).path ( )
context = networkEditor.pwd ( ).childTypeCategory ( )

ctypes.windll.user32.mouse_event ( MOUSEEVENTF_CLICK, 0, 0, 0, 0 )
ctypes.windll.user32.mouse_event ( MOUSEEVENTF_CLICK, 0, 0, 0, 0 )
pos = networkEditor.selectPosition ( None, -1, None, -1 )


nodes = hou.node ( currentPath ).children ( )
nearestNode = None
dist = 999999999.0

for node in nodes:
d = node.position ( ).distanceTo ( pos )
if d < dist:
nearestNode = node
dist = d

if nearestNode:
nearestNode.setDisplayFlag ( True )
nearestNode.setRenderFlag ( True )
nearestNode.setSelected ( True, clear_all_selected=True )



Enjoy
Senior FX TD @ Industrial Light & Magic
Get to the NEXT level in Houdini & VEX with Pragmatic VEX! [www.pragmatic-vfx.com]

youtube.com/@pragmaticvfx | patreon.com/animatrix | animatrix2k7.gumroad.com
User Avatar
Member
387 posts
Joined: Nov. 2008
Offline
Interesting hack, thanks.

networkEditor.cursorPosition()

Enjoy
User Avatar
Member
4515 posts
Joined: Feb. 2012
Offline
Thanks a lot, simplifies my code a lot Now I wonder why that is not documented?:
http://www.sidefx.com/docs/houdini14.0/hom/hou/NetworkEditor [sidefx.com]
Senior FX TD @ Industrial Light & Magic
Get to the NEXT level in Houdini & VEX with Pragmatic VEX! [www.pragmatic-vfx.com]

youtube.com/@pragmaticvfx | patreon.com/animatrix | animatrix2k7.gumroad.com
User Avatar
Member
678 posts
Joined: July 2005
Offline
pusat
… it boosts your productivity by 2%…

Err… thanks???
Edited by - April 28, 2015 22:41:19
User Avatar
Member
333 posts
Joined: Oct. 2012
Offline
kewl. thanks
User Avatar
Member
4515 posts
Joined: Feb. 2012
Offline
mantragora
pusat
… it boosts your productivity by 2%…

Err… thanks???

It's up to 7% now

New changes:
Simplified position checking (thanks to pezetko)
More accurate distance calculation
For Object level nodes, it dives inside the nearest node
If a node is already selected either manually or with this tool and it's called again near the same node, it dives inside. So press the same hotkey twice if you want to dive inside Attrib VOPSOP, Volume VOPSOP, etc.
For VOP nodes, it selects the nearest node

networkEditor = kwargs
currentPath = networkEditor.pwd ( ).path ( )
context = networkEditor.pwd ( ).childTypeCategory ( )
currentContext = context.name()
pos = networkEditor.cursorPosition ( )

nodes = hou.node ( currentPath ).children ( )
nearestNode = None
dist = 999999999.0
for node in nodes:
d = ( node.position ( ) + ( node.size ( ) * 0.5 ) ).distanceTo ( pos )
#print “{0} {1} {2}”.format(d, node.position(), node.name())
if d < dist:
nearestNode = node
dist = d

handled = False
if nearestNode:
if currentContext == ‘Object’:
networkEditor.cd ( nearestNode.path ( ) )

if currentContext == ‘Sop’:
if nearestNode.isDisplayFlagSet ( ):
networkEditor.cd ( nearestNode.path ( ) )
handled = True
else:
nearestNode.setDisplayFlag ( True )
nearestNode.setRenderFlag ( True )

if currentContext != ‘Object’ and not handled:
nearestNode.setSelected ( True, clear_all_selected=True )

Feedback is welcome as always
Edited by - April 30, 2015 16:02:50
Senior FX TD @ Industrial Light & Magic
Get to the NEXT level in Houdini & VEX with Pragmatic VEX! [www.pragmatic-vfx.com]

youtube.com/@pragmaticvfx | patreon.com/animatrix | animatrix2k7.gumroad.com
User Avatar
Member
538 posts
Joined: Dec. 2006
Offline
Very nice!!!
https://gumroad.com/alexeyvanzhula [gumroad.com]
User Avatar
Member
4515 posts
Joined: Feb. 2012
Offline
Thanks mate
Senior FX TD @ Industrial Light & Magic
Get to the NEXT level in Houdini & VEX with Pragmatic VEX! [www.pragmatic-vfx.com]

youtube.com/@pragmaticvfx | patreon.com/animatrix | animatrix2k7.gumroad.com
User Avatar
Member
538 posts
Joined: Dec. 2006
Offline
I think most of users will assign it to Network Pane Hotkey, so you can use kwargs instead of paneTabOfType.
Maybe it will be 0.0000000000000000001% faster
https://gumroad.com/alexeyvanzhula [gumroad.com]
User Avatar
Member
4515 posts
Joined: Feb. 2012
Offline
Thanks that's a good point Changed the code to reflect that.
Senior FX TD @ Industrial Light & Magic
Get to the NEXT level in Houdini & VEX with Pragmatic VEX! [www.pragmatic-vfx.com]

youtube.com/@pragmaticvfx | patreon.com/animatrix | animatrix2k7.gumroad.com
User Avatar
Member
691 posts
Joined: June 2006
Offline
Very Nice!!
Feel The Knowledge, Kiss The Goat!!!
http://www.linkedin.com/in/alejandroecheverry [linkedin.com]
http://vimeo.com/lordpazuzu/videos [vimeo.com]
User Avatar
Member
4515 posts
Joined: Feb. 2012
Offline
Thanks It would be awesome if I could conditionally assign it to wacom pen. I never use the right click menu on the network editor outside the nodes. It would be nice if this could be configured so if you right click on the empty area of the network editor, it would invoke this hotkey.
Senior FX TD @ Industrial Light & Magic
Get to the NEXT level in Houdini & VEX with Pragmatic VEX! [www.pragmatic-vfx.com]

youtube.com/@pragmaticvfx | patreon.com/animatrix | animatrix2k7.gumroad.com
  • Quick Links