ScriptSpot

Forum topic · General Scripting

Array for going through checkboxes (Newby question)

By Maarten · 2016-01-22

Description

Hi all,

I am trying to get a simple piece of code to work but it gives me an error

--Unknown property: "Checked" in "chk0"

I want the script to add the number of each checked checkbox to an empty array (see line 28)

I think my issue is that chk0 is a string in my script and thus I get the error.
This should be a simple error on my side but I am not sure how to fix it.



rollout Test "Test" width:300 height:803  ( --start of Rollout Exporter

	--INCLUDE USER INTERFACE HERE	
	button btn_test "Test" pos:[18,14] width:116 height:60 toolTip:"If 'overwrite name' option is not used; obj name of currently selected obj will be used"
	groupBox grp1 "Export Options" pos:[150,7] width:151 height:439
	checkbox chk0 ".max                         0" pos:[160,25]
	checkbox chk1 ".3DS                         1" pos:[160,50] width:137 height:23         
checked:true
	checkbox chk2 ".AI                            2" pos:[160,70] width:137 height:23
	checkbox chk3 ".DWG                        3" pos:[160,90] width:137 height:23 
	checkbox chk4 ".DXF                         4" pos:[160,110] width:137 height:23 checked:true
	checkbox chk5 ".STL                          5" pos:[160,130] width:137 height:23
	checkbox chk6 ".SAT                         6" pos:[160,150] width:137 height:23
	checkbox chk7 ".PxProj / .NXB          7" pos:[160,170] width:137 height:23
	checkbox chk8 ".FBX                         8" pos:[160,190] width:137 height:23 checked:true
	checkbox chk9 ".DAE                         9" pos:[160,210] width:137 height:23
	checkbox chk10 ".IGS                         10" pos:[160,230] width:137 height:23
	checkbox chk11 ".WIRE                     11" pos:[160,250] width:137 height:23
	checkbox chk12 ".W3D                      12" pos:[160,270] width:137 height:23
	checkbox chk13 ".FLT                        13" pos:[160,290] width:137 height:23
	checkbox chk14 ".OBJ                       14" pos:[160,310] width:137 height:23 checked:true
	checkbox chk15 ".HTR                       15" pos:[160,330] width:137 height:23
	checkbox chk16 ".ASE                       16" pos:[160,350] width:137 height:23
	checkbox chk17 ".WRL                      17" pos:[160,370] width:137 height:23
	checkbox chk18 ".DWF                   18" pos:[160,390] width:137 height:23

--BUTTON
on btn_Test pressed do(
Array_chkboxes=#() --Empty array

for i in 0 to 18 do(
	
	x = "chk" + i as string
	print x
	
	if x.checked == true then(
	append x array_chkboxes
	)

)
print array_chkboxes
)
)

createdialog Test

Thank you :)

-Maarten

Attachments
Comments (1)

Swordslayer · 2016-01-23

You're trying to access a parameter of a string value (i.e. of the name of the checkbox control), not the control itself. Also note that there's rollout.controls array that will give you the list of all the controls of the rollout. Something like this should get you started (untested but in the worst case you'll have something to dissect and analyze):

 

Array_chkboxes = for c in test.controls where isKindOf c CheckBoxControl and c.checked collect c.name