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

    Revert back to saved version

    Scheduled Pinned Locked Moved Developers' Forum
    8 Posts 4 Posters 3.9k 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.
    • D Offline
      driven
      last edited by

      Sketchup.undo

      learn from the mistakes of others, you may not live long enough to make them all yourself...

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

        Encapsulate your 'animation' code thus:
        Sketchup.active_model.start_operation("MyLovelyAnimation")

        do your transformation stuff, using Sketchup.active_model.refresh etc as needed...

        afterwards, to reset everything back to where you started, use...

        Sketchup.active_model.abort_operation

        everything is then undone in one go.

        TIG

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

          ... but does he have to use transform! instead of move! inside the operation block ?

          I'm not here much anymore.

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

            If he's does pure 'animation' using move! instead of transform!, it will indeed not add things to the 'stack'.
            But if he is also changing layer visibility etc, then that is ?
            Aborting the operation will reset back to how it was before the start...
            Although if he's animating the camera, he is advised to save the active view's camera immediately before starting the operation, and after aborting it to reset the view camera back to that ?

            TIG

            1 Reply Last reply Reply Quote 0
            • S Offline
              slbaumgartner
              last edited by

              Seems like maybe a lot of the posts have dodged the original question: when you revert a file, you close the current version and reload the saved one from disk. Can't this be done via:

              
              # true says ignore changes and suppress the save dialog
              Sketchup.active_model.close true
              Sketchup.open_file(path_to_file)
              
              
              1 Reply Last reply Reply Quote 0
              • Dan RathbunD Offline
                Dan Rathbun
                last edited by

                .
                Yes but this will work only on SketchUp 2015+

                close(true) = ignore changes and suppress the save dialog

                filepath = Sketchup.active_model.path
                if Sketchup.active_model.respond_to?(;close)
                  Sketchup.active_model.close(true)
                elsif RUBY_PLATFORM !~ /darwin/i # NOT OSX
                  Sketchup.file_new
                end
                Sketchup.open_file(filepath)
                

                I'm not here much anymore.

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

                  .
                  TIG's Encapsulate your 'animation' code is really a better idea.

                  But try it like this (he omitted the need for a commit_operation call.)

                  begin ### do everything in one go;
                    ###
                    #
                    Sketchup.active_model.start_operation("MyLovelyAnimation")
                      #
                      ### Do your transformation stuff, using
                      ### Sketchup.active_model.refresh etc as needed...
                      #
                    Sketchup.active_model.commit_operation
                    #
                    ###
                  rescue => e
                    # Just output any exception info to console;
                    puts "Error; "<<e.inspect
                    puts e.backtrace # optional
                  else
                    # Things to do only when NO errors occur;
                    UI.messagebox("The show is over. Reset now?")
                  ensure
                    # Whether or not any errors occur;
                    ### reset everything back to start
                    Sketchup.active_model.abort_operation
                  end
                  

                  I am not sure if the messagebox will actually cause a pause before reset.

                  I'm not here much anymore.

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

                    Going back several steps .move! works like .transform! without affecting the stack within an animation ?

                    TIG

                    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