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

    Threads Needed, Waits Wanted

    Scheduled Pinned Locked Moved Developers' Forum
    7 Posts 4 Posters 378 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.
    • M Offline
      MartinRinehart
      last edited by

      I've added an extra parameter to my SketchTalk m command. It's the number of seconds over which the move should be done. This floats a component instance referred to by b up 20 units in 5 seconds:

      m b, [0,0,20], 5

      Problem is, this may or may not execute a single frame of the first move:

      m b, [0,0,20] m b, [20,0,0]

      This is the movie function:

      
      def movie( args ) # animated move
      
          inst = args[0]
          vec = args[1]
          nsecs = args[2]
          
          nframes = nsecs * $sketch_talk_fps # $sketch_talk_fps is a float
          frame_vec = [ vec[0]/nframes, vec[1]/nframes, vec[2]/nframes ]
          mover = Mover.new( frame_vec, nframes, inst )
          anim = Sketchup.active_model.active_view.animation = mover
          
          puts 'main? ' + (Thread.current == Thread.main).to_s()
          until anim.done
              puts 'done? ' + anim.done().to_s()
              Thread.current.sleep( 100 )
          end
          
      end # of movie()
      
      

      Yes, it reports, Thread.current == Thread.main

      No, it reports, anim.done is false.

      It reports this exactly once. I am trying, via the loop at the end of movie() to wait for the animation to finish before going on to the next one. But it seems that the wait loop doesn't do any waiting.

      The @done is set to false in the Mover constructor, reset to true in the Mover's stop() method. The View calls stop() correctly.

      The Ruby code has priority. An infinite loop (no call to sleep) loops infinitely and no animation takes place. Calls to Thread.yield() don't work, either.

      Author, Edges to Rubies - The Complete SketchUp Tutorial at http://www.MartinRinehart.com/models/tutorial.

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

        From previous threads on ... threads πŸ˜’ (no pun intended) it appears that threading in SU ruby is a no-go. Unleashes all kinds of demons of other dimensions.

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

        1 Reply Last reply Reply Quote 0
        • C Offline
          cjthompson
          last edited by

          Is there any reason something like this wouldn't work?

          
          now = Time.now
          UI.start_timer(0,true){
            if(Time.now - now > 0.5)
              puts "Test"
              now = Time.now
            end
          }
          
          
          1 Reply Last reply Reply Quote 0
          • Dan RathbunD Offline
            Dan Rathbun
            last edited by

            @cjthompson said:

            Is there any reason something like this wouldn't work?

            Yes.. there's no exit condition to exit from the timer loop (stop_timer).
            And.. since your not using any start delay (the first param is 0,) it's not necessary to use UI.start_timer, just use a normal Ruby loop of some kind, ie: do .. while, etc.

            But CJ your on the right track using Time.now as a test condition.

            I'm not here much anymore.

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

              @dan rathbun said:

              @cjthompson said:

              And.. since your not using any start delay (the first param is 0,) it's not necessary to use UI.start_timer, just use a normal Ruby loop of some kind, ie: do .. while, etc.

              A normal loop will lock up any other processing. I wonder if a Timer loop allows for other things to process..?

              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

                How does this topic "jive" with: Re: Timer < 1.0 seconds ?
                http://forums.sketchucation.com/viewtopic.php?f=180&t=26454&start=15#p242163

                Psst, I haven't had time to test that code yet.. Has anyone else?

                I'm not here much anymore.

                1 Reply Last reply Reply Quote 0
                • M Offline
                  MartinRinehart
                  last edited by

                  I had this brilliant idea (that was a total flop). Since the delay works between frames in an animation, why not just grab that one?

                  Was working well until I moved the puts Time.now() - start out of the animation code and into the mainline:

                  for i in 1..10 do waiter(500); puts Time.now() - start end
                  

                  That said something like 0.03, 0.06, ... So I moved a call to a continue() method into the animation in response to stop(). BugSplat.

                  I think I know how to at least solve the starter problem. The animated "move" commmand stacks move specs that are then run in an animation. Kludgy? Yup. PITA? Yup. But it should actually work.

                  Author, Edges to Rubies - The Complete SketchUp Tutorial at http://www.MartinRinehart.com/models/tutorial.

                  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