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

Ruby File Auto-Reloader code

Scheduled Pinned Locked Moved Developers' Forum
3 Posts 2 Posters 1.2k Views 2 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.
  • J Offline
    Jim
    last edited by 2 Oct 2010, 18:17

    I got tired of reloading files I was editing, so made this up real quick. It uses a timer to check the last modification time on a file, and loads if updated. It handles errors gracefully by only trying to reload a file once per update. If packaged up with a nice user interface, it might make a nice dev tool.

    Stop the timer in the Ruby Console: UI.stop_timer $t

    Note - It's only good for one file at a time and needs improved if loading multiple files is needed. I just wanted something for "right now," and will try to make it better later.

    
    def autoreload(name)
        pf = Sketchup.find_support_file('plugins')
        file = File.join(pf, name)
        $t = UI.start_timer(2, true) do
            mt = Kernel.test(?M, file)
            if mt.to_i > $mt.to_i
                puts "Loading; #{File.basename(file)}"
                begin
                    load file
                rescue Exception => e
                    puts e.message
                    puts e.backtrace
                end
                $mt = mt
            end
        end
    end
    
    
    

    Hi

    1 Reply Last reply Reply Quote 0
    • M Offline
      Morgan74
      last edited by 5 Oct 2010, 15:45

      Thank-you for this great Plugin !!! 👍
      It's so boring to always close and re-open SU to update my plugins files !! 👿

      1 Reply Last reply Reply Quote 0
      • J Offline
        Jim
        last edited by 6 Oct 2010, 14:32

        I'm glad you found it useful.

        But there are times when it is good to close SketchUp; when you change the name of a method, for example. Closing SketchUp is the only way to get rid of the old method name. Sometimes you have a bug where a part of your code is still using the old method name until you remember you changed it. I've done this numerous times.

        Hi

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

        Advertisement