Failed to definitions.load_from_url

Hi all,

I’m trying to load skp from (Ruby on rails) local web server

url = "http://localhost:3000/rails/active_storage/blobs/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaHBBa29CIiwiZXhwIjpudWxsLCJwdXIiOiJibG9iX2lkIn19--fd47c681580ce0a515c75792125af20b2e063afb/FXCEE.skp"
definition = Sketchup.active_model.definitions.load_from_url url#, load_handler

when I use this code inside my .rb file Sketchup freeze by loading infinitely. I have to force my mac to stop Sketchup app.

If I copy and past this code in console its works perfectly ! ?

I try with and without load_handler.

I’m on Sketchup 2020.1 on mac OS 10.15.4

Find the complete file:
02_componsant_loader.rb (2,8 Ko)

If you do not use a load handler object then you need to wrap within a beginrescue block to trap any errors.

Personally I’d think the load handler would be a better way of handling the download.

I looked at your code and the docs, but the docs don’t seem to indicate whether the load_from_url method is asynchronous or synchronous.

If it is asynchromous, then your following code testing whether definition is nil will not work.
You would need to use the load handler onSuccess and onFailure callbacks to do the post download tests and branch to either a notice of failure to the user, or a subsequent use of the downloaded definition.

And BTW the file is not complete as you did not include your load handler code.

Thanks @DanRathbun!
I try with and without loadhandler without any change :frowning:

I take this code from an old code where it’s works.
The url structure is different, but its works in the previous code.

I try to add #encoding: UTF-8
at the start of the code but nothing change , :frowning:

I try with begin rescue but nothing change (no rescue)

I think load_from_url is synchronous

I finally do not use load_from_url, I simply use

# path of the component on the local hard disk
path = File.join(Adebeo::Pch::ADEBEORUBYPATH,"lib","skp","1234.skp")

# read the file from url
skp_on_line_file = open(url).read

# write the file locally
open(path, "wb") do |file|

#load the file from local storage
definition = Sketchup.active_model.definitions.load path

You refer to ‘path’ without defining it ??
So I assume this is not all of your code…
And also the open(url)... method should have an earlier ‘require’ ?

Thanks for your interrest @TIG,

‘path’ is define as function latter in the code ( you can see it it in the ruby file file attached in the first post)

I already define the Sketchup::require ‘net/http’ at the start of my extension.

Your comment will help the next reader. Thanks!

ps: I edit the previous post

1 Like