Chantaro Posted December 17, 2023 Posted December 17, 2023 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?
Solution argumentum Posted December 17, 2023 Solution Posted December 17, 2023 No idea but add a Sleep(50) above the MsgBox() and let me know it that did it. Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting.
Danp2 Posted December 17, 2023 Posted December 17, 2023 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. Latest Webdriver UDF Release Webdriver Wiki FAQs
ioa747 Posted December 18, 2023 Posted December 18, 2023 (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 expandcollapse popup#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 December 18, 2023 by ioa747 Correction I know that I know nothing
Chantaro Posted December 18, 2023 Author Posted December 18, 2023 @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
Danp2 Posted December 18, 2023 Posted December 18, 2023 I imagine that there is some overhead in calling UBound, but it may not be significant in the big picture. Latest Webdriver UDF Release Webdriver Wiki FAQs
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now