Jump to content

Binding a callback on a SOP to a tilda press (~)? [EDIT:back-quote]

Recommended Posts

CORRECTION: I meant to bind a callback to the back-quote '`' key- not tilda!


I am trying to setup an HDA that uses a selection pattern for points, similar to the native group SOP. I am storing the selected points as a pattern in a string field (same as the group SOP). And I'd like to implement the ability for the user to use back-quote '`' to restart selecting. So when back-quote is pressed I want to run a callback to read the pattern, and switch into point selection mode with the points selected. The only thing I can't figure out is how to bind a callback to that event of pressing back-quote...

Edited by cruiserandmax

Share this post

Link to post
Share on other sites

not sure about `, but since 14 there is new (less confusing way) to re-select geometry


you can notice that many nodes have little arrow icon on the right side of the group field

that's an action button that can be used to execute any python script, and in case of those group fields it's being used to re-select geometry


you can add Action Button to any parm, just by editing parameter interface and type script to Action Button tab

for your needs it may look like this:

import soputils
kwargs['geometrytype'] = hou.geometryType.Points
kwargs['inputindex'] = 0
Edited by anim

Share this post

Link to post
Share on other sites


I am trying something similar but don't know much about python. 

I have created a digital asset which contains group sop. 'pattern' parameter on this group node I have promoted to ui of digital asset. What I want is whenever this digital asset is laid down user should be able to select polygons in the scene viewport and selected polygons should get added in the pattern parameter on digital asset so it creates polygon group out of that selection and digital asset works only on these polygon. Further user should be able to re select the polygons if user wishes so.

Upon searching I came across similar questions but could not implement the solutions provided . It seems I have to use python / kwargs / callback script but have no clue how to use it.

Following is my feeble attempt. I have added this code in script section of the digital asset. 

Is there any tutorial available on kwargs / callback script ?

import toolutils
viewer = toolutils.sceneViewer()
selection = viewer.selectGeometry()
list = selection.mergedSelectionString()
//print list
//import hou
//node = kwargs['node']
//grpnode = node.path()+"./group1"
//b = grpnode.parm("pattern")
//print grpnode
//print b



Share this post

Link to post
Share on other sites

Thanks for the suggestions. So far I am able to add something like the following to a PreFirstCreate script on my HDA:


kwargs['type'].addSelector(name="foo", selector_type="points", prompt="sel points to foo on and hit ENTER")


Then if I create and instance of the node, connect some geometry with points to it's input, then re-enter selection mode (by hitting back quote `)- I can select points, hit ENTER, and then the point pattern is correctly transferred into a string parameter named 'group'.


However if I try and select some points in the 3D viewer on some geometry BEFORE my node is created, then hit TAB and pick my HDA name and press ENTER, I get the error:


'NoneType' object has no attribute 'set'


Any ideas on how to set it up so I can select points, then TAB-create my node and have the group field automatically populate?

Share this post

Link to post
Share on other sites

Sorry for the delay.. the error is:


 Traceback (most recent call last):

  File "sop_test", line 3, in <module>
  File "/usr/houdini/hfs14.0.291/houdini/python2.6libs/toolutils.py", line 926, in new_func
    return function(*args, **kwargs)
  File "/usr/houdini/hfs14.0.291/houdini/python2.6libs/soptoolutils.py", line 661, in genericTool
    exact_node_type = exact_node_type)
  File "/usr/hfs14.0.291/houdini/python2.6libs/soptoolutils.py", line 536, in genericSopNodeFilterTool
  File "/usr/houdini/hfs14.0.291/houdini/python2.6libs/soptoolutils.py", line 261, in initNewSopFilterNode
    setGroupParmsOnSopNode(newnode, selector, selection)
  File "/usr/houdini/hfs14.0.291/houdini/python2.6libs/soptoolutils.py", line 178, in setGroupParmsOnSopNode
AttributeError: 'NoneType' object has no attribute 'set'

Share this post

Link to post
Share on other sites

If anyone could provide an example of the correct way to use a selector on an otl to automatically populate the group field I would really appreciate it!

Share this post

Link to post
Share on other sites

Holy cow you got it- thanks, edward! It's funny I've been staring at those docs ever since I began trying to do this and it just didn't dawn on me to even try creating an attribute named grouptype since I was setting the Selector type to "points" which does not allow it to use different geometry types. But I guess that are just needs to still be there to abode reprint in creation mode. It's weird because without that attr the selector still functions to populate the group field- you just need to lay down and connect the nose first before going into selection mode.

Great suggestion!!

Share this post

Link to post
Share on other sites

You might be able to avoid it with group_type_parm_name="" (ie. the empty string).

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now