Rhino for Mac users can also write and execute Python scripts

i wonder if making rhino remember the last folder will allow a simple alias to work for the syncing? if so, it might be a simple enough solution without needing to assign a path in rhino prefs.

in osx, making an alias instead of a symlink is real easy… just drag&drop a folder while holding option-cmmd… (sidenote- drag&drop with option key creates a duplicate file)

the python scripts will run properly from an aliased folder/file but rhino doesn’t seem to recognize/remember the aliased folder exists so you have to navigate to it if using RunPythonScript… rhino aliases don’t find the folder either even when it’s in ~/Library/Application Support/McNeel/Rhinoceros…

anyway, i’ll try it out on the next WIP

Yeah, I like the RMB functionality in Windows, right mouse drag something and let go, get a context menu > Move, Copy or Create shortcut(alias)… Plus as in Mac Ctrl+LMB drag → copy ; Alt+LMB drag → create shortcut

OK, this sounds promising, will wait until Tuesday to try some of it out… Thanks! --Mitch

OK, so it looks like now the last used path with RunPythonScript is remembered, even between sessions, so progress there.

OTOH, _-RunPythonScript MyScriptName.py does not look in that directory, it still looks in the default scripts path.

That’s probably a good thing, actually, IMO the dashed version of the command should always look in the same directory - or better yet, a set of directories. Now all we need is for the user to actually be able to specify that/those directory(ies) - without having to symlink everything.

Thanks, --Mitch

First I want to say how awesome this is. It’s already helping out on a project.

I am new to both Atom and Python. Is there a way to log statements and break point debug inside of Atom while a rhino python script runs? I have been using print and going through the Rhino history window.

the thing i was wondering about (using an alias instead of a symbolic link) didn’t fly with the update…

the scripts will run from an aliased folder but a macro -RunPythonScript example still doesn’t see the folder… requires a symlink instead.

It’s great that you’re finding this useful for your project.

There’s no debugger for Python scripts in Atom at this point. Adding a debugger is one thing but because the scripts are run by Rhino and not Atom a remote debugger is what is needed and that is not a trivial task. Having this in the future is something we’re looking into but it won’t be in the first release of Rhino for Mac.

1 Like

in the meantime, you could probably use a script to assign aliases.
something like:

import rhinoscriptsyntax as rs

path = rs.OpenFileName("Choose python file")
alias = rs.GetString("Alias name")

rs.AddAlias(alias, "-RunPythonScript " + path)

it’s not doing what you want as far as custom directory assignment… but it does make it easy(er) to assign a custom path to RunPythonScript
?

here’s a script that will create the necessary link from a chosen folder to the rhino Scripts folder

import rhinoscriptsyntax as rs
import os

def scripts_symlinker():

    target = " ~/Library/Application\ Support/McNeel/Rhinoceros/Scripts "
    source = rs.BrowseForFolder()
    if not source: return
    source = source.replace(" ", "\ ")

    # merge Scripts folder with source folder
    os.system ("ditto" + target + source)

    # remove Scripts folder
    os.system ("rm -rf" + target)

    # create symlink
    os.system("ln -s " + source + target)

    print "The folder: " + source + " ...is now linked to your Scripts folder"

scripts_symlinker()

notes –

rs.BrowseForFolder… i couldn’t figure out a way to get a custom message… the dialog which comes up when running the script will just say ‘Open’… choose the folder you’d like to use as your scripts folder (ie- the one in dropbox)
[maybe someone could have a look at that on mac to see if it’s a little bit broken or i’m just using it wrong?]

• the script will first merge the two folders together… if you have different files in your appSupport/scripts than you do in the dropbox folder, no files will be overwritten or deleted… they’ll be merged together as one.

• it’s ok to use a folder in dropbox named something other than ‘Scripts’… the resulting linked folder will be named Scripts as rhino requires the name for macros to work while the source folder will maintain its existing name.

1 Like

Not sure it’s working as expected. It deletes the Scrips file, but then Rhino recreates an empty one when you run a Python script.

Rhino-Python Scripts is a copy of Dropbox folder that I want to create symlink to. The second image is after I ran a script. Before there was no Scripts folder.

IHTH «Randy

Yes, it will recreate the scripts folder - also the subfolder with the samples, funny enough… But according to Jeff, the symlink should work - you should be able to run scripts from aliases that are in the linked folder without having to program a full path. --Mitch

It doesn’t seem to from any Aliases / Macros with _RunPythonScript. I keep getting an error. I will try again, once more coffee takes effect. :smile:

Rhino-Python Scripts should be in your dropbox and you navigate to it when running the symlink maker script.

after running the script, your appSupport/Rhinoceros folder will look like this:

the Scripts folder will now have the arrow on it indicating that it’s linked to another folder… the folder that it’s linked to is in my dropbox called RhinoScripts… that folder stays in dropbox.

(once the link is made, you can work out of either folder… you can edit/delete/add new scripts to either folder… they’ll stay in sync as well as any other computers you have pointing at your dropbox.)


[Edit]

oh, wait… are you trying to use the first script up there or the second one? the first one creates Macros to python files located elsewhere on the system (besides the Scripts folder)…

if you use the second script, there’s really no need for the first one because you can then just make macros like -RunPythonScript Example

one other note that may need to be pointed out… to make a macro, you need to use the dashed version of the command… -RunPythonScript Example … or _-RunPythonScript Example

My typing and what is in my Alias are not the same.

Before running your script, from Dropbox … Finder tells me this.

After, it says link is created,

but no Scripts folder, with Alias / Symlink arrow is created.

I am using the second longer script, running it in rhino from from Dropbox to create a Symlink Folder so all I have to do is keep files in Dropbox and everything runs from default “Scripts” folder. Is this clear?

yep. thanks.

bummer, it works fine for me on 2 computers.

i’m wondering if there’s a problem creating a symlink to /Volumes/HD-1etc… ?

as a simple test, can you put a copy of your Rhino-PythonScripts folder on your desktop then using the script on that folder?


fwiw, my dropbox is located:

…and the symlink creates just fine.

No go, it says it is, but doesn’t create the “Scripts” folder. Tried it a few times.

Yes, bummer. I will try when I get to the office and see if it works there,

thanks

oh @rhinorudi

i think it’s failing because of the spaces in some of the names…
rs.BrowseForFolder is getting the path:

/Volumes/HD-1[SPACE]2013/Dropbox/Rhino-Python[SPACE]Scripts

…but the terminal commands would require slashes to deal with those spaces

HD-1\ 2013 and Rhino-Python\ Scripts


and i really don’t know how to deal with those spaces and adding slashes right now… plus i need to sleep :smile:

so unfortunately, i think it’s only going to work properly if there aren’t any spaces in the user or volume name …and no spaces in the folder names.

I am just off for morning commute. I will deal with “Spaces” in folder names and get back to you. Into my 5th espresso, enjoy your sleep. :grinning:

Works from Desktop without spaces …

:grin:

ok… cool.
i updated the script in the post to handle spaces in the path.

Great, works

Tried it here at work with the space in Rhino-Python Scripts.