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.
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.