Grasshopper

algorithmic modeling for Rhino

Hey guys!

The Question:

I have a mysql database of .gh files that are on this forum as attachments and would like to write a program to open those files and gather 'information' about each components active inputs and outputs (basically what it is connected to and what is connected to it). I've started going through the SDK and it sounds like I can upload the .gh file directly to the c# environment 'run' each one and get the input and output connections of each component. Does this sound right? Is there documentation someone can point me to of running a .gh program and gathering information about its components?

The Reason:

If I can manage to gather each components input and output connections I will apply an auto complete algorithm so users can turn it on and hover over an input or output and get a faded image of most common next pieces. As the number of components grows so does the need to find what you need more efficiently.

Thanks a lot for the help!

McK

Views: 1016

Replies to This Discussion

Hi McK,

it is possible to parse a gh file without using Rhino or Grasshopper. In fact, if you convert a file into ghx, you don't even need to use GH_IO.dll. You can traverse the file, looking for SourceCount and Source(i) entries. This will allow you to build a database of guids that are often linked together. In order to know what each Guid means though (i.e. which object it represents), you will need to start Grasshopper and have a look at the component database. 

The other possibility is to use Grasshopper to open the file, then use the SDK to figure out which objects are connected to which. This is probably the easier solution, though it is a more complicated process of course.

You can probably even add the mouse-hover-show-suggestions part by implementing your own Canvas Widget, but that will certainly be the hardest part.

--

David Rutten

david@mcneel.com

Poprad, Slovakia

Thanks David!

I think I am leaning toward going through the SDK and trading speed for ease (at first). I'm going to play with it a bit and familiarize myself more with the file structure and SDK and keep this thread going as I make progress.

Thanks!

McK

There's a class called Grasshopper.Kernel.GH_ConnectivityDiagram (GH_Documents can create one, use the CreateConnectivityDiagram() method), it's basically only the source/target relationships, so you don't have to deal with all the extra stuff.

--

David Rutten

david@mcneel.com

Poprad, Slovakia

@ McK I'm interested to see what progress you've made! I've had some luck parsing the xml with java (procesing) for a different purpose (translation of GH to processing) but the xml route is buggy. I'd like to be able to generate an array or hashmap of components and their connections from w/i GH.

@David - are there any examples you can show of the GH_ConnectivityDiagram Class in use? 

Thanks!

Chris

I use GH_ConnectivityDiagram and GH_ConnectivityDisparity classes only for clusters at the moment. And then only when a cluster is created from a selection. However I suppose it might be a somewhat useful class for the topic discussed here.

A connectivity diagram is a minimal representation of a Grasshopper file. It only contains objects that derive from IGH_Param (i.e no components, no weird objects like Groups or Scribbles). IGH_Param is the only object in Grasshopper that can be connected with wires to other objects. Components are basically loose conglomerations of a GH_Component object with a bunch of associated IGH_Param inputs and outputs.

It's fairly easy to quickly find the inputs and outputs (sources and recipients as they are called in Grasshopper SDK speak) of any parameter using a connectivity diagram. However since I wrote it with a very specific goal in mind there's a lot of stuff that you'd expect a diagram to be able to do that it in fact doesn't.

If you're only looking to gather statistics on what objects are connected to what other objects, then I think you don't need to use the connectivity diagram. You can just work directly with the GH_Document itself.

I attached a file which has a VB component with a ConnectivityDatabase class inside it that can both (de)serialize itself and collect statistics on connections within any document. Just copy-paste the panel and the VB component into any file you want to record statistics for and it will grow the database.

--

David Rutten

david@mcneel.com

Poprad, Slovakia

Attachments:

Hi David I've been looking through the script you sent (thanks!) and I think I'm beginning to understand the logic. I'd like to pull some additional parameters from the document object (like 'Name' and "Hidden" for example) and write them to the database. However the connections in this script are just focused on the Guid.

For Each source As IGH_Param In param.Sources
'Only record toplevel connections, we don't care much about actual parameter types.
Dim souceID As Guid = source.Attributes.GetTopLevel.DocObject.ComponentGuid
Dim targetID As Guid = param.Attributes.GetTopLevel.DocObject.ComponentGuid

AddConnection(souceID, targetID)
Next

Maybe there's an easy way to iterate over the whole model once in your AddConnection method and find objects with the given Guids? Thanks for all your help so far. 

Finding objects by Guid should be easy if you have a reference to the GH_Document that contains them. There's FindObject, FindParameter, FindComponent, FindAttributes... all functions which have overloads that accept IDs.

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