Notifications
Clear all

[Closed] Use Environment Background

Hello,
I’m looking for a way to turn on/off “Use Environment Background” chekbox using max script in Viewport Background dialog

I searched in maxscript help:banghead: but didn’t found how to make this

9 Replies
 lo1

useEnvironmentMap = off

2 Replies
(@denist)
Joined: 11 months ago

Posts: 0

it’s different.
as i understand it’s about [b][i]max background display toggle – Use Environment Background

[/i][/b]i have no idea how to use this flag. it might be obsolete.

(@denist)
Joined: 11 months ago

Posts: 0

it’s not obsolete. i’ve just never used it. i might be obsolete

 lo1

oh sorry, I misread.
I think UI Accessor is your only friend in this case.

 lo1
struct setEnvBgStr
(
	fn setCheckBoxState hwnd state = 
	(	
		local BN_CLICKED =0
		local BM_SETCHECK = 241
		local WM_COMMAND = 273
		
		local parent = UIAccessor.getParentWindow hwnd
		local id = UIAccessor.getWindowResourceID hwnd
		
		windows.sendMessage hwnd BM_SETCHECK (if state then 1 else 0) 0
		windows.sendMessage parent WM_COMMAND ((bit.shift BN_CLICKED 16) + id) hwnd	
		ok
	),

	fn getButtonHwnd hnd =
	(
		for i in (windows.getChildrenHWND hnd) where matchPattern i[5] pattern:"use env*" do return i[1]
		0
	),
	
	fn UseEnvBGOn = 
	(
		local hnd = dialogmonitorops.getwindowhandle()
		setEnvBgStr.setCheckBoxState (setEnvBgStr.getButtonHwnd hnd) on
		uiaccessor.pressButtonByName hnd "OK"
		true
	),

	fn UseEnvBGOff = 
	(
		local hnd = dialogmonitorops.getwindowhandle()
		setEnvBgStr.setCheckBoxState (setEnvBgStr.getButtonHwnd hnd) off
		uiaccessor.pressButtonByName hnd "OK"
		true
	),

	fn useEnvBG state =
	(
		if environmentMap!=undefined do
		(
			DialogMonitorOPS.unRegisterNotification id:#useEnvBG
			DialogMonitorOPS.enabled = off
			DialogMonitorOPS.enabled = on	
			DialogMonitorOPS.RegisterNotification (if state then setEnvBgStr.useEnvBGOn else setEnvBgStr.useEnvBgOff) id:#useEnvBG
			max background
			DialogMonitorOPS.unRegisterNotification id:#useEnvBG
			DialogMonitorOPS.enabled = off
		)
	)
)

setEnvBgStr.useEnvBG on
--setEnvBgStr.useEnvBG off 

well this was fun

This is perfect, thanks a lot I don’t know how you did it but my humblest appreciation Lo

 lo1

sure, glad to help.

 lo1

A word of warning:
When using DialogMonitorOPS, under some versions of max/windows, 3dsmax will give an error message when you close it (It will not crash unexpectedly or anything, but when you close it normally, it will give a message as though it had crashed).

Thanks Lo is good to know