UI.Timer crashes sketchup
-
Hi all,
I am currently trying to use the code to execute a script and then read the output looking for the string 100 and then exit gracefully. Currently when i run this script in the ruby console it runs the script just fine and reads the 100 string, the message box pops up and says the file is finished creating but the second i click ok sketchup crashes and the bug splat comes up. The puts statement reached end of program is never printed in the console making me think that it breaks in the timer. Any help would be appreciated as I have been stuck on this for quite some time.UI.openURL("file;///Users/jakecharland/Desktop/newfile.command") #define timer which function checkIfFinished() each 2 seconds @timerID = UI.start_timer(2,true) {checkIfFinished(tempPath)} puts "got to end of program" #file.delete(batch_file) #puts "deleted batch file" #file.delete(tempPath) return 0 end # checks the last line of the file for the string "done" def checkIfFinished(outfile) puts "checking file" # get last line in the file last = File.open("#{outfile}").each_line{ |s| puts s if(s == "100\n") UI.stop_timer(@timerID) calculationFinished() end } last.close() end def calculationFinished() UI.messagebox("Finshed creating output file") end
-
Timers can be buggy, especially when combined with UI.messagebox (or similar) they can run continuously without stopping. I also noticed that when you try to stop a one-time timer (just to be sure it is really stopped), it can crash the OSX version of SketchUp.
Does it work when you create a timer only for the next check? I use the following pattern:
def a_method # … checkIfFinished(tempPath) # … end # checks the last line of the file for the string "done" def check_if_finished(outfile) # … if(s == "100\n") calculation_finished() else UI.start_timer(2, false) { check_if_finished(tempPath) } end # … end def calculation_finished() UI.messagebox("Finshed creating output file") end
-
Thank you! that worked perfectly everything is running smoothly now.
Advertisement