Hi!
I’m trying to develop a plugin that download files from my custom server but i’m getting problems in Sketchup 2017 and 2016 using definitions.load_from_url
Here’s a sample code:
def self.downloadModel()
url = 'http://myserver.com/a.skp'
mod = Sketchup::active_model
cdef = mod.definitions.load_from_url(url)
return unless cdef
Sketchup.active_model.place_component(cdef)
end
And here is the behavior:
Sketchup 2018 - Software keeps responsible during download and freezes during import (OK)
Sketchup 2017 - Software is irresponsible during download and import (BAD)
Sketchup 2016 - Software is irresponsible during download and import (BAD)
Usually if you don’t try to do things in the software after the download ends it get back but is very common random crashes when you try to interact with the interface during the download/import of the file in 2016 and 2017.
So how can i get models from web in Sketchup 2016 and 2017 without freezes the interface during the download?
Hmm… strange. We didn’t do anything to the API of the method for SU2018…
Maybe there were some other changes in our core related to downloads that changed this. I would have to dig into the source history.
Are you able to reliably reproduce this? Have you submitted the BugSplats? (Did you enter any information we can use to look up these crashes?)
For SU2016 I’m not sure. Ruby threads isn’t working properly within SketchUp. Something about it being hosted into a desktop application and how Ruby’s treads are all managed by Ruby makes it misbehaves. So you cannot use a Ruby thread to perform a download with Net::Http in the background I’m afraid. (And you’d have SSL issues if you tried to connect to an HTTPS connection because of issues with OpenSSL in those versions.)
Not really, it’s quite random but it occurs very frequently.
For SU2017+ you could use the Sketchup::Http::Request class to perform a non-blocking download
Thanks will check about it.
How/where do you set up the load_handler Class ?
I already tried with and without the loader_handler using the progress method to send updates to the plugin but the result is the same. it works in the 2018 and freezes in 2017 e 2016
If you guys any other ideas how can i produce non blocking downloads inside SU2017 and 2016 please let me know.
Can you make sure to submit the bugsplat. Then give me nudge, with what SU version and platform - along with some keyboard in the report I can use to look it up in the database.
I had a look at the source to to refresh my memory. The download is synchronous only I’m afraid. So you’d have to provide your own download mechanism. As I mentioned, for SU2017 you could use Sketchup::Http. But for SU2016 is more complicated. You could look into make a Ruby C Extension and use a C/C++ library to perform the download async. We got example project on GitHub: GitHub - SketchUp/ruby-c-extension-examples: Ruby C extension examples
Hmm… this sounds odd. The code that download is synchronous - the logic that load the downloaded SKP file into the model executes on the next line - there is no callback here internally. So I’m surprised and puzzled to hear that you find SketchUp to be responsive while it downloads. Can you interact with it? (The viewport, menus etc?)