Import file from URL

Hi,

I was wanting to import a dwg with the Import Content component, with a file hosted on an open URL. The issue is, the file path is not recognized and i get a message stating the file doesn’t exist.

Here is the file: dwg_converter_3.gh

Is there something i’m missing?

Thanks in advance!

Url path is not the same thing as a local file path.


With a small c# script you can download that file into an actual local temporary file.


dwg_converter_3b.gh (8.5 KB)

using System.Net;
using System.IO;

    private void RunScript(string url, ref object tempfile)
    {
        string filename = Path.GetFileName(url);
        string temppath = Path.GetTempPath() + filename;
        WebClient wc = new WebClient();
        wc.DownloadFile(new System.Uri(url), temppath);
        tempfile = temppath;
    }

Beware that this does indeed create (and overwrite) a file every time you run it, you might end up with a big temporary folder.
If two filenames are equal, there will be a collision. (you might an hash of the url as the local filename).
Also, yes, it’s a temporary folder, so you should not rely on it as much as a real local copy/backup of your file.

1 Like

Thanks a lot it works just fine!

I noticed it seems to work better with rhino.compute by changing this line to
string filename = Path.GetFileName(url.ToString());

Thanks for your help,

Best