Greetings! I use two standard examples https://ruby.sketchup.com/Sketchup/DefinitionList.html#load_from_url-instance_method and https://ruby.sketchup.com/UI/HtmlDialog.html.
When I use load_from_url in the Ruby console. Everything is ok, I get the model to be located in the project.
But, after I try to wrap this in the interface then on Windows - everything is fine. I get the model.
But on macOS, no. In the console, I get a message that a model request is going on, and the whole program hangs. I tried to find a solution, but it kept saying I used the wrong method, without class LoadHandler. Well, I took that class and the result is the same.
Below is a sample code for window and ruby call.
module UPLOAD
class LoadHandler
attr_accessor :error
def onPercentChange(percent)
Sketchup::set_status_text("loading: #{percent.round}%")
end
def cancelled?
# You could, for example, show a messagebox after X seconds asking if the
# user wants to cancel the download. If this method returns true, then
# the download cancels.
return false
end
def onSuccess
Sketchup::set_status_text('')
end
def onFailure(error_message)
self.error = error_message
Sketchup::set_status_text('')
end
end
#Window
def self.WND
dialog = UI::HtmlDialog.new(
{
:dialog_title => "Dialog Example",
:preferences_key => "com.sample.plugin",
:scrollable => true,
:resizable => true,
:width => 600,
:height => 400,
:left => 100,
:top => 100,
:min_width => 50,
:min_height => 50,
:max_width =>1000,
:max_height => 1000,
:style => UI::HtmlDialog::STYLE_DIALOG
})
dialog.set_file(File.join(__dir__,'main.html'))
dialog.show
dialog.add_action_callback("dc") { |action_context, url|
puts 'JavaScript return #{url}'
#url = '#{url}'
model = Sketchup.active_model
load_handler = LoadHandler.new
definition = model.definitions.load_from_url(url, load_handler)
model.place_component(definition) #place by mouse
if definition.nil?
puts "Error: #{load_handler.error}"
else
puts "Status: Done}"
end
}
end
#Downloader
toolbar = UI::Toolbar.new "Test"
# This command displays Hello World on the screen when clicked
cmd = UI::Command.new("Test") {
UPLOAD::WND()
}
cmd.small_icon = "ToolPencilSmall.png"
cmd.large_icon = "ToolPencilLarge.png"
toolbar = toolbar.add_item cmd
toolbar.show
end
external HTML
<html lang="en">
<head>
<!-- semantic -->
<meta charset="utf-8">
<title>Upload tester cross OS</title>
</head>
<body class="catalog">
<!-- <h1>Blanc kitchen catalog</h1>
<br /> -->
<script>
function dc1(val) {
sketchup.dc(val);
console.log(val);
}
</script>
<b>Hello world!</b>
<br/>
<button id="https://3dwarehouse.sketchup.com/warehouse/v1.0/entities/c2fcfb40-7bc9-4831-8f4e-ba63236d1220/binaries/s21?download=true&recordEvent=true" onclick="dc1(this.id)">Download 3dwarhouse</button>
<br/>
<a id="https://3dwarehouse.sketchup.com/warehouse/v1.0/entities/c2fcfb40-7bc9-4831-8f4e-ba63236d1220/binaries/s21?download=true&recordEvent=true" onclick="dc1(this.id)">Not button 3dwarhouse</a>
</body>
</html>