RunPythonScript: Use http address for script instead of file on local directory?

Trying to assign a script to a button in Rhino, but the script is stored on a http site. We’ve usually used a local directory which works fine but I can’t seem to access the script via a button. What I’m doing looks something like this
-_RunPythonScript (http://acd/CS/script.py)

which isn’t working :cry:
But if i were to type RunPythonScript in rhino’s command bar, window opens up the pop up/dialogue to select files, and I just paste the address above into where it says file name, it runs fine. I tried writing a python script to get around this but that didn’t work either:

import rhinoscriptsyntax as rs

directory = "http://darkknight/ControlledSoftware/TestSphere.py"

rs.Command("-_RunPythonScript " + directory + " _Enter")

Is it possible to get something like this to work? With or without the script above?

Thank you.

I suggest you try:

directory = r"http://darkknight/ControlledSoftware/TestSphere.py"
rs.Command(“-_RunPythonScript " + directory + " _Enter”)

Regards,
Terry.

Hey thanks for the response Terry. Could you explain the difference in what you did vs what I wrote? I am noticing different direction for the slashes and the addition of r in front of the address. It doesn’t seem to be working for me. But I might be able to work out why with some explanation if that’s ok.
Thank you :slight_smile:

I tried both direction of slashes in Rhino on my system with a local file and both were successful (/ and ).

The r in front of the string means use the raw string. This avoids the need to use double slashes inside the string in cases where the slash plus the following character is a special combination (like \n for new line). Your string does not seem to contain one of these but to be safe I always use the r so I do not have to worry about it.

I get this to work with a local file but I cannot test it with a file at a http location since I do not have an http location to put my file.

So I do not know how to make this work for you.

Regards,
Terry.

You can try this. It worked on my localhost http server for static content. You may have to adjust for your network/server situation.

import rhinoscriptsyntax as rs
import scriptcontext as sc
import Rhino as R

# use this to 'talk' http
import httplib

# Connect to your server, make the request, read response.
# May have to adjust, can't test on your setup, but I pulled a static
# file from my http server and it seemed to work.
conn = httplib.HTTPConnection('darknight', 80) 
conn.request('GET', '/ControlledSoftware/TestSphere.py')
response = conn.getresponse()

# just for troubleshooting
print response.getheaders()

# this should be the TestSphere.py contents
script_string = response.read()

# just for troubleshooting
print script_string

# need this to excecute a python script from a str
python_script = R.Runtime.PythonScript.Create()
python_script.ExecuteScript(script_string)
2 Likes