I have two scripts, Test1 and Test2. In Test2, I require 'Test1' as follows:
require_relative './Script Test/Test1'
module ScriptTest2
extend self
def test2
ScriptTest1.test1
end
def toolbar_maker(toolbar_name)
toolbar = UI::Toolbar.new toolbar_name
toolbar_photo = "a_picture.jpg"
#Specify the command to be run
cmd = UI::Command.new(toolbar_name) {
test2
}
cmd.small_icon = toolbar_photo
cmd.large_icon = toolbar_photo
cmd.tooltip = toolbar_name + ' Toolbars'
cmd.status_bar_text = toolbar_nam
toolbar = toolbar.add_item cmd
toolbar.show
end
toolbar_maker("Test")
end
And this is Test1:
module ScriptTest1
extend self
def test1
prompts = 'Test1:'
values = 'test'
final = inputbox prompts, values, 'Test Inputbox...'
UI.messagebox(final)
end
end
Folder structure is as follows:
Script Test.rbz
Script Test
Test1.rb
Test2.rb
I loaded it to sketchup using the extension manager, and the toolbar has loaded…all well and good.
But when I click the button, nothing happens.
There are no load errors when I Close and reopen SketchUp either…
UI.messagebox and UI.inputbox can fail silently.
This is why you should never use UI.messagebox to debug code.
Output inspection values to the console instead.
For the UI.inputbox method, prompts, defaults and list (of choices) are all array arguments, so try …
final = inputbox [prompts], [values], 'Test Inputbox...'
… or more clearly …
def test1
prompts = ['Test1:']
values = ['test']
final = inputbox( prompts, values, 'Test Inputbox...' )
puts final.inspect
end
Yup…thats the (stupid) solution solved , but that means the problem I’m actually having confuses me more…done a bit more testing, and if I call a second method outside of the module, rather than within, as follows:
require_relative './Script Test/Test1'
require 'path/to/ToolbarCreator.rb'
module ScriptTest2
extend self
def test2
ScriptTest1.test1
end
end
ToolbarCreator.toolbar_maker('Draws Columns', ScriptTest2.test2)
and ToolbarCreator.rb is as follows:
module ToolbarCreator
def self.toolbar_maker(tool_name, does_this)
toolbar = UI::Toolbar.new "Test"
# This toolbar icon runs the inputbox required to Test"
toolbar_photo2 = "a _photo.jpg"
cmd = UI::Command.new(tool_name) {
does_this
}
cmd.small_icon = toolbar_photo2
cmd.large_icon = toolbar_photo2
cmd.tooltip = tool_name
cmd.status_bar_text = tool_name
toolbar = toolbar.add_item cmd
toolbar.show
end
end
Now, I know it will work, if I do it as i did in the previous example…but I want a module that I can call, to create new toolbars for everything!! And the previous example gets the following error: C:/path/to/Script Test/Test1.rb:12:in `test1': undefined method `inputbox' for ScriptTest1:Module (NoMethodError) from C:/path/to/Script Test.rb:11:in `test2' from C:/path/to/Script Test.rb:13:in `<module:ScriptTest2>' from C:/path/to/Script Test.rb:6:in `<main>' [Finished in 0.2s with exit code 1]
aaaaand that isnt explained away by some missing braces
Thanks for that…it works perfectly now…just need to keep slogging away at learning ruby and eventually I could potentially be helping add answers to this site