I have a small problem which is due to OSX behavior with Ruby here: I have a Ruby function that is supposed to download a file from the web. The code is as follows:
def download_file_url(url,output_dir,filename)
ext = url.split('.')[-1]
output_path = output_dir+'/'+filename+'.'+ext
File.open(output_path, "wb") do |saved_file|
# the following "open" is provided by open-uri
open(url, "rb") do |read_file|
saved_file.write(read_file.read)
end
end
return(output_path)
end
This works like a charm on Windows but Mac OSX just says the file with path âurlâ does not exist. Does anyone know of a workaround, either software-wise, hardware-wise or code-wise?
PS: I already have a code that can detect the current running OS, I can use that.
Are you sure that you are actually requiring the open-uri rb ?
Another script might already have done so on your PC, but not on your MAC.
Also whatâs the path you are passing ?
Is it properly constructed as in their examples ?
Also passing ârbâ as a second argument seems wrong to me ??
If some other script is also requiring it for you on the PC, but not on the MAC, then that might be confusing the issue ?
This applies to PC and MAC - many additional Ruby methods do not auto-load with SketchUp, they need to be explicitly required before you try to use them.
The âopenâ function that you use is part of openURI so itâs not a File.open etcâŚ
Yeah, maybe an additional plugin was actually loading the script for me. Iâve now added the require 'open-uri' code, just waiting after a way to now test the behabior on Mac.
Also, after multiple tests, Iâve found out that previous versions of SketchUp (Iâm using 2016) werenât downloading the file either. This solved the issue for SketchUp 2015 but not SketchUp 2014. Iâm looking in SketchUp 2014 to see what kind of console behavior it has (Thereâs a begin/rescue code in the main plugin)
EDIT: OK in SketchUp 2014 itâs an SSL-related problem. Not sure if I can solve that.
Letâs just say that in my head, WebDialogs were something which display in the UI ^^ And besides, I was also using this function to download picture files as well