Drawing a Sketch Object from C#

Hey everyone,

I am trying to develop a plugin for grasshopper. I have been searching for a way to draw Sketch Objects (the freehand strokes on the canvas) from C#, as i would like to draw something like a rectangle for example. I have not yet found a way to do this - any ideas?

I am aware this might not be the best way and maybe i should just draw it using graphics.DrawRectangle(), but using Sketch Objects is probably easier as there is already a way of interacting with them in gh (for example for changing the linetype etc).

Thanks in advance!

It was pretty tricky to find out!
This is a small example, but you should be able to expand it from here:

2023-09-13 01_32_29-Window
GH_Markup sketch V0.1.gh (2.6 KB)

Grasshopper.Kernel.Special.GH_Markup mark = new Grasshopper.Kernel.Special.GH_Markup();
mark.CreateAttributes();
Grasshopper.Kernel.Special.GH_MarkupProperties prop = new Grasshopper.Kernel.Special.GH_MarkupProperties();
prop.Colour = System.Drawing.Color.Lime;
prop.Width = 5f;
prop.Pattern = Grasshopper.Kernel.Special.GH_MarkupDashPattern.Dot;
((Grasshopper.Kernel.Special.GH_MarkupAttributes) mark.Attributes).Properties = prop;
mark.Attributes.Pivot = new System.Drawing.PointF(50, 50);
Polyline poly = new Polyline();
poly.Add(00, 00, 0);
poly.Add(30, 00, 0);
poly.Add(30, 40, 0);
poly.Add(00, 00, 0);
mark.Marks.Add(poly);
this.GrasshopperDocument.AddObject(mark, false);
8 Likes

works perfectly, thank you so much!

may i ask where you found this? i had been looking for it without success

Trial and error, exploring all the sub methods/types in the main libraries through simple auto-completion in c# script in gh… XD

Something that is currently impossible on WIP :smiling_face_with_tear: and probably will be like this for a long time since beta has come
… farewell easy developing days!

1 Like