Notifications
Clear all

[Closed] read selection from array in multiple dropdownlists

I’ve got 2 dropdown lists and list 1 will populate list 2 depending on the selection made.

I need to create an output path from the combined selections but I can’t figure out how to read the selection from the second list due to the array

The code I am using is;

array_1= #()
	array_1[1] = "item 1"
	array_1[2] = "item 2"
	array_1[3] = "item 3"

array_2= #()
	array_2[1] = "item 2-1"
	array_2[2] = "item 2-2"
	array_2[3] = "item 2-3"

try (destroyDialog Asset_Rollout) catch()
rollout Asset_Rollout “Asset” width:400 height:300
(

dropdownlist _dd1 “list_1” width:290 pos:[38,50] items:array_1

dropdownlist _dd2 “” items:blank width:300 pos:[38,100] visible:on
dropdownlist _dd3 “” items:array_2 width:300 pos:[25,100] visible:off
dropdownlist _dd4 “” items:array_2 width:300 pos:[25,100] visible:off

local rolls = #(
#(_dd2),
#(_dd3),
#(_dd4)
)

on _dd1 selected sel do
(
for k=1 to rolls.count do for c in rolls[k] do c.visible = (k == sel)
)

AssetMaxFileOut = _dd1.selected + @”/” + rolls.selected + “.max” –not working due to rolls.selected

	 print AssetMaxFileOut
 )		 

createdialog Asset_Rollout

How can I get the selection from the 2nd dropdownlist and output that selection?
Ive commented out the last two lines that don’t work due to rolls.selected

Thank you for any help

2 Replies

you could use a function to get the current visible rollout in the rolls array
something like:

fn getVisibleItem rolls =
(
	for roll in rolls do (
		for item in roll do (
			if item.visible then return item
		)
	)
	undefined
)

or you could save a reference to the current visible drop down from the event handler for _dd1

but I think the cleanest way to go here is to have only one drop down list for the 2nd list and switch the items. something like this:

(
	try (destroyDialog Asset_Rollout) catch()	
	rollout Asset_Rollout "Asset"
	(
		local array_1 = #("item 1", "item 2", "item 3")

		local array_2 = #("item 1-1", "item 1-2", "item 1-3")
		local array_3 = #("item 2-1", "item 2-2", "item 2-3")
		local array_4 = #("item 3-1", "item 3-2", "item 3-3")
		
		local arrays = #(array_2, array_3, array_4)
		
		dropdownlist _dd1 "list_1" items:array_1
		dropdownlist _dd2 "" items:array_2

		on _dd1 selected arg do
		(
			_dd2.items = arrays[arg]
		)
		
		on _dd2 selected arg do
		(
			local AssetMaxFileOut = _dd1.selected + "\\" + _dd2.selected + ".max"
			print AssetMaxFileOut
		)
	)
	
	CreateDialog Asset_Rollout
)

Matan, the second option you gave is exactly what I was trying to achieve. Thank You for your help.