Gh chunk - finding the plugin that object belongs to

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?

did you “try” and “exception”?
this might prevents from crashing and diverses the two cases of “Lib” existing or not.

Hi Aleksanderdynarek
You can use reflection to get the component from which plugin.like this


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;
1 Like

thank you guys! try and catch solved the problem :slight_smile: i was not used to using this

1 Like