sketchucation logo sketchucation
    • Login
    ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info

    UI.Timer crashes sketchup

    Scheduled Pinned Locked Moved Newbie Forum
    sketchup
    3 Posts 2 Posters 358 Views 2 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • J Offline
      jach9009
      last edited by jach9009

      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
      
      1 Reply Last reply Reply Quote 0
      • A Offline
        Aerilius
        last edited by

        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
        
        
        1 Reply Last reply Reply Quote 0
        • J Offline
          jach9009
          last edited by

          Thank you! that worked perfectly everything is running smoothly now.

          1 Reply Last reply Reply Quote 0
          • 1 / 1
          • First post
            Last post
          Buy SketchPlus
          Buy SUbD
          Buy WrapR
          Buy eBook
          Buy Modelur
          Buy Vertex Tools
          Buy SketchCuisine
          Buy FormFonts

          Advertisement