I am interested in playing with program induction in Grasshopper.
The simplest way to do this, is to build grasshopper definitions via scripting. The examples in this discussion were really useful for me. However, the method ghdoc.AddObject requires a IGH_DocumentObject. While the class used in the example (gh.Kernel.Special) contains many of these type of objects, I could not find the respective objects for geometric functions, such as Construct Point or Line. I explored other spaces, such as gh.Kernel.Geometry, but the classes there (such as .Line2) are not IGH_DocumentObject. How can I find the right class of a certain component of GH to add to canvas using ghdoc.AddObject (or other similar method)?
If instead of scripting I decide to write the xml of my own GH files (with a limited set of components) from scratch, what would be a proper method? What would be the challenges?
If you want you can get visual studio, and then you can code in vb / c# / python and compile and test your components in VS + rhino and or grasshopper. If you are a student you may be able to get it for free.
Hi Arkadius, my goal is not to create components, but to create custom definitions - i.e. the graph with existing components connected. Thanks for your reply.
@johnharding’s Embryo project generates/evolves Grasshopper definitions. I bet you can dig up a lot of relevant nuggets on its github.
Thanks @AndersDeleuran for the ‘shout out’ (or whatever you call it these days).
There’s a special component in Embryo called TypeRevealer that I used to get the component names (I think… it was a while ago now). Just install the Embryo library and it’s in there.
That is exactly what I need. I am only having one problem. Any idea on how to access (via scripting) these modules where the components are located (in your example, the “CurveComponents”)? They are not available with import.
By the way, thanks for your reply, @ AndersDeleuran and @ johnharding. Koza’s text and John’s eCAADe paper that inspired me to develop an exercise with GP for our class.
So you can use metahopper and save the snippet?
this will save the selected portion of a definition for later use…
or am i not understanding you?
I am trying to generate grasshopper graphs using python scripting.
The challenge is to locate the component classes in the gh module. For example, the component class for the slider is “Grasshopper.Kernel.Special.GH_NumberSlider()”, which is accessible by scripting. However, the other classes are not in the same space, so it is tricky even to find something simple such as construct point.
Embryo project has a GH component called TypeRevealer that finds these classes, but it indicates spaces that might not be accessible via scripting without copying dll files to my folder. For example, in the image sent by @johnharding, the class for the component line is located at CurveComponents.Component_LineSDL.
Again, notice that I am not trying to execute the component LineSDL (which I can do with ghpythonlib.components or do something similar with Rhino.Python). My goal is to add the component to the canvas, as in the example of the link I posted in the beginning.
Many components live in referenced assemblies, like CurveComponents.GHA or TriangulationComponents.GHA. To reference these types you will need a reference to these libraries. On my system these assemblies live in
C:\Program Files\Rhino 6\Plug-ins\Grasshopper\Components. My IronPython is rusty but I believe you should be able to reference these just like any other external DLL.
Thanks, @ andheum. This solves my problem.
For reference (rimshot): Here’s how I’ve been referencing e.g. the
KangooSolver.dll (which lives in the same folder) since moving to Rhino 6:
import Grasshopper as gh
clr.AddReferenceToFileAndPath(gh.Folders.PluginFolder + "Components\KangarooSolver.dll")
import KangarooSolver as ks
ps = ks.PhysicalSystem()
You could also use
gh.Folders.AssemblyFolders to get to the Components folder directly. But that’s a bit less readable IMO, and you’ll have to cast it to a string.