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

    Help with Animation

    Scheduled Pinned Locked Moved Developers' Forum
    23 Posts 7 Posters 3.3k Views 7 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

      @chris fullmer said:

      Ahhaaha! "<" I saw was in his example, and that is clearly what I was explaining, which I thought was odd to have to explain.
      ... I agree with Jim - typo.

      Odd. If you look above the "<", in the Arguments, you see "lt;" which I took to be a typo in a character entity, "<" which is what you need if you want "<" to appear in the doc. Someone went to some trouble to get that typo in there. Brain cramp, I guess.

      Thanks for the help.

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

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

        My first goal, today, was to get this thing to tick off 15 seconds and then take out the trash. Expected to get here before breakfast.

        It's now mid-afternoon and still - no ticking. Can anyone suggest the two or three lines of code (I hope!) needed to get ticking?

        Many thanks. (Factoid: show_frame() returns a reference to the View.)

        
        # anim.rb
        
        require 'sketchup'
        
        class Jumper
        
            def nextFrame( view )
                puts Time.now() - $start
                return ( Time.now() - $start ) < 15
            end
            
            def stop()
                puts 'emptying trash'
            end
        
        end # of class Jumper
        
        $start = Time.now()
        
        view = Sketchup.active_model().active_view()
        puts view
        
        # ??????????  ?????????????  ?????????????  ???????????
        
        view.animation = nil
        
        

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

        1 Reply Last reply Reply Quote 0
        • J Offline
          Jim
          last edited by

          view.animation = Jumper.new

          and probably setting it to nil will kill it immediately.

          nil will kill, haha.

          Hi

          1 Reply Last reply Reply Quote 0
          • T Offline
            todd burch
            last edited by

            @martinrinehart said:

            Odd. If you look above the "<", in the Arguments, you see "lt;" which I took to be a typo in a character entity, "<" which is what you need if you want "<" to appear in the doc. Someone went to some trouble to get that typo in there. Brain cramp, I guess.

            Thanks for the help.

            Actually, the way the Google editor works for this online doc is that it takes the author's typing, and "html-ifies" it for display when you click "save". So, in this case, there was probably no extra effort involved in providing a bad example.

            1 Reply Last reply Reply Quote 0
            • Chris FullmerC Offline
              Chris Fullmer
              last edited by

              Jim's code seemed to do the trick. I had to drag the ruby console around to see the puts values get added. But they were getting putsed and at 15 seconds the clocked stopped and your trash emptied.

              And try this with a group or component selected and it will raise that G/C up 1 unit per frame.

              require 'sketchup'
              
              class Jumper
              
                  def nextFrame( view )
              		$gc.transform! $t
                      return ( Time.now() - $start ) < 15
                  end
                  
                  def stop()
                      puts 'emptying trash'
                  end
              
              end # of class Jumper
              
              $gc = Sketchup.active_model.selection[0]
              vec = Geom;;Vector3d.new(0,0,1)
              $t = Geom;;Transformation.new(vec)
              $start = Time.now()
              
              view = Sketchup.active_model().active_view()
              
              view.animation = Jumper.new
              

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

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

                @jim said:

                view.animation = Jumper.new

                and probably setting it to nil will kill it immediately.

                Making progress. Tick! One tick is better than none.

                @chris fullmer said:

                And try this with a group or component selected and it will raise that G/C up 1 unit per frame.

                Could not duplicate, Chris. Could you repost the entire program? What I've got is missing a move!(). Thanx.

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

                1 Reply Last reply Reply Quote 0
                • Chris FullmerC Offline
                  Chris Fullmer
                  last edited by

                  That snippet was my entire code, run through Jims Web Console. I did not use the .move! method, but instead a regular .transform!. But .move! would have worked fine too (assuming the group/component is not rotated or scaled).

                  So to run it, copy and paste all that into Jim's webconsole, select and component and click execute.

                  All it does is creates a transformation (by vector) uf up 1 inch. Then at each next_frame it applies that transformation to the group. And as you know, the animation runs for 15 seconds.

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

                  1 Reply Last reply Reply Quote 0
                  • Chris FullmerC Offline
                    Chris Fullmer
                    last edited by

                    Here is a quick animation showing your code in action (no sound):

                    [flash=1004,675:2gdcctgr]http://chrisfullmer.com/forums/martin_jumper.swf[/flash:2gdcctgr]

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

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

                      @chris fullmer said:

                      I did not use the .move! method, but instead a regular .transform!

                      Hooray! It's alive. (It's doing exactly what TIG said: relative moves contrary to everything that I've seen. But that's another issue.)

                      You wouldn't be able to slow that down to one or two moves per second, would you? At full throttle on my slow machine that's climbing about 63 inches/second.

                      Edit: never mind. I got it.

                      
                              def nextFrame( view )
                                  $gc.transform! $t
                                  view.show_frame( 0.5 ) # Really simple!
                                  return ( Time.now() - $start ) < 5
                              end
                      
                      

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

                      1 Reply Last reply Reply Quote 0
                      • Chris FullmerC Offline
                        Chris Fullmer
                        last edited by

                        Yes, that is where the .show_frame method comes in to play. Change your next_frame method to this:

                        def nextFrame( view ) $gc.transform! $t view.show_frame 0.5 return ( Time.now() - $start ) < 15 end

                        That puts a 0.5 second delay on the animation. That is how you can control the framerate for SU animations. Of course SU can run even slower than what you specify IF you are animating a lot of geometry.

                        delay should equal seconds divided by framerate:

                        delay = 1 / fps

                        So a target of 15 frames per second is 1 / 15 = 0.066667 for the delay value:

                        view.show_frame 0.066667

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

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

                          @chris fullmer said:

                          Here is a quick animation showing your code ...

                          Very cool. "Our code" I think is more exact. And thanks!

                          Hey, how did you do that? I'm thinking that my HTML tutorial is destined for treeware, but that doesn't rule out links.

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

                          1 Reply Last reply Reply Quote 0
                          • Chris FullmerC Offline
                            Chris Fullmer
                            last edited by

                            Also, the way I put in the transformation makes it move 1" each time the .next_frame method fires. So you would have to do some re-working to make it so that it moves 1" per second, regardless of how many frames get made during that second. But that is do-able, and frankly more useful than making it move 1" per frame.

                            I think the way to do it would be to figure in the frames per second into the transformation, so when the user changes the frames per second, it adjusts the transformation vector distance. Just a thought,

                            Chris

                            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

                              View.average_refresh_time
                              http://code.google.com/intl/nb/apis/sketchup/docs/ourdoc/view.html#average_refresh_time

                              @unknownuser said:

                              The average_refresh_time is used to set the average time used to refresh the current model in the view. This can be used to estimate the frame rate for an animation.

                              This could be useful to verify you're getting the desired framerate?

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

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

                                @thomthom said:

                                This could be useful to verify you're getting the desired framerate?

                                Frame rate seems correct, within SketchUp's limits. Moves small things nicely at 24 fps. Flying my 50kB biplane smoothly. Corrects the timer problem.

                                Will slow down, I assume (never assume!), if trying to move too much geometry.

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

                                1 Reply Last reply Reply Quote 0
                                • renderizaR Offline
                                  renderiza
                                  last edited by

                                  @chris fullmer said:

                                  Here is a quick animation showing your code in action (no sound):

                                  [flash=1004,675:rhvt88ob]http://chrisfullmer.com/forums/martin_jumper.swf[/flash:rhvt88ob]

                                  Hi,

                                  The code runs while using the “Ruby Web Console” but when I try to make a jumper.rb out of it to put it on the plugins folder the following error shows;

                                  Load Errors
                                  Undefined method ‘transform!’ for nil:NilClassError Loading File
                                  jumper.rb
                                  undefined method ‘transform!’ for nil: NilClass

                                  If I try to put the following;

                                  def transform
                                  $gc = Sketchup.active_model.selection[0]
                                  vec = Geom;;Vector3d.new(0,0,1)
                                  $t = Geom;;Transformation.new(vec)
                                  $start = Time.now()
                                  
                                  view = Sketchup.active_model().active_view()
                                  
                                  view.animation = Jumper.new
                                  end
                                  

                                  The jumper.rb loads ok but when I press it no animations are triggered. Can someone please help me with this.

                                  Thanks

                                  [url=https://www.sketchupcode.com/:z3kqsidd]My Extensions ...[/url:z3kqsidd]

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

                                    @unknownuser said:

                                    The code runs while using the “Ruby Web Console” but when I try to make a jumper.rb out of it to put it on the plugins folder the following error shows;


                                    Load Errors

                                    Undefined method ‘transform!’ for nil:NilClassError Loading File
                                    jumper.rb
                                    undefined method ‘transform!’ for nil: NilClass


                                    Because the examples in this topic show very poor programming practice!

                                    (1) The code is not namespace protected

                                    (2) The code uses global variables that can conflict with other global variables.

                                    (3) There is no selection checking that prevents an exception if the selection is empty.

                                    (4) There is no entity Type checking to ensure that the selected entity(ies) can have the transform! method called upon them.

                                    I'll see if I can cobble up a better example, perhaps I'll post it in a new [ Code ] topic (so it can be indexed with the Code Snippet indexer.)

                                    🤓

                                    I'm not here much anymore.

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

                                      @dan rathbun said:

                                      I'll see if I can cobble up a better example, perhaps I'll post it in a new [ Code ] topic (so it can be indexed with the Code Snippet indexer.)

                                      Done!

                                      ➡ [Code] AnimateSelection Example v1.0.0

                                      .

                                      I'm not here much anymore.

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

                                      Advertisement