SketchUp STL String Encoding Issues

NO. Not exactly. You need to use rescue in modifier position, not ||.
Also the use of parenthesis will be interpreted as wrapping the parameter list, so should not have a space following the method name:

def file_loaded?(filename)
  $loaded_files.include?(File.basename(filename, ".*").downcase rescue filename)
end

or:

def file_loaded?(filepath)
  filename = File.basename(filepath, ".*")
  filename.downcase! rescue nil
  $loaded_files.include?(filename)
end

But I’ve been preaching that it is unnecessary to push paths of any kind into $loaded_files, as they are already pushed into $LOADED_FEATURES.

So instead do this (but NOT from toplevel nor console!):

# Avoid File.basename & other string methods.
thisfile = caller(0).split(':').first
# Downcase it suppressing errors
thisfile.downcase! rescue nil
# Prepend it with Namespace qualification:
thisfile = "#{Module::nesting[0].name}:#{thisfile}"
begin
  if file_loaded?(thisfile)
    #
    # do once code
    #
    file_loaded(thisfile)
  end
rescue
  # handle error in sketchup.rb
end

I have also preached to “steal” the methods from “sketchup.rb” add them to a mixin module, FIX THEM and use this mixin instead of “sketchup.rb”.

I have logged several bug reports for “sketchup.rb”, that have not yet been repaired.

If anyone wants I have a test “sketchup.rb” override (that I had written several cycles back, but no longer works as a toggle-able extension in the “Plugins” folder, since SU2015 because “Tools” is loaded before “Plugins”. So you’d have to replace it I think.)

PM me if ya want to check it out. It could be wrapped in a mixin module I suppose.