ScriptSpot

Forum topic · General Scripting

validate the dialog box automatically

By JeremyA · 2018-04-18

Description

I want to create an archive for each .max. I want to validate the dialog box automatically when I save.
I found "UIAccessor.PressDefaultButton ()" but I can not use it because my "max file archive" is pausing.
How to solve the problem? Sorry I'm starting =)
Thx


clearlistener()

thePath = getSavePath()--get a path dialog to specify the path
if thePath != undefined do--if the user did not cancel
(
  theFiles = getFiles (thePath+"\\*.max") --collect all max files in the dir.
  for f in theFiles do-- go through all of them
  (
    loadMaxFile f--load the next file
 
-----------------------------------------------------------
-- MAKE SOME SCRIPTED CHANGES TO THE SCENE HERE...
-----------------------------------------------------------
	max file archive
	UIAccessor.PressDefaultButton ()
	
-- 	actionMan.executeAction 0 "40085"  -- File: Archive
	
--     saveMaxFile f --save the file back to disk
  )--end f loop
  resetMaxFile #noPrompt --at the end, you can reset
)--end if
Comments (8)

JeremyA · 2018-04-19

Actually, I've already looked at the documentation but it's not easy. I tested 2 method, but I have the same result. A window appears "Dialog Monitor" he asks me "Close the Dialog?" answer "Yes" or "No". Am I on the right track? I do not understand very well

Method 1


DialogMonitorOPS.Enabled = true

max file archive
uiAccessor.pressButtonByName hwnd "Save"

DialogMonitorOPS.Enabled = false

Method 2



clearlistener()

DialogMonitorOPS.unRegisterNotification id:#savecustom

-- my function for handeling the dialog
fn mf = (
	-- Get the window handle of the current dialog
        windowHandle = DialogMonitorOPS.GetWindowHandle()
        UIAccessor.PressDefaultButton()
	return true
)

DialogMonitorOPS.RegisterNotification mf id:#savecustom
DialogMonitorOPS.Enabled = true

max file archive

DialogMonitorOPS.unRegisterNotification id:#savecustom
DialogMonitorOPS.Enabled = false

.

jahman · 2018-04-19


DialogMonitorOPS.Enabled = false
DialogMonitorOPS.UnRegisterNotification id:#maxArchive

fn handleZIP = (
	
	local hwnd = DialogMonitorOPS.GetWindowHandle()
	
	if hwnd == undefined do return true
	
	local data = windows.getHWNDData hwnd
	
	if data[5] == "File Archive" do (
		
		
		for c in windows.getChildrenHWND data[1] do (
			
			format ">> %\n" c
			
			if c[4] == "Edit" do (
				
				format "- - - - - - - - - - - - - - - - - - -\n" 
				UIAccessor.SetWindowText c[1] "someFile.zip"			
				
				UIAccessor.PressButtonByName data[1] "&Save"
				if ::ForceArchiveOverwrite do UIAccessor.PressDefaultButton()
				
				DialogMonitorOPS.Enabled = false
				DialogMonitorOPS.UnRegisterNotification id:#maxArchive
				
			)
			
		)

		
	)
		
	true
	
)

global ForceArchiveOverwrite = true

DialogMonitorOPS.RegisterNotification handleZIP id:#maxArchive
DialogMonitorOPS.Enabled = true

max file archive

JeremyA · 2018-04-19

Thank you very much for your code. It works very well. I just removed this:


format "- - - - - - - - - - - - - - - - - - -\n" 
UIAccessor.SetWindowText c[1] "someFile.zip"

I needed to have the same name as the .max scene
Could you explain to me please? I would like to try to understand the reasoning.

Thanks again :)

Therefore, for my batch zip:


clearlistener()

-- print (windows.getChildrenHWND #max) -- scanner tout l'interface pour avoir le code des btns

thePath = getSavePath()--get a path dialog to specify the path
if thePath != undefined do--if the user did not cancel
(
  theFiles = getFiles (thePath+"\\*.max") --collect all max files in the dir.
  for f in theFiles do-- go through all of them
  (
    loadMaxFile f--load the next file
 
-----------------------------------------------------------
-- MAKE SOME SCRIPTED CHANGES TO THE SCENE HERE...
-----------------------------------------------------------

	  
	-----------------------------------------
	-- ZIP	START
	-----------------------------------------	  
	DialogMonitorOPS.Enabled = false
	DialogMonitorOPS.UnRegisterNotification id:#maxArchive
	 
	fn handleZIP = (
	 
		local hwnd = DialogMonitorOPS.GetWindowHandle()
	 
		if hwnd == undefined do return true
			
	 
		local data = windows.getHWNDData hwnd
	 
		if data[5] == "File Archive" do (
	 
	 
			for c in windows.getChildrenHWND data[1] do (
	 
				format ">> %\n" c
	 
				if c[4] == "Edit" do (
	 
					
	-- 				format "- - - - - - - - - - - - - - - - - - -\n" 
	-- 				UIAccessor.SetWindowText c[1] "someFile.zip"			
	 
					UIAccessor.PressButtonByName data[1] "&Save"
					if ::ForceArchiveOverwrite do UIAccessor.PressDefaultButton()
	 
					DialogMonitorOPS.Enabled = false
					DialogMonitorOPS.UnRegisterNotification id:#maxArchive
	 
				)
	 
			)
	 
	 
		)
	 
		true
	 
	)
	 
	global ForceArchiveOverwrite = true
	 
	DialogMonitorOPS.RegisterNotification handleZIP id:#maxArchive
	DialogMonitorOPS.Enabled = true
	 
	max file archive
	-----------------------------------------
	-- ZIP	END
	-----------------------------------------	 
	
	
--     saveMaxFile f --save the file back to disk
  )--end f loop
  resetMaxFile #noPrompt --at the end, you can reset
)--end if

.

jahman · 2018-04-19

just read the reference there's nothing complicated

JeremyA · 2018-04-19

Sorry, I badly expressed myself, I wanted you to explain your code, not "maxscript reference scene filename". File archive already use the scene name. That's good ;)

.

jahman · 2018-04-19

Well..

1. check if there's a window handle
2. get window data
3. check if window has appropriate title
4. iterate over window child controls
5. if child control is "Edit" then set archive filename and press Save
6. handle (or not) overwrite popup if directory already contains zip with such filename
7. unregister dialogmonitor

JeremyA · 2018-04-19

Thanks again

Swordslayer · 2018-04-18

Check the DialogMonitorOPS topic in maxscript reference, they're designed to catch the dialog and if it matches the criteria you set, you can then press the default button.