[ Code ] !autoload.rb loads "!_autoload" folders
This is about cleaning up the clutter in the Plugins folder.
This script is meant to be personally modified, especially the paths, for individual tastes.
(The Mac paths are only a poor example on my part.)
You can also see that there are empty sections, where you can add code.
Consider this an Example. Tweak it to your own hearts desire.
- Code: Select all
# ----------------------------------------------------------------------------
# File: !autoload.rb
#{ ----------------------------------------------------------------------------
# Prepared by: Dan Rathbun
# ----------------------------------------------------------------------------
#{ Versions:
#
# 1.0.0 : 2011-08-09
#
# 1.1.0 : 2011-08-09
#
# 2.0.0 : 2012-02-19
# |
# ~ Changed order of load for user documents plugin paths.
# Version specific path now takes precedence over Common path.
# ~ Made sure the $LOAD_PATH array is uniqued.
# ~ Show Mac paths with whitespace filled with '_' character, for making
# running shell scripts easier.
# ~ Updated Notes section.
# ~ All document header sections now expand and collapse (in Notepad++.)
#
# 3.0.0 : 2012-09-28
# |
# ~ Added begin .. rescue block to prevent script loading loop from
# short-circuiting when an error occurs in a file.
#
#} ============================================================================
#{ WARRANTY / DISCLAIMER:
#
# 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.
# ----------------------------------------------------------------------------
# License / Terms of Use:
#
# Public Domain
#}
# ----------------------------------------------------------------------------
#{ NOTES:
#
# (1) Place this configuration script in the Sketchup "Plugins" folder.
#
# Create the verdir and comdir directories manually, if you wish to use
# these paths, then edit the verdir and comdir paths to suit your setup.
#
# * The directories must PRE-EXIST, or they will NOT be added to $LOAD_PATH.
#
# *** Be sure to save this file as "UTF-8 without BOM" / "ANSI as UTF-8" if
# your directory paths conatain any UTF-8 characters. Also recommend
# that you set end of Line characters to UNIX.
#
# (2) You can now move any scriptlets out of the Plugins folder, and into
# a new subfolder (of any of the $LOAD_PATH paths,) named "!_autoload".
#
# Extension registration scripts can go in "!_autoload" as long as they
# use relative paths, and NOT absolute paths.
#
# (3) True Plugins should go in a subfolder of their own, and even better if
# they are in a subfolder, of the "Author's" folder.
#}
#} ============================================================================
require("langhandler.rb")
require("sketchup.rb")
require("extensions.rb")
require("dynamiccomponents.rb")
#show_ruby_panel() # from "sketchup.rb"
# ----------------------------------------------------------------------------
# Push any additional Search paths (that may have a "!_autoload" subfolder,)
# into the $LOAD_PATH array below.
# ----------------------------------------------------------------------------
### The directories must PRE-EXIST, or they will NOT be added to $LOAD_PATH.
if RUBY_PLATFORM =~ /(mswin|mingw)/ # MS Windows
# Create HOME environment var if not defined.
# Allows ~ (tilde) path expansion using File.expand_path("~/some/dir/path").
ENV['HOME']=ENV['USERPROFILE'] unless ENV['HOME']
# Example: Windows User Documents Current Version Plugins path:
verdir = File.expand_path("~/My Documents/Google Sketchup/Sketchup #{Sketchup.version.to_i}/Plugins")
$LOAD_PATH << verdir if Kernel.test(?d,verdir)
# Example: Windows User Documents Common (all versions) Plugins path:
comdir = File.expand_path("~/My Documents/Google Sketchup/Common/Plugins")
$LOAD_PATH << comdir if Kernel.test(?d,comdir)
#
# Add additional paths here.
#
$LOAD_PATH.uniq!
end
if RUBY_PLATFORM =~ /(darwin)/ # Mac OSX
# Example: Mac User Documents Current Version Plugins path:
verdir = File.expand_path("~/Documents/Google_Sketchup/Sketchup_#{Sketchup.version.to_i}/Plugins")
$LOAD_PATH << verdir if Kernel.test(?d,verdir)
# Example: Mac User Documents Common (all versions) Plugins path:
comdir = File.expand_path("~/Documents/Google_Sketchup/Common/Plugins")
$LOAD_PATH << comdir if Kernel.test(?d,comdir)
#
# Add additional paths here.
#
$LOAD_PATH.uniq!
end
# ----------------------------------------------------------------------------
# Load all "!_autoload" folders, that reside in any of the $LOAD_PATH
# array folders.
# ----------------------------------------------------------------------------
$LOAD_PATH.each do |abspath|
#
autodir = "!_autoload"
#
autopath = File.join(abspath,autodir)
#
if Kernel.test(?d,autopath)
#
Dir.new( autopath ).each { |file|
ext = File.extname(file)
next if ext.empty? || ext[-1,1]=="!" # skip if ends in '!'
begin
if ext == ".rbs"
Sketchup.require( "#{autodir}/#{file}" )
elsif [".rb",".rbw",".o",".so",".dll",".dylib",".bundle"].include?(ext)
require( "#{autodir}/#{file}" )
end
rescue Exception => e
puts("File: '#{autodir}/#{file}' did not load:")
puts("Error: #<#{e.class.name}: #{e.message}>")
puts e.backtrace unless $VERBOSE.nil?
else
puts("File: '#{autodir}/#{file}' loaded successfully.")
end
}
end #if autopath
end
# ----------------------------------------------------------------------------
# Any other require() calls to load scripts in subfolders,
# or in the Ruby lib path subfolders... etc.
# ----------------------------------------------------------------------------
# ----------------------------------------------------------------------------
# Any additional configuration calls
# ----------------------------------------------------------------------------

