[SOLVED] How to create a string-based switch? Or a [string:int] selector on a node?

   2911   3   1
User Avatar
Member
39 posts
Joined: Dec. 2018
Offline
Hi everbody,

say I have three shapes, a cylinder, a box and a sphere, all piped into a switch node. Changing the integer parameter on the switch changes the visible shape - nothing new here.

Now, I'd like to have a menu on a separate node, with the strings “cylinder”, “box”, “sphere”. When I choose “box” for example, the integer 1 is sent to the switch and the box is displayed.

I tried to achieve this with an Ordered Menu parameter and a Key-Value parameter, but I don't quite understand how they work. I.e. the OM parameter works only if it shows the integer, not the strings, defying the purpose. And I don't quite understand where to add the key-value pairs in the KV parameter and how to select one of them specifically.

I feel I'm missing something very simple: can somebody enlighten me?

Kind regards,

Manu
Edited by manu3d - July 23, 2019 10:18:41
User Avatar
Member
900 posts
Joined: Feb. 2016
Offline
This is how I understand the Menu:

The tokens column of an ordered menu is the one being evaluated and returned. The Label column doesn't really matter.
With an ordered menu you could either have as tokens strings or actual numbers. Houdini will allow you to do that, but note the following:

  1. If you have strings as tokens, no matter how you check the toggle ‘use menu item Token as Value’, the returned token value will be always the index of the selected menu item. (0,1,2,etc)
  2. If you have numbers as tokens like (64, 128, 256), those numbers will be returned only if you check the toggle ‘use menu item Token as Value’, otherwise again only the token item index will be returned (0, 1, 2, etc). *Update: It seems that you can't use floats as tokens*
  3. If you want to have returned a String instead of a number (like the noise menu of the mountain sop), you should drop a String parameter and then check the toggle ‘use menu’.
  4. Similarly you can have a menu also starting from an integer paramater, but as far as I see it, it's no different than dropping directly an ‘ordered menu’ parameter

Also, note that after you apply your new modifications to a menu, you might see the copied pasted references from your menu NOT updated with the new values. This seems a bug to me, anyway if you see something like this happening, try to ‘initialize’ your freshly modified menu by using it once: select another item of the menu.


Regarding your specific need:
Just create an ordered menu, with UNCHECKED the toggle ‘use menu item Token as Value’. Put whatever you want as token value (but for simplicity you can put the item index), and type the labels accordingly to the order of the objects that you feed into the switch.
Then copy paste the reference of the menu parm onto the switch node
Edited by Andr - July 23, 2019 12:37:53
User Avatar
Member
39 posts
Joined: Dec. 2018
Offline
Dear andr, whoa!

Thank you for your reply and especially for providing so many useful details on how it all works. I searched/googled for a while to find this kind of information. I couldn't even find the page (or paragraph) specific to the Ordered Menu parameter, only generic parameter related pages. Did you find a specific help page about this or is this result of trial and error?

In any case your solution does what I need. Thank you again!

Kind regards,

Manu
User Avatar
Member
900 posts
Joined: Feb. 2016
Offline
Hi Manu,
it was trial and error and wasted a bit of time on it, especially on that bug I mentioned.
So I'm happy to avoid ppl to waste as much time.

Anyway here I see some similar information, on menu-tab section:
https://www.sidefx.com/docs/houdini/ref/windows/edit_parameter_interface.html#parameter-descriptionhere [www.sidefx.com]
But you are right, if you were searching for ordered menu, it's not an easy find.


One thing, I was wrong about using float values as tokens. You can't actually use them, it seems.
but still you could use integers in their place: example, 314 instead of 3.14 if you need PI as token

cheers
  • Quick Links