Hello
How to add circle on canvas with Python?, I find this code from old grasshopper forum but i can’t make it work in Python
private void RunScript(bool add, ref object A)
{
if (add) {
// Create object and add to document
GH_Document activeDoc = Grasshopper.Instances.ActiveCanvas.Document;
MyComponent mfc = new MyComponent();
activeDoc.AddObject(mfc, false, 0);
}
}
// <Custom additional code>
public class MyComponent : GH_Component
{
public MyComponent()
: base("MyFirst", "MFC", "My first component", "Extra", "Simple")
{
}
public override Guid ComponentGuid
{
get { return new Guid("{9C534DC9-DD49-4950-BD2D-D8C45726A46E}"); }
}
protected override void RegisterInputParams(GH_Component.GH_InputParamManager pManager)
{
}
protected override void RegisterOutputParams(GH_Component.GH_OutputParamManager pManager)
{
}
protected override void SolveInstance(IGH_DataAccess DA)
{
}
public override void CreateAttributes()
{
{
this.m_attributes = (IGH_Attributes) new MyAttributes(this);
}
}
}
public class MyAttributes : Grasshopper.Kernel.Attributes.GH_ComponentAttributes
{
public MyAttributes(MyComponent owner) :
base(owner)
{
}
protected override void Render(Grasshopper.GUI.Canvas.GH_Canvas canvas, System.Drawing.Graphics graphics,
Grasshopper.GUI.Canvas.GH_CanvasChannel channel)
{
base.Render(canvas, graphics, channel);
if (channel != Grasshopper.GUI.Canvas.GH_CanvasChannel.Objects)
return;
System.Drawing.PointF p = this.Pivot;
System.Drawing.Pen pen = new System.Drawing.Pen(System.Drawing.Brushes.AliceBlue);
graphics.DrawEllipse(pen, 100, 100, 20, 20);
graphics.FillEllipse(System.Drawing.Brushes.Brown, 100, 100, 20, 20);
}
}
add_circle_to_canvas.gh (4.6 KB)