[Closed] Set DirectX Cache state through Maxscript?
Is there any way to change DirectX cache state and force a scene update through maxscript?
-Eric
The current problem I have is that changing the d3dgfx.ini settings isn’t passed along to the dialog, so that needs to be forced through as well some how.
-Eric
at least there’s a function for the triangle edges bit
Couldn’t spot a way to re-init the thing with what’s in the ini either (short of restarting max).
You could, in theory, go via all that uiaccessor stuff… set up a callback for tabbed dialogs if you want (dialogmonitor will pick it up as well), can use the tabbedDialog interface to change to the correct tab, then press the configure button, wait for the little config dialog, find the checkbox, check it, signal it having changed, press the OK button, close the tabbed dialog… fun, no? and that’ll still briefly flash those dialogs, so it won’t be seamless in your script.
Flashing is fine, just looking for a quick way to do it vs the numerous clicks it takes to do. nPower BREPs work best with DirectX Cache off, while everything else works better with it on. So I am looking for an easy way to enable/disable depending on what I am working with in the scene.
-Eric
welp, here’s the usual scaryCode, then.
global useCache = true -- switch this variable
global prefsDialog_hwnd = undefined
global WM_COMMAND = 0x111 -- Windows Message: Command
global BN_CLICKED = 0
global BM_SETCHECK = 241 -- checkbutton toggle message ID
fn checkDialog = (
local hwnd = dialogMonitorOps.getWindowHandle()
local dialogTitle = uiAccessor.getWindowText hwnd
if (dialogTitle == "Preference Settings") then (
prefsDialog_hwnd = hwnd
local dialogChildren = windows.getChildrenHWND hwnd
local btn_chooseDriver = undefined
for dialogChild in dialogChildren do (
if (dialogChild[5] == "Configure Driver...") then (
btn_chooseDriver = dialogChild
exit
)
)
local btn_chooseDriver_hwnd = btn_chooseDriver[1]
UIAccessor.pressButton btn_chooseDriver_hwnd
)
if (dialogTitle == "Configure Direct3D") then (
local dialogChildren = windows.getChildrenHWND hwnd
local chk_cache = undefined
for dialogChild in dialogChildren do (
if (dialogChild[5] == "Use Cached D3DXMeshes") then (
chk_cache = dialogChild
exit
)
)
local chk_cache_hwnd = chk_cache[1]
local chk_cache_id = UIAccessor.GetWindowResourceID chk_cache_hwnd
windows.sendMessage chk_cache_hwnd BM_SETCHECK (if (useCache) then ( 1 ) else ( 0 )) 0
windows.sendMessage hwnd WM_COMMAND ((bit.shift BN_CLICKED 16) + chk_cache_id) chk_cache_hwnd
UIAccessor.pressButtonByName hwnd "OK"
UIAccessor.pressButtonByName prefsDialog_hwnd "OK"
)
true
)
fn setUseCache state = (
useCache = state
dialogMonitorOps.enabled = true
dialogMonitorOps.interactive = false
dialogMonitorOps.unregisterNotification id:#setD3DCache
dialogMonitorOps.registerNotification checkDialog id:#setD3DCache
max file preferences
dialogMonitorOps.unregisterNotification id:#setD3DCache
dialogMonitorOps.enabled = false
)
-- ------------------------------------------------
-- example usage:
setUseCache false
-- and
setUseCache true
Basically what this does is what you would do with your mouse;
- invoke the preferences dialog
- press the button to open the driver config dialog
- (un)check the checkbox
- press OK to close the config dialog
- press OK to close the preferences dialog
All the rest of the code is just to make things act on the correct dialog, press the correct button, (un)check the right checkbox, etc.
I have no idea if it works or not; it should
Edit: button? checkbox.
Edit2: whoops – old #test ID; fixed and unregisterNotifications added.
hate to bump, but… did this work? It toggles fine here, but I can’t tell if it’s actually doing anything
Works great here in max 2009. Try throwing some high-res models at it and you will notice a difference :P.
Thanks for the help Richard.
-Eric
Hi Richard,
Looking at your code, how would I change the “checkDialog” function so that it ONLY tests the state of the checkbox and returns its current state, when I execute the “setUseCache” function (but without actually changing its state!)?
The UIAccessor is a bit confusing…!
Thanks,
Mike
almost idental, but by getting the state instead of setting it
global useCache -- will hold cache state
global prefsDialog_hwnd = undefined
global WM_COMMAND = 0x111 -- Windows Message: Command
global BM_GETCHECK = 240 -- checkbutton checked state message ID
fn checkDialog = (
local hwnd = dialogMonitorOps.getWindowHandle()
local dialogTitle = uiAccessor.getWindowText hwnd
if (dialogTitle == "Preference Settings") then (
prefsDialog_hwnd = hwnd
local dialogChildren = windows.getChildrenHWND hwnd
local btn_chooseDriver = undefined
for dialogChild in dialogChildren do (
if (dialogChild[5] == "Configure Driver...") then (
btn_chooseDriver = dialogChild
exit
)
)
local btn_chooseDriver_hwnd = btn_chooseDriver[1]
UIAccessor.pressButton btn_chooseDriver_hwnd
)
if (dialogTitle == "Configure Direct3D") then (
local dialogChildren = windows.getChildrenHWND hwnd
local chk_cache = undefined
for dialogChild in dialogChildren do (
if (dialogChild[5] == "Use Cached D3DXMeshes") then (
chk_cache = dialogChild
exit
)
)
local chk_cache_hwnd = chk_cache[1]
local chk_cache_id = UIAccessor.GetWindowResourceID chk_cache_hwnd
useCache = case (windows.sendMessage chk_cache_hwnd BM_GETCHECK 0 0) of (
0: false
1: true
0: #indeterminate
)
UIAccessor.pressButtonByName hwnd "OK"
UIAccessor.pressButtonByName prefsDialog_hwnd "OK"
)
true
)
fn getUseCache = (
useCache = undefined
dialogMonitorOps.enabled = true
dialogMonitorOps.interactive = false
dialogMonitorOps.unregisterNotification id:#setD3DCache
dialogMonitorOps.registerNotification checkDialog id:#setD3DCache
max file preferences
dialogMonitorOps.unregisterNotification id:#setD3DCache
dialogMonitorOps.enabled = false
useCache
)
-- example usage:
getUseCache()
( http://msdn.microsoft.com/en-us/library/bb775986(VS.85).aspx )