How to run tutorial extension on my Sketchup?

I follow GitHub - SketchUp/sketchup-ruby-api-tutorials: SketchUp Ruby API Tutorials and Examples, to create a example extension.

I place ex_hello_cube.rb in /Applications/SketchUp 2024/SketchUp.app/Contents/PlugIns
image

ex_hello_cube.rb

# Copyright 2016 Trimble Inc
# Licensed under the MIT license

require 'sketchup.rb'
require 'extensions.rb'

module Examples
  module HelloCube

    unless file_loaded?(__FILE__)
      ex = SketchupExtension.new('Hello Cube', 'ex_hello_cube/main')
      ex.description = 'SketchUp Ruby API example creating a cube.'
      ex.version     = '1.0.0'
      ex.copyright   = 'Trimble Navigations © 2016'
      ex.creator     = 'SketchUp'
      Sketchup.register_extension(ex, true)
      file_loaded(__FILE__)
    end

  end # module HelloCube
end # module Examples

ex_hello_cube/main.rb

# Copyright 2016 Trimble Inc
# Licensed under the MIT license

require 'sketchup.rb'

module Examples
  module HelloCube

    def self.create_cube
      model = Sketchup.active_model
      model.start_operation('Create Cube', true)
      group = model.active_entities.add_group
      entities = group.entities
      points = [
        Geom::Point3d.new(0,   0,   0),
        Geom::Point3d.new(1.m, 0,   0),
        Geom::Point3d.new(1.m, 1.m, 0),
        Geom::Point3d.new(0,   1.m, 0)
      ]
      face = entities.add_face(points)
      face.pushpull(-1.m)
      model.commit_operation
    end

    unless file_loaded?(__FILE__)
      menu = UI.menu('Plugins')
    menu.add_item('01 Create Cube Example') {
      self.create_cube
    }
      file_loaded(__FILE__)
    end

  end # module HelloCube
end # module Examples

When I start to run Sketchup, I cannot find any sub menu item named “01 Create Cube Example” under the menu Extensions.

even I add a message box in ex_hello_cube.rb

module Examples
  module HelloCube

    UI.messagebox('Hello Cube!')

    unless file_loaded?(__FILE__)
      ex = SketchupExtension.new('Hello Cube', 'ex_hello_cube/main')
      ex.description = 'SketchUp Ruby API example creating a cube.'
      ex.version     = '1.0.0'
      ex.copyright   = 'Trimble Navigations © 2016'
      ex.creator     = 'SketchUp'
      Sketchup.register_extension(ex, true)
      file_loaded(__FILE__)
    end

  end # module HelloCube
end # module Examples

when I restarted Sketchup , I can not see any message box shown.

But when I use ruby editor code to write some code and run it ,it works. I see the sub menu item “01 Create Cube Example” and after click it ,the “hello” message box shown.

menu = UI.menu('Plugins')
menu.add_item('01 Create Cube Example') {
   UI.messagebox("hello")
}

What’s wrong with it?

ENV
Mac: MacOS 14.6.1 (23G93)
sketchup: Version 24.0.554
Not PRO?

Is it possible that only Sketchup Pro can make it work?
image

Try opening the Ruby Console, leave it open when you quit SketchUp, then relaunch SketchUp. Does any output appear in the console?

Edit: on rereading your post, I noticed you are putting the extension code into the wrong folder. That folder is for pre-packaged plugins that are distributed with SketchUp, not for user-added extensions. Your code should go in

/Users/yourname/Library/Application Support/SketchUp 2024/SketchUp/Plugins

where you should replace “yourname” with your actual login name.

The reason it works from the Ruby Code editor extension is that the editor loads the code into the running Ruby within SketchUp. Things in the folder you used are loaded a different way (notice they all have extension .plugin not .rb).

2 Likes

@slbaumgartner Thank you very much.
It works as I follow your metioned path.


s
Thank you very much again.

1 Like