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