Greying out Buttons

HI guys,

Most like a simple one for most of you but this is giving me a little bit of a headache.

I am trying to grey out (make unclickable) all my buttons in my rollout unless a condition (a box exists in the scene) is met but I cant get it to work. The "bounding box" button creates the box I want in the scene.

Should this be done through .enabled? Should I make the conditional check on the box a loop?

rollout threepointlight "3 Point Lighting"
 
(
 
	group "Bounding Box"
	(
 
    button But_info "Usage Guide" enabled:true
 
	button But_BoundingBox "Build Bounding Box" enabled:true
 
	button but_BoundingBoxToggle "Hide Bounding Box"	
 
    button but_BoundingBoxToggle2 "Show Bounding Box"	
 
	on But_BoundingBox pressed do 
		box height:150 width:150 length:150 pos:[0,0,0]
 
	on But_info pressed do messagebox "Place and Scale your object inside the Bounding box for this script to work"
 
	on but_BoundingBoxToggle pressed do hide $Box001
 
	on but_BoundingBoxToggle2 pressed do unhide $Box001
	)
 
 
 
	-- Lighting section
	group "Lights"
	(
	button but_buildlights1 "Build Omni one" enabled:false
 
	on but_buildlights1 pressed do 
	(	
		l1=MiAreaLightomni pos:[0,0,370]  $.castShadows = on  $.useGlobalShadowSettings = on $.multiplier = 0.70 $.rgb = color 178 178 178
   ) 
 
	button but_buildlights2 "Build Omni Two" enabled:false
 
	on but_buildlights2 pressed do 
		l2=MiAreaLightomni pos:[0,370,-150] intensity:1.0 shadows:false
 
	button but_buildlights3 "Build Omni Three" enabled:false
 
	on but_buildlights3 pressed do 
		l3=MiAreaLightomni pos:[370,45,150] intensity:1.0 shadows:true
 
	colorpicker L1_d "Light one Color"
	 color:[255,255,255] align:#right offset:[-20,0] fieldwidth: 20 enabled:false
 
 
	colorpicker L2_d "Light two Color"
	 color:[0,0,255] align:#right offset:[-20,0] fieldwidth: 20 enabled:false
 
	colorpicker l3_d "Light three Color" 
	 color:[255,0,0] align:#right  offset:[-20,0] fieldwidth: 20 enabled:false
 
	button But_AddSky "Add SkyLight" enabled:true
 
    spinner spn_skyIntense "Skylight Intensity" enabled:false
	range:[0.0,1.0,1.0]
		on But_AddSky pressed do 
		skylight pos:[0,0,0]
	)
 
 
 
)
createDialog threepointlight height:700 width:300

Sorry if this has been covered a lot, Ive just stepped into the world of maxscripting.

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Tim270's picture

Thanks for the responses

Thanks for the responses guys! They are very helpful.

fajar's picture

maybe you want it something

 

maybe you want it something like this==

Theres a box , all grayed btn is ungrayed

 

 theres no box , all back to grayed button 

 

fn doGraytheAllBut btn1 btn2 btn3 btn4 btn5 btn6=
(
	theBoxExistOrNot=for i in geometry where classOf i == box collect i
	if theBoxExistOrNot.count!=0 then
	(
		btn1.enabled=true
		btn2.enabled=true
		btn3.enabled=true
		btn4.enabled=true
		btn5.enabled=true
		btn6.enabled=true
	)
	else
	(
		btn1.enabled=false
		btn2.enabled=false
		btn3.enabled=false
		btn4.enabled=false
		btn5.enabled=false
		btn6.enabled=false
	)
)
 
 
rollout threepointlight "3 Point Lighting" width:162 height:234
(
	GroupBox grp01 "Bounding Box" pos:[2,1] width:156 height:82
	GroupBox grp02 "Lights" pos:[2,85] width:155 height:108
 
 
 
	button But_info "Usage Guide" pos:[7,167] width:145 height:21 enabled:true
	button But_BoundingBox "Build Bounding Box" pos:[5,16] width:149 height:19 enabled:true
	button but_BoundingBoxToggle "Hide Bounding Box" pos:[5,36] width:149 height:21 enabled:false		 
	button but_BoundingBoxToggle2 "Show Bounding Box" pos:[6,57] width:148 height:21 enabled:false	
	button but_buildlights1 "Build Omni one" pos:[7,101] width:122 height:21 enabled:false	
	button but_buildlights2 "Build Omni Two" pos:[7,123] width:122 height:21 enabled:false
	button but_buildlights3 "Build Omni Three" pos:[7,145] width:122 height:21 enabled:false
 
 
 
	-- Lighting secti
 
	on threepointlight open do 
	(
		callbacks.addScript #nodePostDelete "doGraytheAllBut threepointlight.But_info threepointlight.but_BoundingBoxToggle threepointlight.but_BoundingBoxToggle2 threepointlight.but_buildlights1 threepointlight.but_buildlights2 threepointlight.but_buildlights3" id:#CheckBBox
		callbacks.addScript #sceneNodeAdded "doGraytheAllBut threepointlight.But_info threepointlight.but_BoundingBoxToggle threepointlight.but_BoundingBoxToggle2 threepointlight.but_buildlights1 threepointlight.but_buildlights2 threepointlight.but_buildlights3" id:#CheckBBox
		--callbacks.addScript #selectionSetChanged "doGraytheAllBut threepointlight.But_info threepointlight.but_BoundingBoxToggle threepointlight.but_BoundingBoxToggle2 threepointlight.but_buildlights1 threepointlight.but_buildlights2 threepointlight.but_buildlights3" id:#CheckBBox
	)
 
	on threepointlight close do 
	(
		callbacks.removeScripts #nodePostDelete id:#CheckBBox
		callbacks.removeScripts #nodeCreated id:#CheckBBox
	)
 
 
	colorPicker L1_d "" pos:[129,102] width:22 height:20 enabled:false color:[255,255,255] fieldWidth:20
 
 
	colorPicker L2_d "" pos:[129,124] width:22 height:20 enabled:false color:[0,0,255] fieldWidth:20
 
	colorPicker l3_d "" pos:[129,146] width:22 height:20 enabled:false color:[255,0,0] fieldWidth:20
 
	button But_AddSky "Add SkyLight" pos:[7,210] width:73 height:21 enabled:true
 
	spinner spn_skyIntense "Val:" pos:[94,213] width:59 height:16 enabled:false range:[0,1,1]
	GroupBox grp5 "Lights" pos:[3,193] width:155 height:40
	on but_buildlights1 pressed do
	(	
		l1=MiAreaLightomni pos:[0,0,370]  $.castShadows = on  $.useGlobalShadowSettings = on $.multiplier = 0.70 $.rgb = color 178 178 178
	)
	on But_info pressed do
		messagebox "Place and Scale your object inside the Bounding box for this script to work"
	on But_BoundingBox pressed do
		(box height:150 width:150 length:150 pos:[0,0,0])
	on but_BoundingBoxToggle pressed do
		hide $Box001
	on but_BoundingBoxToggle2 pressed do
		unhide $Box001
	on but_buildlights2 pressed do
		l2=MiAreaLightomni pos:[0,370,-150] intensity:1.0 shadows:false
	on but_buildlights3 pressed do
		l3=MiAreaLightomni pos:[370,45,150] intensity:1.0 shadows:true
	on But_AddSky pressed do
		skylight pos:[0,0,0]
)
createDialog threepointlight width:162 height:234

Thats only raw basic script based on in scene objects if theres box object or not...you can change it tho for your personal purpose with another.You can add a name in box and later use it as identification of your unique object.

Anubis's picture

welcome to scripting then ;)

What I'll say is almost the same. You already answer ourself. The "enabled" property control that state:
myControlName.enabled = on/off (true/false)

Also, if I remember, rollout.controls was mapped array, that mean you can set some property on multiple controls at once (w/o for-loop):
myRolloutName.controls.enabled = true/false

Here is some sketch:

rollout roP3Ligth "3 Point Lighting"
(
	local objBBName = "SomeUniqueName101"
	local objBB = undefined
 
	button btnAddBBox "Make BBox" enabled:false
	checkButton cbtnBBoxVisTogle "Hide BBox"
	button btnAddLight1 "Add Omni one"
	-- ... and so on...
 
	on btnAddBBox pressed do
	(
		objBB = box name:objBBName \
		height:150 width:150 length:150
	)
 
	on cbtnBBoxVisTogle changed state do
	(objBB.isHidden = state)
 
	on roP3Ligth open do
	(
		objBB = getNodeByName objBBName
		if not IsValidNode objBB do
		(
			roP3Ligth.controls.enabled = off
			btnAddBBox.enabled = on
		)
	)
)

my recent MAXScripts RSS (archive here)

miauu's picture

You have to use .enabled to

You have to use .enabled to make your controls unclickable.
Also, it is better to give the unique name of the bounding box object, something like "Tim270BoundingBoxHelperObject", so you can easily get/check if this box exist in the scene or not.

When you want the script to make your controls unclickable?
If you need this when you run the script then you need to add this in your code:

on threepointlight open do
	(
		for o in geometry where (classof o == Box) and (o.name == "Box001") do
		(
			--	this will make all controls in the rollout unclickable.
			for ctrl in threepointlight.controls do ctrl.enabled = false
		)
	)

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.