• Login
sketchucation logo sketchucation
  • Login
🔌 Quick Selection | Try Didier Bur's reworked classic extension that supercharges selections in SketchUp Download

Milli-second timer?

Scheduled Pinned Locked Moved Developers' Forum
10 Posts 4 Posters 320 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 14 Jun 2009, 18:57

    I found out UI.start_timer has a one-second resolution, so is there some way to implement a milli-second timer in Ruby without pausing execution?

    Threads, maybe?

    Hi

    1 Reply Last reply Reply Quote 0
    • T Offline
      thomthom
      last edited by 14 Jun 2009, 19:25

      Typing 0.1 seem to work... ...or is there some issues I'm not seeing?

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

      1 Reply Last reply Reply Quote 0
      • J Offline
        Jim
        last edited by 14 Jun 2009, 19:28

        start_timer will accept a value less than a second - say 0.5, but it returns immediately, and doesn't wait for the 0.5 seconds.

        Hi

        1 Reply Last reply Reply Quote 0
        • T Offline
          thomthom
          last edited by 14 Jun 2009, 19:38

          Ah, rounds down to an Integer? hmm...

          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
            TIG Moderator
            last edited by 14 Jun 2009, 20:17

            Get the Time and remember it, as say 'time'.
            Keep getting the Time in a 'while time < time+clicks' loop till 'time+clicks' exceeds expectations - or / milliseconds /seconds / minutes etc after initial 'time'...

            TIG

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

              Yeah, I've found that my code like

              ` now = Time.now

              do lots of code here

              now2 = Time.now

              puts now2-now`

              That will return a time down to the 1/100 second on my system.

              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 14 Jun 2009, 20:58

                But with that allow other code to run?

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

                1 Reply Last reply Reply Quote 0
                • J Offline
                  Jim
                  last edited by 14 Jun 2009, 21:42

                  This is somewhat related, but I just found timeout.rb in the Ruby standard library.

                  With it, you can do this (abort a long-running operation) I have not tried too hard to break it, but it appears to work well. SketchUp still 'white-screens', but it does abort after the set time (20 seconds in this example)

                  
                  begin
                    timeout(20) do
                      Sketchup.active_model.start_operation "Draw Sphere"
                      up = Geom.linear_combination(0.5, Z_AXIS, 0.5, Y_AXIS)
                      entities.add_group.entities.add_sphere([500, 500, 0], 200, up, 24)
                      Sketchup.active_model.commit_operation
                    end
                  rescue TimeoutError
                    Sketchup.active_model.abort_operation
                    UI.messagebox("Operation Aborted - taking too long.")
                  end
                  
                  

                  Hi

                  1 Reply Last reply Reply Quote 0
                  • J Offline
                    Jim
                    last edited by 14 Jun 2009, 21:45

                    Yeah, what wanted to do is detect a "double-click" in a method called from a shortcut. Single tap - method a gets called, double tap - method b gets called.

                    I can do it using Time.now - last_click_time, but method a always gets fired under both circumstances. I'm fairly sure I need a millisecond timer to delay the first call to method a in case a double-tap occurs.

                    Like maybe the normal single-tap runs the method, but a double-tap brings up a config dialog.

                    Hi

                    1 Reply Last reply Reply Quote 0
                    • J Offline
                      Jim
                      last edited by 14 Jun 2009, 21:58

                      @jim said:

                      With it, you can do this (abort a long-running operation)

                      Oh yeah, I'm definitely going to try to tie this in to start_operation. That way, I can set a single timeout limit for all scripts transparently.

                      Hi

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

                      Advertisement