Grasshopper

algorithmic modeling for Rhino

Call python module rhinoscriptsyntax from a external interpreter

Hi all!

I was wondering whether there is a way to call a python script, which imports rhinoscriptsyntax, from OUTSIDE Rhinoceros. I know that Rhinoceros includes a Python interpreter but, as Steve Baer told here, "Rhino doesn't ship with a console program that would let you run python scripts from the command line".

I have installed IronPython in my PC and I have tried to "move" rhinoscriptsyntax.py to the ironPython module folder but, unfortunately, I could not find such rhinoscriptsyntax.py in the Rhinoceros installation.

Finally I have installed Grasshopper and ghpython hoping that I could use it from the MS-DOS window, but I do not know how to do it.

The reason to execute a python script from MS-DOS is that my program have to call Rhinoceros inside a loop to generate geometry at the beginning of each iteration. The only way I know to do that is to write:

Rhino /nosplash /runscript="!_-RunPythonScript "file.py""

where file.py changes in every iteration. But the latter command will open Rhinoceros in each iteration, making my program very slow.

Thanks in advance,

Fran Pena

Views: 4357

Replies to This Discussion

Hi Fran,

From what you have said, it is difficult to see a solution for you. It sounds like you are doing something in a way that is much more difficult than it needs to be. If you'd like help, you should describe the task you are trying to accomplish. People may have suggestions for how to make the task much easier, and even to avoid using IronPython outside of Rhino. What are you doing in "file.py" that requires you to run it from the command line? Why are you running a script that changes another script?

Two possible things to look at which may help: 

  1. you can run command line scripts from Rhino, and receive information back (I used this to run CPython from Rhino).
  2. you can store data in many ways, and open and close files as needed, without closing and opening Rhino.
  3. Post the script itself and explain what you are trying to do, then everyone can help you find the easiest way to solve the problem.

Hi Benjamin,

Thanks you for your kind advise. Here is the problem: I have to deal with an optimization problem; basically, I have to run an iterative process where, in each iteration, I have to create

  1. a  file with the geometry using Rhino and then,
  2. call a numerical simulation package, Salome + Code Aster, to evaluate a cost function;
  3. finally, an optimization algorithm decides the new geometry to try with.

My first guess was to create a python script containing the iterative process and call it from MS-DOS; your idea of running the whole program inside Rhino can work, but only if Salome + CA does not have a requirement similar to Rhino (I still have to investigate that point). Maybe, a python script in Salome can be called from outside Salome, in a similar way Rhino is called with the command:

Rhino /nosplash /runscript="!_-RunPythonScript "file.py""

But these could imply that a graphical window is opened in each iteration and, since the whole process can involve several hundred iterations, the time to open and close a graphical window in each iteration is not negligible.

Of course, the possibility to access to the rhinoscriptsyntax module is still the best solution for me since:

  1. I can retain the control of the program (for example, imagine that my python script needs to call an external module that the Rhino Python does not recognize...);
  2. There is no time consumed in opening a graphical window.

Thank you in advance for any suggestion you have. 

Sincerely,

Fran Pena

Here's what I would try, in your situation:

  • Make a script in IronPython, not Rhino.
  • Run it from the command line.
  • Don't try to import rhinoscriptsyntax, but use RhinoCommon instead. rhinooscriptsyntax focuses on using an open Rhino document, while RhinoCommon is a set of classes that you can use to build geometry.
  • Don't move the RhinoCommon DLL, just use the necessary file paths to import it.
  • Import Geometry classes from RhinoCommon, and use them to build the models that you need.
  • Store your geometry using cPickle, rather than creating Rhino documents.

I would also see if Salome + CA can be run on command line (it appears likely). If so, I would create one script in Rhino that runs the whole thing, and calls external python scripts to run analysis in Salome + CA. I would still store geometry using cPickle.

I'm not sure if either of these will work, but that's how I would approach it. I hope this helps.

-Ben

Hi Benjamin,

your approach seems promising. Let me try and I'll tell you about.

Sincerely,

Fran Pena

Did the proposed approach work for you?▼ Reply

RSS

About

Translate

Search

Photos

  • Add Photos
  • View All

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service