[Template] Ruby Plugin main file


#1

Seconded! And also since it’s likely you will write more than one plugin, each plugin should be sub-wrapped in it’s own sub module of your toplevel module.

Change “Author” in the template to your own unique top-level company name, brand name, initials, or online nickname. (Do not use some other entity’s trademarks, salesmarks, brandnames, patented names, etc. Ie, do not use “Sketchup” or “Layout” in any form, in any case combination, with or without appended or prepended words.)

Save your template as encoding UTF-8 without BOM (Bit Order Mark.)
It is also recommend that Unix type end of lines be used. (Although some prefer Windows EOLs on PC because snippets can be pasted into the Ruby Console and line breaks work. Snippets with Unix EOLs will not line break in the PC console. I personally have only the little snippet files in my “Snippets” folder set to Windows EOLs.)

# encoding: UTF-8
#{ =========================================================
#  Documentation block ...
#} =========================================================
 
require 'sketchup.rb'
module Author
  module ThisPlugin

    # CONSTANTS defined here
 
    # Module @@variables defined here

    # Classes unique to ThisPlugin defined here
 
    class << self
 
      def init()
        # define instance @variables here
      end

      # def plugin methods here
 
    end # proxy class
 
    # Run Once at startup block here:
    this_file = Module::nesting[0].name <<':'<< File.basename(__FILE__)
    unless file_loaded?( this_file )
 
      init() # call the init method if needed
 
      # define commands, menus and menu items here
 
      file_loaded( this_file )
    end
 
  end # plugin module
end # toplevel module

:bulb:


Advice to put class inside a ruby module
Plugin naming conventions
Can't load required rb
How to create a component definition without drawing?
Ruby Learning Resources [WikiLists]