Auto create spare parms when VEX preset is selected

   1181   5   2
User Avatar
Member
475 posts
Joined: Aug. 2014
Offline
We can define our own VEX presets for various nodes using the VEXpressions.txtfile. Is it possible to tell Houdini to automatically create appropriate spare parameters when a preset that uses them is selected?

And ideally, in case another VEX preset is selected, is it possible to automatically remove unused spare parameters?
Edited by ajz3d - Oct. 30, 2023 18:15:17
User Avatar
Member
2042 posts
Joined: Sept. 2015
Offline
After setting up your code and parameters you want - saving as a preset will generate those parameters when you click to use it.
If you select another preset the node should automatically remove the current spare parameters to what was set up with the current preset you just selected.
In the alternative you could just select delete all spare parameters.
User Avatar
Member
143 posts
Joined: May 2017
Offline
The problem with the snippet menu is that you cannot take the callback for selecting - it seems that this is a houdini-internal. So to make it possible, you need to implement one.

Basically every time a snippet is selected from the menu, a temporary callback function runs over the wraglers snippet input looking for channels - similar to the action button for spare parameters, except that these have to be automatically removed/replaced when a new snippet preset is applied.

To achieve this you can customise the buildSnippetMenu() and createSpareParmsFromChCalls() functions in the vexpressionmenu.py module.

In the hip file below you will find the code. Simply (add) copy and paste the contents into your vexpressionmenu.py or expand your Houdini path or package. Then go to the type properties of your wrangler, select the VEXpression (snippet) parameter and switch to the menu tab. Replace the following code and apply:
import vexpressionmenu
node = kwargs['node']
snippetname = 'attribwrangle/snippet'
parmname = 'snippet'
return vexpressionmenu.custom_buildSnippetMenu(node, snippetname, parmname)

For debugging or in general I would recommend a HDA wrapper around the wrangle. So use it at your own risk!

Now, every time the snippet provides a channel, the corresponding parameters will be generated.
Edited by viklc - Nov. 1, 2023 06:12:04

Attachments:
Snippet_Menu_with_Spare_Parms.gif (152.9 KB)
Snippet_Menu_with_Spare_Parms.hip (70.8 KB)

User Avatar
Member
2042 posts
Joined: Sept. 2015
Offline
viklc
The problem with the snippet menu

snippet menu isn't the only thing available.
If you choose a snippet that also has references for parameters to be created, create those parameters, THEN create a Preset;
You can do away with all that python.

Afterwards - just select the Preset.
Also, if you don't want to have to delete the spare parameters manually, just set up a default preset that doesn't have spare parameters or snippets;
Just a matter of switching back and forth in the preset list(not snippet menu.) - Old parameters are removed automatically and new ones automatically created(if originally defined for the preset).
Edited by BabaJ - Oct. 31, 2023 13:21:09
User Avatar
Member
143 posts
Joined: May 2017
Offline
BabaJ
snippet menu isn't the only thing available.
Just create the module extesion of practice porpuses, since curntly digging into prameter templates 😊. But nice to know, thx.
Edited by viklc - Nov. 1, 2023 06:52:53
User Avatar
Member
475 posts
Joined: Aug. 2014
Offline
Many thanks for your input guys. Much appreciated.
It's funny that it didn't occur to me to use an operator preset instead of a VEX preset. The darkest place is indeed under the lantern.

I like @viklc's approach too. In fact my initial thought was to use some form of a callback script, but I wasn't sure where to start. Perhaps I should pay more attention to Python modules supplied with Houdini.
  • Quick Links