Grasshopper

algorithmic modeling for Rhino

I am interested in rewriting the Quick Graph component so it could accept x and y-value inputs, that is, for example, a list of temperatures for the y-axis, while the x-axis would be the time of the day. I was wondering what type of libraries with C# do I need in order to do this? I have never really dabbled with graphics before, so most help would be appreciated. Thank you.

Views: 1284

Replies to This Discussion

Hi Jacky,

Grasshopper uses GDI+ to draw everything on the canvas. If you want to draw custom geometry on the canvas (like QuickGraph) then you need to import the System.Drawing namespace. If you want to draw inside Rhino viewports, then you only need a RhinoCommon.dll reference

Important things to know about GDI+:

  • You always draw using a System.Drawing.Graphics object. This object may point to a Bitmap, or a window, or a control or, or or.... you shouldn't have to care what the ultimate destination of the pixels is.
  • System.Drawing.Graphics exposes several drawing functions. There's easy ones (lines, polylines, rectangles, beziers, ellipses/circles and ellipticalsegments/arcs) and more involved ones (GraphicsPath and Region).
  • When drawing line geometry you need to create a Pen object. A Pen defined the colour, thickness, dashpattern, caps and line-join properties of the geometry you're drawing.
  • When filling shapes, you need to create a Brush object. There are several types of brushes (Solid, Gradient, PathGradient, Hatch and Texture).
  • Always always always dispose of any pens, brushes or graphicspaths you create.
  • Grasshopper also provides several functions for drawing Grasshopper specific shapes, so when you have a specific problem be sure to ask it here to see if there's an easy solution already available.

--

David Rutten

david@mcneel.com

What you do is create custom attributes for your parameter/component. Attributes are responsible for drawing the object on the canvas and for handling all the mouse-events. If you do not create custom attributes then your object will be given default attributes.

There's an example of overriding attributes in the SDK documentation, you can start there. Do note that overriding attributes for a component is much, much harder than overriding them for a parameter. But a parameter can only have a single input and output, so that may not be an option.

Examples of components that have custom attributes in Grasshopper are Gradient and Legend.

--

David Rutten

david@mcneel.com

My IDE is screaming at me for this: http://puu.sh/5o1Li/979ee3dbdb.png

Your IDE is trying to tell you something ;-). Try replacing the fourth parameter with "GH_ParamAccess.item".

Go through the errors, one by one, and really read them.

I will give you one hint though, when calling "DA.GetData", try working with non-grasshopper types (i.e. bool, not GH_Boolean).

p.s. For more up to date help developing a custom component, try searching for "Simple Component (C#)" in the "Examples" section of the SDK.

Run the "GrasshopperGetSDKDocumentation" command in Rhino.

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