Notifications
Clear all

[Closed] Close dialog windows from maxscript

Hey guys, I’m glad to finally find a site that will help me with this maxscript problem.

I created a script that goes through all the subdirectories of a directory of my choosing, and converts .max files to another format (which we have a plugin that handles).

This file is a batch script, it goes through them all and converts them by itself.

However, if a max file is corrupt, or for whatever reason wont open, a dialog box prompt appears, and I have to press OK to continue the process.

My question is: Is there a way for maxscript to signal an OK or RETRY or etc to the dialog box that pops up after the error appears on screen?

Ive been trying to find a method, but it completely alludes me!

Thanks in advance!

  • Doron
20 Replies

Use the quiet mode when loading your max files to suppress errors or missing file dialogs.


   [left]loadmaxfile "apollo.max" quiet:true
   [/left]
    

Hope that’s what you’ve been looking for. Depends on the corruptness of the scenes xD

Thanks for the reply

I actually used Listeners and the UIAccessor and it did the trick.

But if this one line code works, it’s even better; ill give it a shot, thanks!

if you still get a dialog despite using silent:true, have a look at DialogMonitorOps and UIAccessor ; combine the two and you can easily close any dialog that my pop up or perform a specific function depending on the dialog.

Ok, well the one line trick didn’t work but my listeners are still good to go

Although it does what it has to, after the script is run, it says (in the error box in bottom left)

MAXScript DialogMonitor Exception: –Unable to convert: undefined to type: boolean <<

Not sure how to fix that?

Also, is there someway to log the exact error of each popup? I don’t think there’s a method in UIAccessor for that.

Thanks again!

You could try something like this…


  dialogMonitorOps.unRegisterNotification id:#test
  fn checkDialog = (
  	local hwnd = dialogMonitorOps.getWindowHandle()
  	if (hwnd == 0) then ( false )
  	else (
  		format "==================================================
"
  		format "%
" hwndText
  		local children = uiAccessor.getChildWindows hwnd
  		format "--------------------------------------------------
"
  		for child in children do (
  			format "%
" (uiAccessor.getWindowText child)
  		)
  		format "==================================================
"
  		uiAccessor.pressDefaultButton()
  		true
  	)
  )
  
  dialogMonitorOps.enabled = true
  dialogMonitorOps.interactive = false
  dialogMonitorOps.registerNotification checkDialog id:#test
  loadMaxFile "c:\	emp\\atextfile.txt" silent:true
  dialogMonitorOps.enabled = false
  

Edit: The error you got is probably due to the function you registered not returning a boolean value – it must always return true or false.

Hm, I’ll post what I have so far, and maybe I can get a better grip on this by you guys understanding where I’m at (but thanks for the code, im testing it as we speak)


MacroScript Moves category:"My Toolz" buttonText:"Moves"
(
rollout BatchRollout "Batch Export" width:341 height:158
(
	button btn15 "Source" pos:[13,13] width:96 height:24
	button btn17 "Export" pos:[10,110] width:323 height:35
	edittext edt11 "" pos:[121,13] width:206 height:24

	on btn15 pressed do
	(
	source_dir = getSavePath()
	edt11.text = (source_dir as string)
	)
	on btn17 pressed do
	(	
				
		fn getFilesRecurse dir =
		(
		
			global batch_file = createFile (edt11.text + "\\batchLog.txt")
			
			direc = GetDirectories (edt11.text + "\\*")
			for d in direc do
			(
				join direc (GetDirectories (d+ "\\*"))
			)

			append direc (edt11.text + "\\") -- Need to include the original top level directory

			maxfiles = #()
			for de in direc do join maxfiles (getFiles (de + "*.max"))
			
			------------------
			DialogMonitorOPS.unRegisterNotification id:#hello
			fn handleBox = 
			(
				local windowHandle = DialogMonitorOPS.GetWindowHandle()
				if (windowHandle != 0) then 
				(
					local children = UIAccessor.getChildWindows windowHandle
					for child in children do
					(
						format "%
" (UIAccessor.getWindowText child) to:batch_file
					)
					--local title = UIAccessor.GetWindowText WindowHandle
					--local error = UIAccessor.GetWindowDllDescription WindowHandle
					UIAccessor.PressDefaultButton()
					true
				)
			)
			-----------------
			
			for f in maxfiles do
			(
				DialogMonitorOPS.RegisterNotification handleBox id:#hello
				DialogMonitorOPS.Enabled = true
				
				if (loadMaxFile f == true) then
				(
				fname = getFilenameFile(f) + ".bin"
				exportFile fname #noprompt
				continue
				)
				else
				(
				format "%
" f to:batch_file
				)
			)		
		)
		getFilesRecurse edt11.text
		DialogMonitorOPS.unRegisterNotification id:#hello
		DialogMonitorOPS.Enabled = false
	) 
)
createDialog BatchRollout 341 158
)

This loops through a directory, finds all .max files, exports it to .bin (our plugin), and should skip bad files (as it does) and it logs the name of the file that was skipped.

But now I need to log the error that was associated with each file as well.
That’s where I’m at!

Haven’t run the code yet, but seems like that should be exactly what it’s doing in its current form?

silly me…

As I said, the function used by DialogMonitorOps -must- return true/false. You changed the code around so that if the hwnd -isn’t- zero, it continues and returns true. However, you don’t specify what it should return if it -is- zero

So make it…


if (windowHandle != 0) then
(
	local children = UIAccessor.getChildWindows windowHandle
	for child in children do
	(
		format "%
" (UIAccessor.getWindowText child) to:batch_file
	)
	--local title = UIAccessor.GetWindowText WindowHandle
	--local error = UIAccessor.GetWindowDllDescription WindowHandle
	UIAccessor.PressDefaultButton()
	true
)
else ( false )

Which is really the same code, but with its logic swapped.

That leaves the format to the batch_file, however. ‘batch_file’ doesn’t exist by the time that function is evaluated (which is -before- that section of code is run), so it will try to format to a void. You’ll have to make that external

Here’s just a quick adjustment…
Things to keep in mind are…

  • you have to make sure you close that batch text file when done (otherwise a handle remains open)
  • you should only open that file handle once, at the beginning of the batch
  • because the dialog pops open -before- loadMaxFile gets its result, the error has to be cached so that it can be written out -after- the filename is written out. Easier would be if you always wrote the filename out, and then note that that file did load OK; that way you have a record of -all- files parsed while you’re at it Then the cache of the error can be dropped as well.

 global batch_file
 global f_error
 
 fn handleBox = 
 (
 	local windowHandle = DialogMonitorOPS.GetWindowHandle()
 	if (windowHandle != 0) then 
 	(
 		local title = UIAccessor.GetWindowText WindowHandle
		format "	Window Title: %
" title to:f_error
 		format "	Window Body:
" to:f_error
 		local children = UIAccessor.getChildWindows windowHandle
 		for child in children do
 		(
 			format "		%
" (UIAccessor.getWindowText child) to:f_error
 		)
 		--local error = UIAccessor.GetWindowDllDescription WindowHandle
 		UIAccessor.PressDefaultButton()
 		true
 	)
 	else ( false )
 )
 
 rollout BatchRollout "Batch Export" width:341 height:158
 (
 	button btn15 "Source" pos:[13,13] width:96 height:24
 	button btn17 "Export" pos:[10,110] width:323 height:35
 	edittext edt11 "" pos:[121,13] width:206 height:24
 
 		fn getFilesRecurse dir =
 		(
 		
 			direc = GetDirectories (edt11.text + "\\*")
 			for d in direc do
 			(
 				join direc (GetDirectories (d+ "\\*"))
 			)
 
 			append direc (edt11.text + "\\") -- Need to include the original top level directory
 
 			maxfiles = #()
 			for de in direc do join maxfiles (getFiles (de + "*.max"))
 			
 			------------------
 			DialogMonitorOPS.unRegisterNotification id:#hello
 			-----------------
 			
 			for f in maxfiles do
 			(
 				DialogMonitorOPS.RegisterNotification handleBox id:#hello
 				DialogMonitorOPS.Enabled = true
 				
 				f_error = stringStream ""
 				if (loadMaxFile f == true) then
 				(
 				fname = getFilenameFile(f) + ".bin"
 				exportFile fname #noprompt
 				continue
 				)
 				else
 				(
 					format "%
" f to:batch_file
 					format "%
" (f_error as string) to:batch_file
 				)
 			)		
 		)
 
 	on btn15 pressed do
 	(
 	source_dir = getSavePath()
 	edt11.text = (source_dir as string)
 	)
 	on btn17 pressed do
 	(
 		batch_file = createFile (edt11.text + "\\batchLog.txt")
 		getFilesRecurse edt11.text
 		close batch_file
 		DialogMonitorOPS.unRegisterNotification id:#hello
 		DialogMonitorOPS.Enabled = false
 	) 
 )
 createDialog BatchRollout 341 158
 
Page 1 / 3