How do I create a component from an instance I have drawn?


  1. Do not double post. It is a violation of the forum guidelines.
    Please fix the first, and delete the second.

  2. As I already said above, please post code properly in these forums.
    Read: [How to] Post correctly formatted and colorized code on the forum?

  3. All of your code needs to be within a toplevel author namespace module.
    Then each one of your extensions should be in it’s own submodule inside your namespace module.

  4. These statements …

    require 'sketchup.rb'
    require 'extenions.rb'

    … are not needed as SketchUp loads them automatically before loading extensions.
    (This has been done since SketchUp version 2014 and it’s use of Ruby 2.x.)

  5. Use an extension registrar filename that is unique. The “Plugins” folder file space is a shared space. Your extension registrar script (in the “Plugins” folder,) should be named like:
    "CaydenWilson_TrimProfiler.rb", and the extension subfolder needs to have the same name (without the “.rb” extension,) ie: folder "CaydenWilson_TrimProfiler"

    See: class SketchupExtension

    The filenames within your extension subfolder(s) can be whatever you wish. Ie: "TrimProfiler_main.rb" or "main.rb", etc. One of these files will be the loader file that loads all the rest of the extensions files (if there are any.)

  6. Do not open a model messagebox during SketchUp startup. It will block the startup cycle and the user will have to dismiss the messagebox manually. (A good way to anger users.)
    Instead, use a UI::Notification balloon (that can slide into view down in the lower right corner) if you really must inform the user of an important fact during startup.

  7. You cannot use gets in SketchUp’s embedded Ruby, because standard IO is not like in a normal Ruby shell (IRB.) SketchUp’s Ruby Console has hijacked it.
    Instead, you must use UI.inputbox method to display entry boxes or dropdown select controls for the user.

  8. As you work on an extension, you’ll be reloading it manually as your make changes to methods.
    This means you must protect the UI building (commands, menus, toolbars) so they only get created once when your module loads the first time.
    This will be your pattern …

# encoding: UTF-8

module CaydenWilson
  module ProTrim

    extend self

    # CONSTANTS go here ...

    # Module variables go here ...

    def draw_trim_profile
      # Method code goes here ...

    # More methods go here ...

    if !@loaded

      # Create commands, submenus, menu items
      #   and toolbar objects here:'Extensions').add_item('CW Designs: ProTrim') {

      @loaded = true