-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathQuerySelectedGhComponentToGraph.cs
More file actions
51 lines (44 loc) · 1.41 KB
/
QuerySelectedGhComponentToGraph.cs
File metadata and controls
51 lines (44 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
using System;
using System.Collections.Generic;
using System.Linq;
using Rhino;
using Grasshopper;
using Grasshopper.Kernel;
using GraphHop2.Utilities;
//Query list of connection to list of tuples (source component document object, target component document object)
void RunScript()
{
if (Grasshopper.Instances.ActiveCanvas == null)
{
RhinoApp.WriteLine("Grasshopper is not loaded or no canvas is active!");
return;
}
var ghDoc = Grasshopper.Instances.ActiveCanvas.Document;
if (ghDoc == null)
{
RhinoApp.WriteLine("No active Grasshopper document found!");
return;
}
var selectedObjects = ghDoc.SelectedObjects();
if (selectedObjects.Count == 0)
{
RhinoApp.WriteLine("No Grasshopper components selected!");
return;
}
var connections = SelectionToGraphUtility.GetConnections(selectedObjects);
if (connections.Count == 0)
{
RhinoApp.WriteLine("No connections found for selected components.");
}
else
{
RhinoApp.WriteLine("Connections (source -> target):");
foreach (var pair in connections)
{
string srcName = pair.Item1?.GetType().Name + ": " + (pair.Item1 as IGH_Component)?.Name;
string tgtName = pair.Item2?.GetType().Name + ": " + (pair.Item2 as IGH_Component)?.Name;
RhinoApp.WriteLine($"({srcName}) -> ({tgtName})");
}
}
}
RunScript();