If you do not use a load handler object then you need to wrap within a begin … rescue 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.
# 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|
file.write(skp_on_line_file)
end
#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’ ?