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
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?