[Closed] Set DirectX Cache state through Maxscript?
-
getWindowResourceID() is your best bet. It’s unlikely to change at any time unless the dialog designer decides to re-order things (in which case any other methods, such as “detect the 2nd ‘Medium’” may fail just as well).
-
what does it crash with? i.e. the crash error text, any line highlighted, etc.
OK. The getWindowResourceID() function solved my identical named buttons problem. thanks
However, I’m still getting a failure with the basic code (at the bottom of this message) when I first run it…
No error message/info appears in the listener window.
Here’s what I am doing:
- Run the code below.
- Go File, import
- The file import dialog window appears for a nano-second and then disappears.
- Your “cbLogger” script (nice BTW) gives me the following info:
GE: #preImport @ 69205151
GE: #importFailed @ 69205245
RV: #redrawViews @ 69205261
I think my logic is wrong somewhere when initially searching for the second dialog window?
Strangely, if I comment out the following 2 lines of code at the bottom:
dialogMonitorOps.unRegisterNotification id:#setBREPImportDialogSettings
dialogMonitorOps.enabled = false
and then re-run the entire code form the editor, it works perfectly? I’m confused!
--**REMOVE Startup SCRIPTS**
callbacks.removescripts id:#nv_BREP_preImport
--
--**ADD Startup SCRIPTS**
callbacks.addscript #preImport "BREP_preImport_Dialog_Settings()" id:#nv_BREP_preImport
--
global firstDialogOpened
--
fn BREP_preImport_Dialog_Settings =
(
firstDialogOpened = false
dialogMonitorOps.enabled = true
dialogMonitorOps.interactive = false
dialogMonitorOps.unRegisterNotification id:#setBREPImportDialogSettings
dialogMonitorOps.registerNotification BREP_SET_Import_Dialog_Settings id:#setBREPImportDialogSettings
firstDialogOpened = false
)
--
fn BREP_SET_Import_Dialog_Settings =
(
local hwnd = dialogMonitorOps.getWindowHandle()
local DialogTitle = uiAccessor.getWindowText hwnd
if (hwnd != 0) do
(
if (DialogTitle == "Select File to Import") then ( firstDialogOpened = true )
if ((firstDialogOpened) AND (DialogTitle == "IGES Import")) then
(
format "% [%]
" "Working OK..! :-)" localtime
)
)
dialogMonitorOps.unRegisterNotification id:#setBREPImportDialogSettings
dialogMonitorOps.enabled = false
true
)
EDIT: Forgot to add “global firstDialogOpened” at the top of the code. I have also changed the second dialog to the standard Max IGES import plugin, which has a second dialog with the title: “IGES Import”. The code still doesn’t work…! This shows it has nothing to do with BREP causing a problem.
Mike,
What version of Power Translator are you running? What file type are you trying to import? I have run into cases in the past where the import dialog is only good per max session.
BTW, you may want to split this discussion into its own topic, since this is no longer about setting the DirectX Cache feature. Feel free to answer my questions there.
-Eric
This…
dialogMonitorOps.unRegisterNotification id:#setBREPImportDialogSettings
dialogMonitorOps.enabled = false
…should not go in the top level of the dialogMonitor callback. You should -only- set that when you’re done; and you’re not done after you detect the first dialog… the second dialog should still call the callBack a second time (but by then you’ve disabled it by the above code).
So the above code should at least go into the function that handles the actual BREP import dialog.
It should also go into, probably, a callback (looks like #importFailed gets triggered if you cancel an import… (headshaking implied here)) to detect the user cancelling the import in the file selection dialog (again, this is why I recommended making your own file import dialog function; gives you more control).
Thanks for the cbLogger props, btw – ’tis indeed quite useful to keep around… I just use the scripted access (cbLogger.start()/stop()) whenever I want to check what events get called for a sequence of events that I might trigger off of
Thanks Richard.
The code works now (testing for just the Max standard IGES import dialog) but ONLY after I have executed it twice?
The code below has lots of format messages to see exactly what is happening.
It seems to pop-up the first dialog, but has a hwnd of “0”, so fails. This then calls the importfailed callback which unregisters the dialogmonitorops till next time, you go to file, import. If I execute the code a second time, it works fine and continues to do so. Very strange. What have I missed?!! :curious:
--**REMOVE Startup SCRIPTS**
callbacks.removeScripts id:#nvBREPpreImport
callbacks.removeScripts id:#nvBREPfailedImport
callbacks.removeScripts id:#nvBREPpostImport
--
--**ADD Startup SCRIPTS**
callbacks.addscript #preImport "BREP_preImport_Dialog()" id:#nvBREPpreImport
callbacks.addscript #importFailed "BREP_failedImport_Dialog()" id:#nvBREPfailedImport
callbacks.addscript #postImport "BREP_postImport_Dialog()" id:#nvBREPpostImport
--
global firstDialogOpened
--
fn BREP_preImport_Dialog =
(
firstDialogOpened = false
dialogMonitorOps.enabled = true
dialogMonitorOps.interactive = false
dialogMonitorOps.unRegisterNotification id:#setBREPImportDialogSettings
dialogMonitorOps.registerNotification BREP_SET_Import_Dialog_Settings id:#setBREPImportDialogSettings
format "% [%]
" "Callback has been registered" localtime
firstDialogOpened = false
format "%% [%]
" "firstDialogOpened=" firstDialogOpened localtime
)
--
fn BREP_SET_Import_Dialog_Settings =
(
local hwnd = dialogMonitorOps.getWindowHandle()
format "%% [%]
" "hwnd=" (hwnd as string) localtime
local DialogTitle = uiAccessor.getWindowText hwnd
format "%% [%]
" "DialogTitle=" DialogTitle localtime
if (hwnd != 0) then
(
if (DialogTitle == "Select File to Import") then ( firstDialogOpened = true )
format "% [%]
" "Select File to Import Dialog Found" localtime
if ((firstDialogOpened) and (DialogTitle == "IGES Import")) then
(
format "% [%]
" "3dsMax IGES Import Dialog Found" localtime
dialogMonitorOps.unRegisterNotification id:#setBREPImportDialogSettings
format "% [%]
" "Callback has been unregistered" localtime
dialogMonitorOps.enabled = false
)
)
else
(format "%
" "HWND=0")
true
)
--
fn BREP_failedImport_Dialog =
(
dialogMonitorOps.unRegisterNotification id:#setBREPImportDialogSettings
dialogMonitorOps.enabled = false
format "% [%]
" "importFailed callback has been executed" localtime
)
--
fn BREP_postImport_Dialog =
(
dialogMonitorOps.unRegisterNotification id:#setBREPImportDialogSettings
dialogMonitorOps.enabled = false
format "% [%]
" "postImport callback has been executed" localtime
)
I think you’ve got a scope issue…
fn BREP_preImport_Dialog =
(
...
dialogMonitorOps.registerNotification BREP_SET_Import_Dialog_Settings id:#setBREPImportDialogSettings
...
)
However, the function ‘BREP_SET_Import_Dialog_Settings’ is defined -after- the function BREP_preImport_Dialog.
Try either switching them about, or add a ‘global BREP_SET_Import_Dialog_Settings’ near the top of your script