Home Technical Talk

Maxscript #Noprompt loop trouble

polycounter lvl 15
Offline / Send Message
leslievdb polycounter lvl 15
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

  • LoTekK
    Options
    Offline / Send Message
    LoTekK polycounter lvl 17
    Max can be a bit retarded about showing dialogs, but you can get rid of the dialog with a bit of DialogMonitorOps hackery.
    DialogMonitorOps.RegisterNotification confirmObjImport id:#pressObjOK
    yourfunction here
    DialogMonitorOps.unRegisterNotification id:#pressObjOK
    
    function confirmObjImport = (
    	local hwnd = dialogMonitorOps.getWindowHandle()
    	if (uiAccessor.getWindowText hwnd == "[dialog window title here]") then (
    		local children = windows.getChildrenHWND hwnd
    		UIAccessor.PressButtonByName hwnd "[button name here]"
    		forceCompleteRedraw()
    	)
    	return true
    )
    

    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!
  • leslievdb
    Options
    Offline / Send Message
    leslievdb polycounter lvl 15
    oh yeah tnx, i didn't really think of that option, such a shame maxscript is so buggy

    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
  • LoTekK
    Options
    Offline / Send Message
    LoTekK polycounter lvl 17
    I haven't done much with dotnet stuff, but would a while loop work instead of using the dotnet timer callback? Seems a bit hacky, but then again, to me, maxscript is hacky. :P
  • leslievdb
    Options
    Offline / Send Message
    leslievdb polycounter lvl 15
    oh this is just beautifull
    (
            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
  • leslievdb
    Options
    Offline / Send Message
    leslievdb polycounter lvl 15
    I found a crappy workaround for this problem

    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 " "
    
Sign In or Register to comment.