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

    UI.start_timer Issues

    Scheduled Pinned Locked Moved Developers' Forum
    9 Posts 3 Posters 586 Views 3 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.
    • chrisglasierC Offline
      chrisglasier
      last edited by

      @thomthom said:

      There's an issue with SU's timers - the interval is rounded down to whole integers. So anything below 1.0 will turn into 0.0 turning the timer into an instant loop.

      This not really about onKeyDown but about the assertion that I don't understand. Here is a callback that runs an object animation that seems (at least to me) to contradict it.

      
      
      @dlg.add_action_callback("move") {|d, p|
      		a = p.split(";")
      		entityNo =  Integer(a[0])
      		model = Sketchup.active_model
              entities = model.active_entities
              entity = entities[entityNo]
      		p entity.name
              selection = model.selection
              selection.clear
              selection.add entity
      		nr = Integer(a[1])
      		incr = Float(a[2]).mm
      		int = Float(a[3])		# int = 0.1
      		dur = Integer(a[4])		# dur = 5
      		model = Sketchup.active_model
      		entities = model.active_entities
      		entity = entities[entityNo]
      		mv = Geom;;Transformation.translation [0,incr,0]
      		clock = 0	
      		timer = UI.start_timer(int, true) {
      		clock += int
      		if clock < dur
      		entity.transform! mv
      		else 
      		UI.stop_timer timer
      		end
      	}
      
      

      Please tell me if I have missed something fundamental (I lost my sensitivity many years ago).

      With TBA interfaces we can analyse what is to be achieved so that IT can help with automation to achieve it.

      1 Reply Last reply Reply Quote 0
      • thomthomT Offline
        thomthom
        last edited by

        
        t=Time.now; UI.start_timer(1.5, false) { puts Time.now - t }
        12546
        1.01
        
        t=Time.now; UI.start_timer(0.5, false) { puts Time.now - t }
        12514
        0.02
        
        

        See - the timer does not wait for the full duration - instead round the interval down to a whole number.

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

        1 Reply Last reply Reply Quote 0
        • Dan RathbunD Offline
          Dan Rathbun
          last edited by

          @chrisglasier said:

          Please tell me if I have missed something fundamental ...

          I think your confusion comes from that your using the 1st arg to UI.start_timer for double duty. Your also using it within the block as a iteration increment value. Which is fine, it would control the iteration steps correctly, no matter what the delay was/is for the block to begin execution.
          As ThomThom points out, in your case it's actually rounding down to 0.

          The API does explain the first arg as:
          @unknownuser said:

          seconds The time in seconds before your code should be called.

          I'm not here much anymore.

          1 Reply Last reply Reply Quote 0
          • chrisglasierC Offline
            chrisglasier
            last edited by

            @thomthom said:

            
            > t=Time.now; UI.start_timer(1.5, false) { puts Time.now - t }
            > 12546
            > 1.01
            > 
            > t=Time.now; UI.start_timer(0.5, false) { puts Time.now - t }
            > 12514
            > 0.02
            > 
            

            See - the timer does not wait for the full duration - instead round the interval down to a whole number.

            Well all I know is I used true (repeat) instead of false and the object moves 50 increments in 5 seconds.

            With TBA interfaces we can analyse what is to be achieved so that IT can help with automation to achieve it.

            1 Reply Last reply Reply Quote 0
            • chrisglasierC Offline
              chrisglasier
              last edited by

              Thanks I will overnight it (the verb)

              With TBA interfaces we can analyse what is to be achieved so that IT can help with automation to achieve it.

              1 Reply Last reply Reply Quote 0
              • Dan RathbunD Offline
                Dan Rathbun
                last edited by

                @chrisglasier said:

                Well all I know is I used true (repeat) instead of false and the object moves 50 increments in 5 seconds.

                Of course! But if you changed the first arg to a literal 1.0 (and left the local var int still at 0.1,) then your object would finish moving in about 6 seconds (1 second delay before the loop, and 5 seconds worth of animation time.)

                I think you were under the impression that the 1st arg delay would occur at the start of each loop iteration, which is not true. It's ONLY the delay BEFORE the block (which I think Ruby converts internally to a Proc object,) is CALLED.

                I'm not here much anymore.

                1 Reply Last reply Reply Quote 0
                • thomthomT Offline
                  thomthom
                  last edited by

                  @chrisglasier said:

                  Well all I know is I used true (repeat) instead of false and the object moves 50 increments in 5 seconds.

                  Could be that the transformation done inside the timer block slows the iteration down to a point where you're getting a time close to what you expect.

                  i=0; t=Time.now; x=UI.start_timer(0.5, true) { puts Time.now - t; i+= 1; UI.stop_timer(x) if i == 10 } 19079 0.02 0.03 0.05 0.06 0.08 0.1 0.11 0.13 0.14 0.16

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

                  1 Reply Last reply Reply Quote 0
                  • chrisglasierC Offline
                    chrisglasier
                    last edited by

                    It looks pretty close - I will check the mm tomorrow.


                    pig 010.png


                    pig 011.png

                    With TBA interfaces we can analyse what is to be achieved so that IT can help with automation to achieve it.

                    1 Reply Last reply Reply Quote 0
                    • chrisglasierC Offline
                      chrisglasier
                      last edited by

                      @thomthom said:

                      Could be that the transformation done inside the timer block slows the iteration down to a point where you're getting a time close to what you expect.

                      As this thread title seems to have morphed I want to ask other related questions.

                      Is the timer different from an array because it does not call the next iteration until the transformation is complete?

                      I am more concerned about sequence than precise timing. So would multiple transformations suffer/benefit from hardware efficiency equally - i.e. the sequencing will be correct?

                      Thanks

                      With TBA interfaces we can analyse what is to be achieved so that IT can help with automation to achieve it.

                      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