Skip to content

Instantly share code, notes, and snippets.

@eigenhombre
Created February 28, 2018 20:14
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eigenhombre/8bcaff80a9e6bc08e198260308a06bd5 to your computer and use it in GitHub Desktop.
Save eigenhombre/8bcaff80a9e6bc08e198260308a06bd5 to your computer and use it in GitHub Desktop.
# scan_plugins.rb
# March 28, 2010
#
# Description: scan a separate plugin directory and load scripts
# automagically.
#
# To use, set PATH to some working directory and create your plugin
# scripts there. DirScanner will keep an eye on that directory and
# load (i.e., execute) any scripts which appear there. Because each
# file will be executed as soon as it is changed, the Ruby files in
# PATH should consist ONLY of SketchUp plugins!
#
# Copyright: John Jacobsen, NPX Designs, Inc.
#
# Permission to use, copy, modify, and distribute this software for
# any purpose and without fee is hereby granted, provided that the above
# copyright notice appear in all copies.
#
# USE OF THIS SOFTWARE IS AT YOUR OWN RISK!
# THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
require 'sketchup.rb'
PATH = "/Users/jacobsen/Programming/sketchup"
class DirScanner
def initialize(path)
@extra_plugin_path = path
@sem = @extra_plugin_path+"/.sem"
end
def doload(checksem=false)
Dir["#{@extra_plugin_path}/*.rb"].each() { |x|
if (!checksem) or (File.mtime(x) > File.mtime(@sem))
touch
load(x)
puts "(Re-)loaded #{x}"
end
}
nil
end
def touch
File.new(@sem, "w").close()
end
def scan
doload
UI::start_timer(1, true) {
doload(true)
}
end
end
if (not file_loaded?("scan_plugins.rb"))
DirScanner.new(PATH).scan
file_loaded("scan_plugins.rb")
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment