Note: Though my question primarily arises from the lack of RhinoScript in Rhino for Mac, I’ve chosen to post in the Scripting forum because any solutions or discussion should be just as valid on either platform and is intended to be a question about Python, not “wait, how do I get this to work on the Mac”.
The question: What is the most straightforward way of creating multiple new commands/macros in Rhino using only Python?
Here’s the scenario, using Pascal Golay’s Project_Direction as an example.
Rhino.AddAlias "ProjectDir", "! _NoEcho _-Runscript ProjectDir" Rhino.AddAlias "ProjectView", "! _NoEcho _-Runscript ProjectView" Sub ProjectDir() Project(0) End Sub Sub ProjectView() Project(0) End Sub Sub Project(pdir) ' ...implementation... End Sub
# In Python we set the alias to launch the script # because -RunScript doesn't exist in v5 (at least on Mac Rhino). rs.AddAlias("ProjectDir", "! _NoEcho _-RunPythonScript Project_Direction") rs.AddAlias("ProjectView", "! _NoEcho _-RunPythonScript Project_Direction") def ProjectDir(): project(0) def ProjectView(): project(1) def project(pdir): # Implementation if __name__ == "__main__": # If this script contained only one function, we would call it here
My issues are as follows:
- There is no [documented] way to pass arguments to a script via RunPythonScript
- LastCommandName is the _NoEcho, and something like LastLastCommandName (via CommandHistory) isn’t very nice. Otherwise in the last statement we could write something like
if rs.LastCommandName == "ProjectView": ProjectView()
- The commands should be independent, i.e. not require a dialog, message, or prompt to take their argument (though I haven’t looked into whether this works on Mac Rhino either).
For immediate use, the simplest solution is probably to split each command up into its own file and then import them into a single module if required. For the sake of discussion though, I’m curious as to whether there are any other options as searching has turned up nil.