It’s also possible to add components using their GUIDs’, Here is another example using InstantiateNewObject.
import rhinoscriptsyntax as rs
import clr
from Grasshopper import Instances, Kernel
from System import Guid, Drawing
polygon_component_id = '845527a6-5cea-4ae9-a667-96ae1667a4e8'
offset_instance_id = '2eeaae3b-3de0-4d80-9707-29d7b9a60700'
gh = rs.GetPlugInObject('Grasshopper')
if gh.IsEditorLoaded():
canvas = Instances.ActiveCanvas
if canvas:
canvas.InstantiateNewObject(Guid(polygon_component_id), Drawing.PointF(100,100), True)
polygon_comp = canvas.Document.Objects[canvas.Document.Objects.Count-1]
offset_comp = canvas.Document.FindObject(Guid(offset_instance_id), True)
offset_comp.Params.Input[0].AddSource(polygon_comp.Params.Output[0])
gh.RunSolver(True)
In this example I tried to show how you can do that, obviously you need to know the Instance GUID of the target object; Here is a small C# components that helps you find this kind of information:
GUID.gh (3.2 KB)