[Template] Multi-File, Multi-Class with SharedConstants Mixin


#1

SketchUp Extension Template

Multi-File, Multi-Class with SharedConstants Mixin Module

MultiClass_MultiFile.zip (2.8 KB)

NOTE: Typo error (reported below.)


Change module name “Author” in the template files 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.)

Change the “MultiClassPlugin” sub-module name (in all files,) to the name of your particular plugin.

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

:bulb:


Ruby API and Ruby Classes
Global Variable?
Ruby Learning Resources [WikiLists]
Examples of proper extension organization
Can't load required rb
#2

Updated : 2017-12-29

Added an actual "MultiClassPlugin_SharedConstants.rb" file showing the
definition of the Author::MultiClassPlugin::SharedConstants module.

Although from the code examples, it was implied that this file must exist, many new coders did not understand this, so I was asked to actually provide this file.


#3

Hi Dan,

Thanks for putting this template together, I’m finding it very helpful as I dive into learning Ruby and the SketchUp API. I just wanted to let you know of a typo in Author_MultiClassPlugin.rb. On line 28, the method name should refer to SketchupExtension.creator instead of SketchupExtension.creater. I tried to create an extension with your template and SketchUp threw an error on load. undefined method 'creater='


#4

Hi Matt

Alternatively you can use this as template: https://github.com/Eneroth3/open-newer-version/blob/master/src/ene_open_newer_version.rb.

This example gets the extension dir name from the loader file name, so you don’t need to manually edit it for new extensions. By the RBZ specification these names must be the same anyway. It also keeps a constant as reference to the extension object, allowing you to easily reference it in any nested classes or modules, e.g. to use its name for menu entries, or if you need to get its version string.


#5

Very cool Christina, thank you! I was actually just playing around with the UI::Notification class, scratching my head on how to retrieve the extension object. Having that constant defined makes it easy.