Auto Reload Plugin folder

Auto Reload Plugin folder

Postby Morgan74 » Tue Oct 05, 2010 5:08 pm

Hello,

Thanks to Jim's topic http://forums.sketchucation.com/viewtopic.php?f=180&t=31394 I wrote a plugin to reload a complete folder.

You define the folder to check and you can define some ignored files.
When the LastModificationDate change SU reload the file.
If an error occurs, a messagebox is displayed with the error message with a retry buton.

My module name is Morgan74DevTools so to start the plugin just call "Morgan74DevTools.startAutoReload()" from the console, from your code or uncomment the last code line.

Code: Select all
module Morgan74DevTools
  Folder = "plugins/Morgan74"
  IgnoredFiles = ["Morgan74ToolLoader.rb","Morgan74Tools.rb"]
 
  @timer = nil
  @fileList = []
  @fileDate = []

  def self.startAutoReload()
    folder = Sketchup.find_support_file(Folder) #find folder
    @fileList = Dir.entries(folder) #find files
    #remove sub-folders & Ignored files
    to_delete_list = IgnoredFiles
    @fileList.each do |f|
      if File.directory?(File.join(folder,f)) == true
        to_delete_list.push(f)
      end
    end
    to_delete_list.each do |f|
      @fileList.delete(f)
    end
    #concat folder and files
    @fileList.collect! {|f| File.join(folder,f)}
    #Save last modification Date
    0.upto(@fileList.length()-1){|i|
      @fileDate[i] = Kernel.test(?M,@fileList[i])
    }

    self.startTimer()
  end

  def self.startTimer()
    #Start Timer
    @timer = UI.start_timer(2, true) do
      self.AutoReload()
    end
  end

  def self.stopAutoReload()
    UI.stop_timer(@timer)
  end

  def self.AutoReload()
    0.upto(@fileList.length()-1){|i|
      if Kernel.test(?M,@fileList[i]) != @fileDate[i]
        begin
          Sketchup.set_status_text("Loading : " + @fileList[i].to_s(),SB_PROMPT)
          load @fileList[i]
          @fileDate[i] = Kernel.test(?M,@fileList[i])
        rescue Exception => e
          #Stop timer
          self.stopAutoReload()
          msg = "AutoReload Plugin\n\n"
          msg << "Error loading file :\n" + @fileList[i].to_s() + "\n\n"
          msg << "Error message :\n" + e.message + "\n\n"
          msg << "Fix the error before click RETRY or CANCEL to stop the plugin"
          result = UI.messagebox(msg,MB_RETRYCANCEL)
          self.startTimer() if (result == 4)#Retry = restart timer
        end
      end
    }
  end
end

#Morgan74DevTools.startAutoReload()


Next step can be reload all the folders inside the plugin folder.
0

Morgan74 
 

Re: Auto Reload Plugin folder

Postby Morgan74 » Wed Oct 06, 2010 8:42 am

Here is an example of the error message :

0

Morgan74 
 

Re: Auto Reload Plugin folder

Postby thomthom » Wed Oct 06, 2010 8:46 am

Would help if it included the traceback message so one know exactly where the error occurred.
0
Thomas Thomassen — SketchUp Monkey & Coding addict
List of my plugins and link to the CookieWare fund
User avatar
thomthom 
PluginStore Author
PluginStore Author
 

Re: Auto Reload Plugin folder

Postby Morgan74 » Wed Oct 06, 2010 10:16 am

The traceback is always the same with this plugin because the lastest method used is "load" :
["C:/Program Files (x86)/Google/Google SketchUp 7/Plugins/Morgan74DevTools.rb:48:in `load'", "C:/Program Files (x86)/Google/Google SketchUp 7/Plugins/Morgan74DevTools.rb:48:in `AutoReload'", "C:/Program Files (x86)/Google/Google SketchUp 7/Plugins/Morgan74DevTools.rb:44:in `upto'", "C:/Program Files (x86)/Google/Google SketchUp 7/Plugins/Morgan74DevTools.rb:44:in `AutoReload'", "C:/Program Files (x86)/Google/Google SketchUp 7/Plugins/Morgan74DevTools.rb:35:in `startTimer'", "C:/Program Files (x86)/Google/Google SketchUp 7/Plugins/Morgan74DevTools.rb:34:in `call'"]

But you have in the error message the line of the error and a "small" description :
0

Morgan74 
 

SketchUcation One-Liner Adverts

by Ad Machine » 5 minutes ago



Ad Machine 
Robot
 



 

Return to Developers' Forum

Who is online

Users browsing this forum: No registered users and 10 guests

Visit our sponsors: