I am writing small code that analyses components used in grasshopper definition. I am using Gh_Archive as in this example
Thing is, i need to iterate through all objects used in definition and display (and count etc) only ones belonging to particular plugin . How to do that? Using Grasshopper File Viewer I found out that every object chunk that is belonging to custom plugin, not a native one, has not only GUID and Name in its hierarchy but also Lib, which points to the plugin used (i think so?). But when i am trying to (chunk.GetGuid(“Lib”) or (chunk.GetString(“Lib”) all program crashes. I guess its because most native objects dont have “Lib”, so there is an empty reference pointer. How to do that?
using System.Linq;
using System.IO;
var ghObjs = this.Component.OnPingDocument().Objects;
A = ghObjs.Select(obj => obj.GetType().Assembly.Location).Select(p => Path.GetFileNameWithoutExtension(p));
You may need to get Libraries loaded by Grasshopper.
var ghaLibrary = Grasshopper.Instances.ComponentServer.Libraries;
A = ghaLibrary;