Notifications
Clear all

[Closed] Loop to change checkbox status

Ok, newbie here and I am taking my first steps with maxscript and pythong.

In this particular case, I have a long list of checkboxes that I want to enable and disable using another checkbox. I was trying to simpligy this process but instead of having something like this

 _nck.checked = theState 
 _pck.checked = theState
 _zck.checked =  theState
 _ack.checked =  theState
 _n2ck.checked = theState
 _aock.checked =  theState
 _motionck.checked =  theState

so I thought that I could use an array

dataAllArray = #("_nck", "_pck", "_zck", "_ack", "_n2ck", "_aock", "_motionck")

and then on the main checkbox use a for loop to set all of those checkboxes on or off

on _dataALL changed theState do
	(
		
		for i = 1 to dataAllArray.count do
		(
			dataAllArray[i].enabled = theState
		)
	)

The problem is that this doesn’t work, and I am not seeing another solution due to my limited knowledge. Anything that I am missing and could be useful?

Thanks in advance for any help

2 Replies

it should be .checked I guess

btw you can set property to all items of collection at once, example:

try (destroydialog X ) catch ()
rollout X "" (

	checkbox a "a" checked:true
	checkbox b "b"
	checkbox c "c"
	checkbox d "d"
	
	local checkboxes = #(a,b,c,d)
	
	fn Solo cbox =
	(
		(for cb in checkboxes where cb != cbox collect cb).checked = false
	)
	
	on a changed state do Solo a
	on b changed state do Solo b
	on c changed state do Solo c
	on d changed state do Solo d

)
createDialog X pos:[100,100]

Thanks, Serejah for this.

Yes, it is supposed to be .checked

I am going to test it and post the results.