python development environments
I started looking at python and rhino (win7) recently and had some questions regarding which python development environment is recommended. It looks like there are 3 ways:
This brings up the python shell allows me to write python scripts outside with my favorite text editor. If I do
then I can import my python scripts and then call them from the python shell. It's great. But I find that when the python shell is active, I am not able to select rhino objects. I can select objects only after exiting the python shell. I feel most comfortable with this but seems painful to go back and forth all the time.
This brings up the built-in IDE. Do I have to edit the scripts in the editor provided? Can I import scripts? How do I add a command similar to what's described in http://python.rhino3d.com/threads/27-Add-a-command but for the windows 7 environment? How would I import other modules like gecode (http://pypi.python.org/pypi/gecode-python/) into it?
3. Rhino.python for grasshopper
This allows me to embed python scripts inside grasshopper. This looks useful for creating knobs and sliders GUI to attach to my python scripts but it seems this would be useful most likely for small/medium python scripts before the run time becomes an issue. Grasshopper looks cool but for complex programming I would prefer to implement it textually so I can use some SCM and IDE, etc.
So, I'm leaning towards #2. Thanks for your suggestions and comments.
welcome to the forum.
Yes, the _EditPythonScript editor is the place where we write most scripts to automate specific tasks. I've answered some general questions I had, too, about the environment here:
On the other hand, you can use the interactive editor and the GhPython component to test some code quickly with different values. The idea is that the code can run mostly unchanged.
>>Do I have to edit the scripts in the editor provided?
Not really, you can use any text or code editor, even Notepad (I would not recommend that editor for this task though).
>>Can I import scripts?
If you mean modules, the answer is yes. Also if you mean reading text, the answer is yes. All you need to make sure to import modules, as you already noticed, is that the path to it can be found by the runtime.
About the question of commands, I'd say that it is supposed to work also on Windows. I haven't looked too carefully into that lately, though. The idea for the release of Rhino.Python is surely to have that working.
>>How would I import other modules like gecode into it?
1) Make sure that the path can be found 2) Type "import ..." or any other normal Python import statement
The example you provided is a big exception, though. gecode is not written in Python, so it cannot be referred to as a "Python module" only, it is a wrapper/binding module to a C++ library. Rhino currently uses a .Net implementation of Python, called IronPython, to be able to execute its code both on Windows and on Mac. To make the story short, this means that we cannot import gecode easily, just as we would do with normal Python modules, because the C++ part is not meant for the Python runtime used in Rhino.
Does this help, at least a little?
Thanks for taking the time to respond. They were very helpful indeed.
Regarding gecode, would it work if I provided a DLL? Perhaps someone has tried this with other packages, and not particularly gecode.
The only way to access gecode would be if there were a .NET binding for the C++ library. Anything in .NET can be access by python in Rhino.
Thanks Steve. I'll start down the path of compiling gecode with visual studio 2010 (?), and share what I find.
You might want to look around and see if someone else has already started writing .NET bindings for this library.