Need some help creating new extension

I’m new to creating extensions…how should I start my new extension. Here’s what I have. How does this look?

#protrim.rb
require 'sketchup.rb'
require 'extenions.rb'

module Examples
    module CustomTool

        #Loading Extension
        unless file_loaded?()
          ex=SketchupExtension.new('ProTrim')
          ex.description='Trim builder using the FollowMe function.'
          ex.version='1.0.0'
          ex.copyright='Softworx 2019'
          ex.creator='Softworx'
          Sketchup.register_extension(ex, true)
          file_loaded()
        end

        class ComponentInstance

          #Activating extension for use
          def activate
          @mouse_ip=Sketchup::InputPoint.new
          @picked_first_ip=Sketchup::InputPoint.new
          update_ui
        end

        def deactivate(view)
          view.invalidate
        end

        #Suspend use of extension
        def resume(view)
          update_ui
          view.invalidate
        end

        #Resetting if interrupted
        def onCancel(reason, view)
          reset_tool
          view.invalidate
        end


        model=Sketchup.active_model
        entities=Sketchup.active_model.entities
        UI.menu("Extensions").add_item("ProTrim") {
        UI.messagebox("Welcome to ProTrim. Select your trim, select the path you wish it to extrude on, and click ok.")
        #Method
        draw_trim_profile
          }
        def draw_trim_profile
        #Create variables
        puts"Trim Height"
        trim_height=gets.chomp
        puts"Trim Width"
        trim_width=gets.chomp
        puts"Quarter Round"
        quarter_rount_width=gets.chomp
        quarter_round_height= quarter_rount_width
end

I gave advice in your other topic thread.

Still not posting code correctly for the forum.

The registrar part must be in a file of it’s own in the “Plugins” folder, …
… and the SketchupExtension.new call must also pass a relative filepath to your extension’s loader file, that must be in your extension’s subfolder.
Explained in (5) of the other topic.
Example registrar file …

# encoding: UTF-8

module CaydenWilson
  module ProTrim
    EXTENSION = SketchupExtension.new(
      'ProTrim', 'CaydenWilson_ProTrim/loader'
    )
    EXTENSION.instance_eval {
      self.description='Trim builder using the FollowMe function.'
      self.version='1.0.0'
      self.copyright='Softworx 2019'
      self.creator='Softworx'
    }
    Sketchup.register_extension(EXTENSION, true)
  end
end

The “loader.rb” file would load all the other files that make up your extension.


Also all your files need to be in YOUR unique top level namespace module.
Explained in (3) of the other topic.


Also a quick websearch shows companies already using the name “SoftWorx” in the U.S., Canada, and Scotland (U.K.). Have you filed fictitious name in your state on this or is it just an example name ?

1 Like

Main reference for the structure of a SketchUp extension can be found here: