sketchucation logo sketchucation
    • Login
    โš ๏ธ Attention | Having issues with Sketchucation Tools 5? Report Here

    Launch animation

    Scheduled Pinned Locked Moved Plugins
    17 Posts 3 Posters 489 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.
    • inteloideI Offline
      inteloide
      last edited by

      Hello TIG,

      Thanks for your answer, mainly for the last link, which I didn't read yet.

      But the issue I have is to keep the animation running.
      With my code below, I made a class which show scenes page by page
      But the animation stop when I change the page (pages.selected_page = model.pages[$xg])
      Also I don't know if switch time between pages will be as per value defined in sketchup parameters...

      Any idea, or other way to proceed ?

      class Anima
      def initialize
      $xg = 0
      end

      def nextFrame(view)
      pages = Sketchup.active_model.pages
      model = Sketchup.active_model
      #UI.messagebox $xg
      $xg+=1
      if $xg > pages.count then
      $xg = 0
      end
      pages.selected_page = model.pages[$xg]
      #view=Sketchup.active_model.active_view
      #view.show_frame

      return true
      

      end
      def stop
      UI.messagebox "fin"
      end
      end #class

      Humanity will do a huge step when the IT professionals will understand that computers are tools...

      1 Reply Last reply Reply Quote 0
      • TIGT Offline
        TIG Moderator
        last edited by

        A few points...
        Use @xg which is specific to that instance of your class... and NEVER use $xg which would be global to ALL scripts loaded...
        To keep it going reset @xg=0 if @xg>pages.length-1 - so it never ends... remember that an array starts at 0 so you need the -1 when doing a comparison .....

        TIG

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

          This proposed feature by inteloide should be integrated by default in the next Sketchup version. Having to click three times to play the animation is no good so I'll be keeping an eye when this plugin is done ๐Ÿ˜„

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

          1 Reply Last reply Reply Quote 0
          • inteloideI Offline
            inteloide
            last edited by

            ok, by changing to :
            @xg=0 if @xg>pages.size-1

            all pages are activated, but without any break between each of them. (it's like it goes directly to the last page). How to implement a break ?
            Also it doesn't loop : when the last page is shown, it stops (doesn't loop). Any reason why ?

            Thanks again.
            I will post my complete plugin when finish. Actually it's based on mover.rb plugin (to move components between pages) but I wanted to add a toolbar to have all tool within on click.

            Humanity will do a huge step when the IT professionals will understand that computers are tools...

            1 Reply Last reply Reply Quote 0
            • TIGT Offline
              TIG Moderator
              last edited by

              Read the Page section of the API.
              page.delay_time gives the time to delay between pages [there is also transition_time], you could try using it/them between page changes, using a UI.start_timer(...){...} for each page ? [untested]...
              If it's -1 you need to also get the model's page-options to find what the default value is...
              Sketchup.active_model.options["SlideshowOptions"]["SlideTime"]
              Sketchup.active_model.options["PageOptions"]["TransitionTime"]
              etc

              TIG

              1 Reply Last reply Reply Quote 0
              • inteloideI Offline
                inteloide
                last edited by

                Thanks TIG for telling me to look at Page API, because I thought it was only a collection (Pages) and not an entity.

                So at the end, the solution I found is the following one :

                def lire_anim (p) model = Sketchup.active_model pages = model.pages pages.selected_page = pages[p] if p<pages.size-1 then id = UI.start_timer(Sketchup.active_model.options["PageOptions"]["TransitionTime"], false) { lire_anim(p+1) } end end

                and to launch : lire_anim(0)

                Now, I need to find a way to stop animation while it's running...

                Humanity will do a huge step when the IT professionals will understand that computers are tools...

                1 Reply Last reply Reply Quote 0
                • TIGT Offline
                  TIG Moderator
                  last edited by

                  You also need to understand view.animation= etc...
                  https://developers.google.com/sketchup/docs/ourdoc/view#animation=
                  Add this into your script's methods

                  animation = Anima.new()
                   model = Sketchup.active_model
                   view = model.active_view
                   anim = view.animation=animation
                   if (anim)
                     UI.messagebox anim
                   else
                     UI.messagebox "Failure"
                   end
                  

                  To cancel the current view's animation use view.animation=nil

                  TIG

                  1 Reply Last reply Reply Quote 0
                  • inteloideI Offline
                    inteloide
                    last edited by

                    I'm close to the aim !
                    I have 2 issues :
                    1-When start the animation it goes to "stop" subrouting but it doesn't stop animation ...?!
                    2-When setting view.animation to nil, it' doesn't stop... ?!

                    Again your help is welcome !

                    class Class_Run_Animation def initialize puts "Start of animation" show_scene(0) end def show_scene(p) puts "Go to scene #{p}" pages = Sketchup.active_model.pages pages.selected_page = pages[p] if p<pages.size-1 then id = UI.start_timer(Sketchup.active_model.options["PageOptions"]["TransitionTime"], false) { show_scene(p+1) } return true else puts "End of loop" return false end end def stop puts "Loop stopped" return false end end

                    Humanity will do a huge step when the IT professionals will understand that computers are tools...

                    1 Reply Last reply Reply Quote 0
                    • TIGT Offline
                      TIG Moderator
                      last edited by

                      You loop through the pages and then return false, this stops it, you never call stop, and don't really need to...
                      You should only use the initialize() method to set up @ variables etc, if needed...
                      You have dropped the def nextFrame(view)... Why? I think this is confusing the issue... Using it would let you create an animation class object that you could assign to the view [looping through the scenes [pages] etc] in some separate code with view.animation=Class_Run_Animation.new(), then you can later cancel with view.animation=nil.
                      The separate code used would be something like:

                      module Inteloide
                        def self.start_animation()
                          Sketchup.active_model.active_view.animation=Class_Run_Animation.new()
                        end
                        def self.end_animation()
                          Sketchup.active_model.active_view.animation=nil
                        end
                      end
                      

                      Used in the console [or added to a toolbar command] as
                      Inteloide.start_animation
                      and
                      Inteloide.stop_animation
                      Your earlier code could be readily adapted to do this...

                      TIG

                      1 Reply Last reply Reply Quote 0
                      • inteloideI Offline
                        inteloide
                        last edited by

                        ok, I changed to an animation class, but it still don't stop
                        I think the issue comes from the start_timer which start the procedure even if animation is stopped.

                        ` class Class_Run_Animation
                        def initialize
                        puts "Start of animation"
                        #show_scene(0)
                        @p=0
                        end

                        def nextFrame(view)
                        puts "Go to scene #{@p}"
                        pages = Sketchup.active_model.pages
                        pages.selected_page = pages[@p]
                        if @p<pages.size-1 then
                        @p+=1
                        id = UI.start_timer(Sketchup.active_model.options["PageOptions"]["TransitionTime"], false) { nextFrame(view) }
                        return true
                        else
                        puts "End of loop"
                        return false
                        end
                        end
                        end

                        module Inteloide
                        def self.start_animation()
                        Sketchup.active_model.active_view.animation=Class_Run_Animation.new()
                        end
                        def self.stop_animation()
                        Sketchup.active_model.active_view.animation=nil
                        end
                        end`

                        Humanity will do a huge step when the IT professionals will understand that computers are tools...

                        1 Reply Last reply Reply Quote 0
                        • TIGT Offline
                          TIG Moderator
                          last edited by

                          You've made it iterate itself!
                          Try something like this...

                          
                          def initialize()
                            @model=Sketchup.active_model
                            @pages = Sketchup.active_model.pages
                            @po=@model.options["PageOptions"]
                          end
                          def nextFrame(view)
                            while view
                              @pages.to_array.each_with_index{|page, i|
                                next unless page.name==page.label ### (SKIP)
                                puts page.name
                                @pages.selected_page = @pages[i]
                                UI.start_timer(@po["TransitionTime"],false){###}### wait for a time
                              }
                            end#while
                          end
                          

                          or similar...

                          TIG

                          1 Reply Last reply Reply Quote 0
                          • inteloideI Offline
                            inteloide
                            last edited by

                            Well, I'm lost ;o)

                            what is the aim of this loop :
                            @pages.to_array.each_with_index{|page, i|
                            next unless page.name==page.label ### (SKIP)

                            what do you put instead of "###" in the code :
                            UI.start_timer(@po["TransitionTime"],false){###}
                            (I put nextFrame(view) because if not the animation doesn't continue)

                            Humanity will do a huge step when the IT professionals will understand that computers are tools...

                            1 Reply Last reply Reply Quote 0
                            • inteloideI Offline
                              inteloide
                              last edited by

                              Maybe it's because I don't understand how sketchup makes the loop for an animation, what's happen after nextframe is called and run ? I'm lost in fact.... ๐Ÿ˜ฎ(

                              Humanity will do a huge step when the IT professionals will understand that computers are tools...

                              1 Reply Last reply Reply Quote 0
                              • TIGT Offline
                                TIG Moderator
                                last edited by

                                Maybe I confused you with the addition of
                                next unless page.name==page.label ### (SKIP)
                                All this does is NOT display the page IF the name and label don't match.
                                A page's name and its label are the same UNLESS the page has be marked NOT to be included in the animation in the Scene-Manager dialog - it then has the name labeled inside () - so you won't show it...
                                The ### is a 'rem' statement - a 'comment' after the code so what follows is ignored...

                                The next part:
                                puts page.name
                                simply displays the name of the scene it's processing in the Ruby Console
                                Then:
                                @pages.selected_page = @pages[i]
                                sets the selected page to be the current pages 'item' [by index 'i'] in the list of pages...
                                Next:
                                UI.start_timer(@po["TransitionTime"],false){###}### wait for a time
                                The timer starts a pause - the rem ### at the end is as above...
                                ON reflection... I appreciate that this final part is wrong. ๐Ÿ˜ฎ
                                Because the timer then runs outside of the main loop !
                                Perhaps using:
                                sleep(@po["TransitionTime"])
                                instead, might work instead ?? This stop processing for that long before the next page is set 'selected'. ๐Ÿ˜•

                                TIG

                                1 Reply Last reply Reply Quote 0
                                • inteloideI Offline
                                  inteloide
                                  last edited by

                                  Hi,

                                  I didn't saw your answer but I produced this code...
                                  I post it for your information...but I will work on your answer

                                  So, my code, as it is now (please don't blame me using a global variable... ๐Ÿ˜‰ )

                                  ` class Class_Run_Animation
                                  def initialize
                                  puts "Start of animation v1"
                                  @p=0
                                  @id=0
                                  end

                                  def nextFrame(view)
                                  if $inteloide_cont==true then
                                  puts "Go to scene #{@p}"
                                  pages = Sketchup.active_model.pages

                                    pages.selected_page = pages[@p]
                                    if @p<pages.size-1 then
                                      @p+=1
                                      @id=UI.start_timer(Sketchup.active_model.options["PageOptions"]["TransitionTime"]+Sketchup.active_model.options["SlideshowOptions"]["SlideTime"], false) { nextFrame(view) }
                                      return true
                                    else        
                                      puts "End of loop"
                                      return false
                                    end
                                  else
                                    puts "stop animation"
                                    @id=UI.start_timer(1, false) { nextFrame(view) }
                                  end
                                  

                                  end
                                  end

                                  module Inteloide
                                  def self.start_animation()
                                  $inteloide_cont=true
                                  Sketchup.active_model.active_view.animation=Class_Run_Animation.new()
                                  end
                                  def self.stop_animation()
                                  $inteloide_cont=false
                                  Sketchup.active_model.active_view.animation=nil
                                  end
                                  def self.pause_animation()
                                  $inteloide_cont = !($inteloide_cont)
                                  puts $bg_cont
                                  end
                                  end`

                                  Humanity will do a huge step when the IT professionals will understand that computers are tools...

                                  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