sketchucation logo sketchucation
    • Login
    Oops, your profile's looking a bit empty! To help us tailor your experience, please fill in key details like your SketchUp version, skill level, operating system, and more. Update and save your info on your profile page today!
    πŸ«› Lightbeans Update | Metallic and Roughness auto-applied in SketchUp 2025+ Download

    Milli-second timer?

    Scheduled Pinned Locked Moved Developers' Forum
    10 Posts 4 Posters 347 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

      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
      • thomthomT Offline
        thomthom
        last edited by

        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

          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
          • thomthomT Offline
            thomthom
            last edited by

            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
            • TIGT Offline
              TIG Moderator
              last edited by

              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
              • Chris FullmerC Offline
                Chris Fullmer
                last edited by

                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
                • thomthomT Offline
                  thomthom
                  last edited by

                  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

                    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

                      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

                        @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
                        • First post
                          Last post
                        Buy SketchPlus
                        Buy SUbD
                        Buy WrapR
                        Buy eBook
                        Buy Modelur
                        Buy Vertex Tools
                        Buy SketchCuisine
                        Buy FormFonts

                        Advertisement