algorithmic modeling for Rhino

Is there anyone who has experience in using the PythonEditor to run a grasshopper file. 
I'm trying to generate information in grasshopper and once the first loop is done, change the values in the sliders and run the same process again. 
Unfortunately you can not backloop in grasshopper so i was told to use the PythonEditor.
But i can't find any examples of how to combine this with grasshopper. 



Views: 2418

Replies to This Discussion

Hi Tijl,

who told you to use the PythonEditor? It seems like you want to achieve something similar to Galapagos. Set a few slider values, run a solution, harvest data, repeat.

Grasshopper has a completely open SDK so this kind of stuff is definitely possible, but the easiest would be to do so from within Grasshopper. I.e. you can write an object (typically in C# or VB.NET) that sits inside the Grasshopper document and which can take control of the grasshopper solutions.

Which programming languages (apart from Python) are you familiar with?

David Rutten
Seattle, WA
Hi David,
Thanks for pointing me to Galapagos! As far as i can judge now it seems to be a very powerful tool! But for me at this point the tool is a little too advanced.
My idea works on pretty much the same ideas as Galapagos, but i would like to have the process something different.
My goal is to use grasshopper as a dataBase generator, without any optimization in it. And to have the system work through all the possibilities one by one, so no generic algorithms (yet). This is because i want to generate all the options possible and then start comparing the options.
One thing that galapagos does that i am looking into is the changing the sliders in accordance with the outcome. This 'backlooping' is very interesting for me, since i don't know how long the generating of data takes i can't do this with a timer. (i'll add my first try with a timer).
To 'hack' my way round this problem Giulio advised me to work with the EditPythonScript editor. (see his reaction below!) I'm now trying to understand his code and see if this works for me.
Unfortunately i don't have any other programming skills than Python, but managed to work with VB if a tutorial helps me converting the actions and keeping the code very simple and basic...

Thanks for your reaction!
Oh, I see that "theEngine" script is not working anymore with 0.8.3... it seems there has been a change in behavior in the Grasshopper SDK and I did not account for the possible change.

Please, if you use the new version, use this new file. Or check the new Grasshopper timer component.

- Giulio
McNeel Europe, Barcelona
I've been going trough some older posts and one of your comments is:

"But note that you're not supposed to update sliders while you're inside a solution. So if you're doing this from within GH_Component.SolveInstance, there's really no way this is valid, as you're expiring a slider while a solution is being computed." (

So i was wondering if it is wise to study the PythonEditor? Can i achieve my goal with this, or is this only to update the values once?
I do seem to have trouble with accessing the sliders and anything else but a rhino command.. (line, circle, point, etc)

So would it be possible to have a component like Galapagos, but then less fancy? Only adding 1 to a slider if the solution is ready? Continue doing this until the slider is at its max,
then that add 1 to an other slider(no2) if the first slider has reached its max, and start at min with the slider(no1) again??

see previous file where i do this with a timer.

Hi Tijl,

you can definitely code this up. Either from a Script component or as a GHA library. I'm happy to write something for you, but you'll need to tell me which language you're most comfortable with C# or VB? Script component or Visual Studio project?

David Rutten
Seattle, WA
Hi David,
Unfortunately i can only work with Python (until now). But it must be possible to learn C# as well (or at least some of the basics). Most people i work/study with, are very comfortable in C#.
I don't run Visual Studio, but work in eclipse most of the time (but this i only use for python, but can offcourse be useful for other languages).

I still want to go through your manual to learn how to learn how to script in Rhino. (RhinoScript101) so this will be my next step then.

If you could write something, that would be great!!



Hi Kirk,

how is this development going? If you still need some help, could you please start a new discussion? (this one is a bit old)


- Giulio
McNeel Europe

Hi Tijl,

it's a bit of code, but here is how you can do it. This sets a circle into Grasshopper and receives the result. Save the file on the desktop to test this. In the EditPythonScript editor:

import clr

import System
import Rhino
import Grasshopper
from Rhino import RhinoApp, RhinoDoc
from Rhino.Geometry import *

gh = RhinoApp.GetPlugInObject("Grasshopper")

docServer = Grasshopper.GH_InstanceServer.DocumentServer
doc = docServer[0] # first opened document

def FindBatteryByNickname(docObjects, name):
if docObjects is None: return None

for obj in docObjects:
attr = obj.Attributes
if attr.PathName == name:
return obj
raise Exception(name + " was not found in document")

param = FindBatteryByNickname(doc.Objects, "myBegin")
if param is not None:
newCircle = Circle(Point3d(1,11,111), 32)
param.AddPersistentData(newCircle) # you must add the right type here!
param.ExpireSolution(True) # recomputes the whole solution

param = FindBatteryByNickname(doc.Objects, "myResult")
if param is not None:
ghCircles = param.VolatileData # access persistent data as a tree
ghCircle = ghCircles[0][0] # a list of all grasshopper-types
#circle = ghCircle.Value # access the "real" circle
rhinoDoc = RhinoDoc.ActiveDoc
ghCircle.BakeGeometry(rhinoDoc, rhinoDoc.CreateDefaultAttributes(), System.Guid())

The file I had on the desktop is attached.
Also, you get autocompletion with types after using clr.AddReferenceByName the first time, which is pretty useful.

EDIT, 2020/Feb/19: Script edited to account for SDK changes.

- Giulio
McNeel Europe, Barcelona

Thanks for this piece of code! It seems that the last line lacks a small bit of information though. I haven't been able to replace or add this..
I'm trying to understand what is happening with this code and than change it so it suits my wishes!
Again thanks for all your help!

Sure, here the whole text in a file.

- Giulio
McNeel Europe, Barcelona
Thanks! Now its digging into the code and extending it to my wishes!




It has been a while, but back with questions again..

I've been trying to understand your script and adapt it in such a way that i can use it.

At the moment i seem to be able to change a few parameters, but other than lines, curves and circles have been difficult.  No idea how to change a slider or move component yet. (is there any way to find their names or what code to use?)


All i try now is to change the length of a line and draw a circle at the end. Once the circle is drawn, i want to measure the radius and if this radius is not the previous radius length it should continue with the loop and add a line.


I'll add my grasshopper file and code.

Do you know how i can make this last step??


Thanks for your help!









  • Add Photos
  • View All


  • Add Videos
  • View All

© 2021   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service