Jump to content

ConsoleWrite not triggering before Msgbox


Go to solution Solved by argumentum,

Recommended Posts

Posted

Hello Everyone

Strange issue with a ConsoleWrite and MsgBox.

I have a script inside a While loop that goes something like this:

$projectfilepath = "insert/path/here"
$outputpath = "insert/path/here"
$finalframe = 174
$blenderpath = "insert/path/here"
$init = 0

ConsoleWrite(@HOUR & ":" & @MIN & ":" & @SEC & " Render Initiate" & @CRLF)

While 1

;Grab amount of files in output folder
$aFileList = _FileListToArray($outputpath,"*.png")
$nextframe = UBound($aFileList,1)

If $nextframe > $finalframe Then
    ConsoleWrite(@HOUR & ":" & @MIN & ":" & @SEC & " Render Finished" & @CRLF)
    MsgBox(0,"Finished","Render complete!")
    Exit
Else

    ;XYZ

EndIf

Sleep(5000); Check status at regular intervals

WEnd

When the project finishes rendering I get a MsgBox like expected, but for some reason it does not log the actual time it finished (on the ConsoleWrite) but rather when I clicked the MsgBox away.

Example

Anyone know why this happens?

Posted

Some of these may not be applicable to your situation, but here are a few other things you may want to revise --

  • The resulting array from _FileListToArray already contains the row count, so there shouldn't be a need to get UBound.
  • If possible, move the _FileListToArray outside of your While loop to avoid calling it repeatedly.
  • Instead of Exit, use ExitLoop. That way your script will continue beyond the While...WEnd.
Posted (edited)

If I understand correctly, the script simply checks in real time, the number of png files in the $outputpath folder,
and when the number of png files reaches $finalframe number,
then it notifies us that the Render process has finished

 

#include <File.au3>

$projectfilepath = "insert/path/here"
$outputpath = @ScriptDir & "\png1\" ;"insert/path/here"
$finalframe = 20
$blenderpath = "insert/path/here"
$init = 0

ConsoleWrite("- " & @HOUR & ":" & @MIN & ":" & @SEC & " Render Initiate" & @CRLF)

; *** Render Simulation ***
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; If the directory exists Then Remove it
If FileExists($outputpath) Then
    DirRemove($outputpath, $DIR_REMOVE)
EndIf
; and create New directory.
DirCreate($outputpath)
FileWrite($outputpath & "Fake_0.png", "1st fake png file")
ShellExecute($outputpath)
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

While 1
    $init += 1 ; *** Render Simulation ***
    ;Grab amount of files in output folder
    $aFileList = _FileListToArray($outputpath, "*.png")
    $nextframe = $aFileList[0]
    ;$nextframe = UBound($aFileList,1)
    ConsoleWrite("$nextframe=" & $nextframe & @CRLF)

    If $nextframe > $finalframe Then
        ConsoleWrite("- " & @HOUR & ":" & @MIN & ":" & @SEC & " Render Finished" & @CRLF)
        MsgBox(0, "Finished", "Render complete!")
        Exit
    Else
        FileWrite($outputpath & "Fake_" & $init & ".png", $init & "st fake png file") ; *** Render Simulation ***

        ;XYZ

    EndIf

    Sleep(100) ;5000 Check status at regular intervals

WEnd


I didn't notice anything unusual, first comes the Console Write, and then the MsgBox
I put  "- "  in front because otherwise it comes out colorful
ConsoleWrite("- " & @HOUR & ":" & @MIN & ":" & @SEC & " Render Finished" & @CRLF)

 

Edited by ioa747
Correction

I know that I know nothing

Posted

@argumentum

good old missing sleep solution seems to have done it 😅

@Danp2

true good catch, but is there any performance benefit to not using Ubound? It just so happens to return that number +1 already which helps for my case.

Unfortunately I need to call it every loop so it knows when to stop rendering by checking the amount of files in the folder, if you know another way I'd be happy to hear it.

Good call on the ExitLoop! It has been implemented :D

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...