vex: creating ordered menu from array values

   2365   3   0
User Avatar
Member
1004 posts
Joined: April 2017
Offline
Hi!

I have a detail string array with values: A, B, C, D. I would like to use a detail wrangle where I can use a dropdown menu to choose what value I want and ouput into my s@chosenLetter.

I already know how to use an integer to chose a value in the string array.

int chosenIndex = chi("chosen");
s@chosenLetter = s[chosenIndex]@myArray;

The part I'd like to understand is how to populate the menu (ordered menu?) with the values of my array so 0=A, 1=B, 2=C. etc. Can this be done automatically?

-Olivier
Edited by olivierth - Feb. 23, 2020 13:47:47
User Avatar
Member
471 posts
Joined: July 2005
Offline
Hi,


you can use Python under the menu tab of the ordered menu
('s' is the name of the string array), but you have to convert the ordered menu to string (or the indices are -1).


import numpy as np

node = hou.pwd()
geo = node.geometry()

W = geo.stringListAttribValue('s')
n = len(W)

L = map(lambda x:[str(x), W[x]], range(0,n))
Q = np.array(L).flatten()
return Q

Attachments:
py_ordered_menu.hipnc (87.0 KB)

User Avatar
Member
8506 posts
Joined: July 2007
Offline
olivierth
I already know how to use an integer to chose a value in the string array.
int chosenIndex = chi("chosen");
s@chosenLetter = s[chosenIndex]@myArray;

I guess you meant:
int chosenIndex = chi("chosen");
s@chosenLetter = s[]@myArray[chosenIndex];
Edited by tamte - Feb. 23, 2020 17:35:19
Tomas Slancik
FX Supervisor
Method Studios, NY
User Avatar
Member
1004 posts
Joined: April 2017
Offline
Aizatulin: Ah! I didn't think I needed to use python for this. I'll try it out. Thanks!

tamte: oops… Thanks!
  • Quick Links