How to add components to the canvas using Rhino Python

Have you checked this one?

Here is a small example for Rhino Python:
Farhad

import clr
clr.AddReferenceToFileAndPath(r"C:\Program Files\Rhino 7\Plug-ins\Grasshopper\Components\CurveComponents.gha")
from CurveComponents import Component_Polygon, Component_OffsetCurve
from Grasshopper import Instances
from System.Drawing import PointF
import rhinoscriptsyntax as rs
gh = rs.GetPlugInObject('Grasshopper')
if gh.IsEditorLoaded():
    doc = Instances.ActiveCanvas.Document
    if doc:
        polygon_comp = Component_Polygon()
        polygon_comp.CreateAttributes()
        polygon_comp.Attributes.Pivot = PointF(100, 100)
        doc.AddObject(polygon_comp, False)
        
        offset_comp = Component_OffsetCurve()
        offset_comp.CreateAttributes()
        offset_comp.Attributes.Pivot = PointF(200, 100)
        doc.AddObject(offset_comp, False)
        
        offset_comp.Params.Input[0].AddSource(polygon_comp.Params.Output[0])
        gh.RunSolver(True)

Farhad.py (915 Bytes)