-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathQuerySelectedGhComponent.cs
More file actions
41 lines (35 loc) · 962 Bytes
/
QuerySelectedGhComponent.cs
File metadata and controls
41 lines (35 loc) · 962 Bytes
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
// #! csharp
#r "nuget: Neo4j.Driver, 5.28.3"
using System;
using System.Linq;
using Rhino;
using Rhino.Commands;
using Grasshopper;
using Grasshopper.Kernel;
using Grasshopper.GUI.Canvas;
// Get the Grasshopper plugin instance
var gh = Grasshopper.Instances.ActiveCanvas;
if (gh == null)
{
RhinoApp.WriteLine("Grasshopper is not running.");
return Result.Failure;
}
var ghDoc = gh.Document;
if (ghDoc == null)
{
RhinoApp.WriteLine("No Grasshopper document is open.");
return Result.Failure;
}
// Get all selected objects in the Grasshopper document
var selectedObjects = ghDoc.SelectedObjects();
if (selectedObjects.Count == 0)
{
RhinoApp.WriteLine("No components are selected in Grasshopper.");
return Result.Success;
}
RhinoApp.WriteLine("Selected Grasshopper components:");
foreach (var obj in selectedObjects.OfType<IGH_Component>())
{
RhinoApp.WriteLine($"- {obj.Name} (ID: {obj.InstanceGuid})");
}
return Result.Success;