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

Timeout for Ruby Scripts

Scheduled Pinned Locked Moved Developers' Forum
6 Posts 4 Posters 415 Views 4 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
    Jim
    last edited by 23 Jun 2009, 16:10

    I am experimenting with a way to pause running scripts, and this is what I have so for. I don't have all that deep of an understanding of threads, so if this is going in the wrong direction, let me know.

    Please try this out if you have time. You will likely need to adjust the count and timeout variables for your system.

    I don't know what kind of performance penalty using the thread variable imposes, but it sure is nice to have a progress report as you go; and could easily show an estimated time for completion.

    Eventually, I would like to make this transparent by providing a simple wrapper for making the call, and integrating into start_operation/commit_operation/abort_operation.

    
    
    model    = Sketchup.active_model
    entities = model.entities
    
    count    = 10000
    timeout  = 3 # seconds
    
    thr1 = Thread.new {
        z = 0
        count.times do |i|
    	Thread.current[;i] = i
    	x = i + 1
    	p1 = [0, 0, z]
    	p2 = [x, 0, z]
    	p3 = [x, x, z]
    	p4 = [0, x, z]
    	entities.add_face p1, p2, p3, p4
        end
    }
    
    while thr1.alive?
        thr1.join(timeout)
        break unless thr1.alive?
        # model.active_view.invalidate
        if( UI.messagebox("#{thr1[;i]} of #{count} complete.\n\nContinue?", MB_YESNO) == IDNO )
    	Thread.kill thr1
        end
    end
    
    
    
    

    ruby_timeout.rb

    Hi

    1 Reply Last reply Reply Quote 0
    • J Offline
      Jim
      last edited by 23 Jun 2009, 20:00

      I am getting the same sort of increasing slow-downs as Chris was asking about. The time between each pause increase the more geometry is added.

      Hi

      1 Reply Last reply Reply Quote 0
      • C Offline
        Chris Fullmer
        last edited by 23 Jun 2009, 20:35

        Grrr thats annoying. Is it messing up the ability of the timer to work right?

        Lately you've been tan, suspicious for the winter.
        All my Plugins I've written

        1 Reply Last reply Reply Quote 0
        • T Offline
          thomthom
          last edited by 23 Jun 2009, 20:39

          Does it help taking out the garbage? Using that GC trick?

          Thomas Thomassen — SketchUp Monkey & Coding addict
          List of my plugins and link to the CookieWare fund

          1 Reply Last reply Reply Quote 0
          • T Offline
            tbd
            last edited by 23 Jun 2009, 20:47

            I don't think so, it is more a limitation of SU openGL architecture than ruby.

            SketchUp Ruby Consultant | Podium 1.x developer
            http://plugins.ro

            1 Reply Last reply Reply Quote 0
            • J Offline
              Jim
              last edited by 23 Jun 2009, 20:55

              @jim said:

              I am getting the same sort of increasing slow-downs as Chris was asking about. The time between each pause increase the more geometry is added.

              Oops, not quite. I was creating and exploding groups when I wrote the above. When I just add plain geometry, the timeout appears to work alright.

              But... the pause between when my dialog is visible and when it actually becomes click-able is getting longer.

              I think I'm beating a dead horse.

              Hi

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

              Advertisement