hey guys, i'm trying to import a batch of obj files from a directory without having the script show any dialogs but for some reason it always shows the import dialog on the first import i want to do.
The following objs import without showing any dialog. Here is the code
(
theFiles = getFiles "C:\\path\\*.*"
for i = 1 to theFiles.count do
importFile theFiles[i] #noprompt using:Wavefront_Object
)
Does anyone know a workaround or a fix to this problem?
Replies
You'll need to get the name of the window (basically the title bar) and the name of the button (the text on the button itself). Note that both of those are case sensitive!
second problem is that the import dialog has a loadingbar, so i thought i'd add a timer that would set a bool to true after 2 seconds but this doesn't seem to work and yet again i can't really see why not
( local PressImport = false local TimerStarted = false local LoadbarTimer = dotNetObject "System.Windows.Forms.Timer" LoadbarTimer.Interval = 2000 -- wait 2 seconds fn Tick = (PressImport = true) dotnet.addEventHandler LoadbarTimer "tick" Tick fn confirmObjImport = ( local HWND = dialogMonitorOps.getWindowHandle() if ((uiAccessor.getWindowText HWND) == "OBJ Import Options" ) do ( print "Import Dialog Showing" TimerStarted = true ) if (TimerStarted == false) then ( LoadbarTimer.start() TimerStarted = true ) if PressImport then ( UIAccessor.PressButtonByName HWND "Import" print "pressed" forceCompleteRedraw() LoadbarTimer.stop() TimerStarted = false PressImport = false ) return true ) DialogMonitorOps.RegisterNotification confirmObjImport id:#pressObjOK DialogMonitorOPS.Enabled = true theFiles = getFiles "C:\\Users\\Leslie\\Desktop\\leslie\\20111207_Batchimports\\tiled\\*.*" for i = 1 to theFiles.count do importFile theFiles[i] #noprompt using:Wavefront_Object DialogMonitorOPS.Enabled = false )edit: crap it seems like the dialog box halts the script , so if i don't set a delay it will be fast enough to import but won't have enough time to load the loadbar resulting in a "Nothing found to import" message. And with the delay my function to press the button will not be called when the dialog is active
( waiting = 0 fn confirmObjImport = ( local HWND = dialogMonitorOps.getWindowHandle() while ((uiAccessor.getWindowText HWND) == "OBJ Import Options" ) do ( print "Import Dialog Showing" waiting +=1 if (waiting == 20000) then ( UIAccessor.PressButtonByName HWND "Import" print "pressed" forceCompleteRedraw() LoadbarTimer.stop() TimerStarted = false PressImport = false ) ) return true ) DialogMonitorOps.RegisterNotification confirmObjImport id:#pressObjOK DialogMonitorOPS.Enabled = true theFiles = getFiles "C:\\Users\\Leslie\\Desktop\\leslie\\20111207_Batchimports\\tiled\\*.*" for i = 1 to theFiles.count do importFile theFiles[i] #noprompt using:Wavefront_Object DialogMonitorOPS.Enabled = false )guess what, this holds the Import Dialog from loading the mesh so yet again it results in a "Nothing found to import" message. -_-'
I really need this to work since it would be running on a server
So what i'm doing now is running a vbs script that focuses my screen and sends a space command.
Maxscript
( vbran = false fn confirmObjImport = ( local HWND = dialogMonitorOps.getWindowHandle() if ((uiAccessor.getWindowText HWND) == "OBJ Import Options" ) do ( print "Import Dialog Showing" if vbran == false then ( ShellLaunch "C:\\Users\\Leslie\\Desktop\\leslie\\20111207_Batchimports\\PressSpace.vbs" "" vbran = true ) ) return true ) DialogMonitorOps.RegisterNotification confirmObjImport id:#pressObjOK DialogMonitorOPS.Enabled = true theFiles = getFiles "C:\\Users\\Leslie\\Desktop\\leslie\\20111207_Batchimports\\tiled\\*.*" for i = 1 to 5 do importFile theFiles[i] #noprompt using:Wavefront_Object DialogMonitorOPS.Enabled = false )PressSpace.vbs
Set WshShell = WScript.CreateObject("WScript.Shell") WshShell.AppActivate("Untitled - Autodesk 3ds Max 2011 x64") WScript.Sleep(2000) WshShell.SendKeys " "