Grasshopper

algorithmic modeling for Rhino

Im curious to know if there is a way to read .ghcluster files outside of grasshopper (i.e. any programming language/environment such as python,vb,etc) for the purpose of documenting tools I've made. Obviously the file format isn't "human readable" but is there a way to convert and get information from it such as:

input names and descriptions

author

cluster name

output names and descriptions

If there was a streamlined way to self document programmatically, I'm sure many people would share their creations (I know I would really love to know if this is possible)

Views: 870

Replies to This Discussion

You can use GH_IO.dll to open almost any file grasshopper produces. It'll give you a typesafe hierarchical dictionary representing the file, and you can always save to xml if you prefer that format.

Ah very nice. I see the fileviewer.exe also is a gui for this too. Now Im guessing it might be easiest to create a script component in grasshopper to read a folder (series of files), and parse,then output accordingly.

Is there a ghPython example perhaps that implements the GH_IO.dll? I'm most familiar with python. thanks!

I figured it out! Yay. Now Im curious how to create a "capsule" preview jpg or some kind of bitmap with inputs and outputs etc simlar to the typical cluster/component:


is this possible with the grasshopper SDK? thanks! this is going great.

Sort of, you either have to draw it yourself, but you can use the GH_Capsule class to help out with the boxes, or you can actually instantiate a component with the correct inputs/outputs and have it render itself into the graphics context of your choice. It may mean you need to be running inside Rhino though, I'm not entirely sure.

I saw the GH_capsule class, but once created how do I convert from GH_capsule instance to bitmap of some sort? I didn't see any methods that would do this.

You don't convert from GH_Capsule into Bitmap, you create a new Bitmap, associate a new Graphics object with that bitmap, then create a capsule and render it into the graphics context.

What is the code to instantiate a component? I see "gh.Kernel.Attributes.GH_ComponentAttributes.RenderComponentCapsule()" but I'm having issues instantiating it/ reading in a file to it. Any code samples?

New components can be created using standard constuctors, or you can use the GH_ComponentServer.EmitXXX() methods to create them (that is the preferred method).

Once you have a new component, you must make sure it has attributes, I think the method is called CreateAttributes(). Then, you can layout the attributes, position them at the correct location and render. It's all pretty involved, and it turns out you need an actual GH_Canvas for a component to render itself into. I'm trying to see if I can make it work.

Not having too much luck, for some reason the component only renders as a blank box...

Is this something you need to do on client machines, or are you only looking to create these images once? If so, you may be able to just automate capturing images from the real canvas.

Attachments:

Hmm thats an interesting example! Im trying to read a cluster from a file path ("C:\Users\cjm\Desktop\test.ghcluster") rather than an existing element on the canvas.

I get using the gh_io namespace with external files, but not sure how to utilize the gh_componentserver or gh_component class to grab  the external cluster into a guid or something transferrable like in your example. how might this be done?

Mm I guess to be more clear, Ill attach my file and a screenshot. Im using ghPython and i've had success with the gh_capsule to jpg. But it doesn't get me the black strip and I guess to put the nodes and labels it would have to be "manually" calculated which is a pain.

 if there is a way to emulate the "typical inparam,outparam, clusterName on black strip" capsule, maybe th
at would be the easiest. Hopefully my file will help explain my desired use case.

Attachments:

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2025   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service