HDA parm menu from script does not make any sense

   1451   2   1
User Avatar
Member
29 posts
Joined: May 2019
Offline
Hi, I found it very surprising how Ordered Menu parms work when fed by a script:
* The script must return a list where each odd element is the "token", and each even element is the label, e.g.
[token1, label1, token2, label2]
* If you call parm.eval(), the parameter *always* returns the int index of the selected item, even if you selected Use Token as Value.

So I need to perform extra lookups to find the token, even though the menu already had it at construction time.
Am I missing something? Or is it an incomplete implementation? (did this in H19 and 18.5)
The docs on this topic could be slightly better. Houdini scripting docs in general are superb, though!
Edited by monomon - Jan. 18, 2022 06:17:03
User Avatar
Staff
1448 posts
Joined: July 2005
Offline
Ordered Menu is essentially an integer parameter, whose value is an index of an item in that menu.

For menus in general (including an ordered menu), the token can be an arbitrary string, eg "foo", which does not have a numerical value. The "Use Token as Value" applies only to items whose token are numerical strings, eg "20". Eg, if your Ordered Menu is ("10", "Ten", "20", "Twenty") and has Use Token as Value toggled on, then parm.eval() will return integer value of 10 or 20, instead of an index 0 or 1.

If your tokens are non-numeric strings and you want want the token of the current menu item, you don't need "Use Token as Value", but rather you can just eval as string: parm.evalAsString().

Note, menus are not restricted only to Ordered Menu parameter. You can also have a menu on an Integer or on a String parameter. Eg, if you want string tokens, perhaps String parm with menu would be more suitable, since you could do parm.eval() and it would return the token value already.
Edited by rafal - Jan. 18, 2022 11:03:03
User Avatar
Member
29 posts
Joined: May 2019
Offline
Thank you very much, this makes sense, although it is somewhat confusing for a noob.
Indeed I need non-numeric strings as tokens, so will go with a String parameter with a menu.
  • Quick Links