How to get token (not index) value from a ordered menu parm?

   861   9   0
User Avatar
Member
609 posts
Joined: 8月 2019
Offline
When we use ch() to access an ordered menu parameter's value, it returns the index (0, 1, 2...) not the token (prim, point...). Which is troublesome in some cases.

For example, I have this setup:



I try to refer Group SOP's group type from Attribute Mirror SOP's group type. However, it doesn't work as expected:





Because 'Primitives' is at index 0 for Group SOP's menu, while 'Vertices' is at the index 0 for Attribute Mirror's menu, when I select Primitives, Attribute Mirror's menu changes to Vertices.

Is it possible to access the token ('prim') so it can reliably read the correct value without depending on the specific order of menu items?

Attachments:
ordered_menu_token.hiplc (100.3 KB)
Screenshot 2025-02-18 223240.jpg (19.5 KB)
Screenshot 2025-02-18 223518.jpg (34.6 KB)
Screenshot 2025-02-18 223503.jpg (21.4 KB)

User Avatar
Member
79 posts
Joined: 8月 2017
Offline
I don't know hscript, but using a Python Expression you can use hou.parm("grouptype").evalAsString()

Attachments:
python-expression-example.png (22.7 KB)

User Avatar
Member
609 posts
Joined: 8月 2019
Offline
alexmajewski
I don't know hscript, but using a Python Expression you can use hou.parm("grouptype").evalAsString()
Image Not Found

Thank you for the answer. However, I just realized that I misunderstood the issue.

It's not the problem to get token value (in Python, evalAsString() as you said; in HScript, chs()). But the problem is that the ordered menu can't take an expression that returns string as its input.

So in my case, even Attribute Mirror can get the token value (via evalAsString() for example), I can't use the expression to set the menu value...
User Avatar
Member
609 posts
Joined: 8月 2019
Offline


As the image shows, even the expression correctly gets the token ("point"), the ordered menu doesn't accept this string value.

Attachments:
Screenshot 2025-02-18 225231.jpg (114.3 KB)

User Avatar
Member
79 posts
Joined: 8月 2017
Offline
I see what you're saying. These two menus have different tokens, that's why it doesn't work. "point" vs "points", "vertex" vs "vertices" and "primitive" vs "prims". The only thing these two menus have in common are their labels. So you would like to set them using a label, is that right?

Edited by alexmajewski - 2025年2月18日 10:23:00

Attachments:
comparison.png (42.7 KB)

User Avatar
Member
9124 posts
Joined: 7月 2007
Offline
Ordered Menu parms are integer, so you can't set them directly using string value, so:

1. for your menus, you can use String parameter with menu and then chs() will work

2. however for factory nodes especially HDK ones, where you can't change type from ordered menu or integer to string you can try something like this to figure out the index within current parm's menu
ref = hou.parm("../grouppromote1/totype1").evalAsString()
menu = hou.parm( hou.expandString("$CH") ).menuItems()
if ref not in menu:
    return 0 
return menu.index( ref )
Edited by tamte - 2025年2月18日 10:31:47

Attachments:
ordered_menu_token_fix.hipnc (99.3 KB)

Tomas Slancik
CG Supervisor
Framestore, NY
User Avatar
Member
243 posts
Joined: 5月 2017
Offline
hou.expandString("$CH") is interesting usually use pwd with parm name - thanks for sharing.
User Avatar
Member
9124 posts
Joined: 7月 2007
Offline
or
3. for menus that don't have compatible names you can also create custom mapping tailored to the specific parameter pair, so less generic, but that may not matter, in Hscript it would be something like:
atof( arg( "3 1 0", ch("../grouppromote1/totype1") ) )
Tomas Slancik
CG Supervisor
Framestore, NY
User Avatar
Member
9124 posts
Joined: 7月 2007
Offline
vikus
hou.expandString("$CH") is interesting usually use pwd with parm name - thanks for sharing.
you can also directly use $CH in hscript, which is also very handy for expressions that depend on parameter name
Tomas Slancik
CG Supervisor
Framestore, NY
User Avatar
Member
609 posts
Joined: 8月 2019
Offline
tamte
or
3. for menus that don't have compatible names you can also create custom mapping tailored to the specific parameter pair, so less generic, but that may not matter, in Hscript it would be something like:
atof( arg( "3 1 0", ch("../grouppromote1/totype1") ) )

Thank for all your answers. I eneded up using arg(). Surprisingly, Houdini seems to automatically convert string to int. It works even without atof().
  • Quick Links