Hi guys,
I am trying to set up a Python script as an alias, but it seems the folder I assigned in the ScriptEditor is not recognised.
If I write the absolute path in the alias, it all works nicely.
Hi guys,
I am trying to set up a Python script as an alias, but it seems the folder I assigned in the ScriptEditor is not recognised.
If I write the absolute path in the alias, it all works nicely.
Hi @libny.pacheco ,
I don’t know if this is relevant but do you have the #! python3
flag at the top of your alias script?
Alternatively, do you have the module path set for IronPython2 as well? I’m not sure but would guess that Aliases could run Py2 by default but perhaps not…
May be worth checking, just a guess though
-RunPythonScript
uses the the old pythonscript editor settings of EditPythonScript.
For running scripts created in ScriptEditor, or to use the paths from ScriptEditor, use
-ScriptEditor r "path\to\script.py"
Thanks for chipping in, Michael!
The #! python3
flag didn’t matter in this case
Gijs! That was the ticket.
I could use a relative path! The only thing to do is add the backslash and the .py to the file name in the alias field.
@libny.pacheco The folders in the script editor are python Module Search Paths
. Do not put your scripts in those folders unless you want to import them into another script.
Use Rhino > Options > Files > Search Paths for scripts
That now finds Python scripts? Before it didn’t work, it only found VB Rhinoscripts. So it’s no longer necessary to set search paths it the editor to run scripts via aliases without full paths hard coded?
Thanks, @eirannejad ! That makes sense.
I am adapting the guide I was writting accordingly!
No. As long as scripts can be found on the File search paths in Rhino, this macro should work with no issues:
_-ScriptEditor _Run "MyScript.py"
And you can still use the ()
to embed the complete script in a macro
!_NoEcho _-ScriptEditor _Run (
#! python 3
import scriptcontext
import rhinoscriptsyntax as rs
n = 0
limit = 100
while True:
rs.Prompt("test "+str(n)+" of "+str(limit)+" (Press ESC to terminate)")
n += 1
rs.Sleep(100)
if n> limit:
break
if scriptcontext.escape_test(False):
print("ESC pressed")
break #get out of the loop
print("Done")
)
111
I got these documented here