I want to use an existing HTML file (test1.html
) in an HtmlDialog.
I’ve got it to work using the Ruby heredoc
construct and cut and pasted the html file contents into the Ruby file that way.
It works fine on its own when opening in Chrome, and did work just as well inside SU when included as a heredoc
.
I’m using a slightly adapted version of an HtmlDialog example from the Sketchup GitHub pages (the Step03 example).
But I can’t see how to use the file itself using dialog.set_file(filename)
The ruby file that loads the example dialog is:
module JWMPlugins
module Test2
# Window fully reusable.
def self.create_dialog
options = {
:dialog_title => "Example",
:preferences_key => "example.htmldialog.test",
:style => UI::HtmlDialog::STYLE_DIALOG
}
dialog = UI::HtmlDialog.new(options)
dialog.center
dialog
end
def self.show_dialog
if @dialog && @dialog.visible?
@dialog.bring_to_front
else
# Attach content and callbacks when showing the dialog,
# not when creating it, to be able to use the same dialog again.
@dialog ||= self.create_dialog
@dialog.add_action_callback('poke') { |action_context, name, num_pokes|
self.on_poke(name, num_pokes)
nil
}
@dialog.set_file("test1.html")
@dialog.show
end
end
def self.on_poke(name, num_pokes)
num_pokes.times {
puts "Poke #{name}!"
}
end
end # Test2
end # JWMPlugins
The test1.html
file is in the Sketchup Plugins/test
folder, the same folder as test2.rb
, and there’s nothing else in the test
folder.
But I can’t get the dialog code to open this file.
All that shows is a blank white window with (as set up in options
) the window title Example
.
I’ve tried @dialog.set_file("./test1")
and @dialog.set_file("test/test1")
but that neither of those works either.
And there are no errors in the Ruby console.
I expect it’s something simple that I’m misunderstanding or just ‘doing wrong’ but I can’t see what it is myself.
Any suggestions please?
The API Docs example shows a full path to the file, but is that necessary?