Notifications
Clear all

[Closed] button state in toolbar

Hi folks!

I got an idea on how to have more control of the state of objects they’re in, e.g. 5 boxes with $.backfacecull = on already set.
A button in my toolbar should tell me if backface culling is active on all those objects in my scene or not and should be displayed ‘pressed’ or respectively ‘released’.

How can I achieve this?

best regards,
toby

3 Replies
1 Reply
(@denist)
Joined: 1 year ago

Posts: 0

/* by denisT */
macroScript BackFace_Cull_Mode
buttonText:"BackFace"
category:"Custom" 
tooltip:"BackFace Cull Mode Control"
icon:#("SubObjectIcons",4)
(
	local state = off
	on isChecked do
	(
		state = off
		for n in selection while not state do state = n.backFaceCull
		state
	) 
	on isEnabled do (selection.count > 0)
	on execute do if selection.count > 0 do selection.backFaceCull = (state = not state)
)

Like this?

(
	rollout frmMain "Button States"
	(
		checkbutton chkStates "Backface Cull"
		
		on frmMain open do
		(
			bStates = for i in selection where i.backFaceCull == true collect i
			if bStates.count == selection.count then chkStates.state = true
		)
	)
	
	createDialog frmMain
)

And a better version, using nodeeventcallback, toggles the button while you select different objects, remember if you have a selection of 5 objects and one of them has backfacecull disabled the button will also be disabled. It will only be enabled if ALL objects selected have backfacecull on.

(
	rollout frmMain "Button States"
	(
		checkbutton chkStates "Backface Cull"
		
		local callbackItem
		
		fn checkStates =
		(
			if selection.count != 0 then
			(
				bStates = for i in selection where i.backFaceCull == true collect i
				if bStates.count == selection.count then chkStates.state = true else chkStates.state = false
			)
		)
		
		fn selCallback ev nd =
		(
			checkStates()
		)
		
		on frmMain open do
		(
			checkStates()
			callbackItem = NodeEventCallback mouseUp:true selectionchanged:selCallback
		)
		on frmMain close do
		(
			callbackItem = undefined
			gc light:true
		)
	)
	
	createDialog frmMain
)