Hello everyone,
I wrote a C# code (R8) in order to find the plugins used in a canvas. It works quite well although to make it update from time to time I have to attached a trigger. I wonder if there is a way to do the same but using events as @sonderskovmathias did for the grouping template.
// Grasshopper Script Instance
using System;
using System.IO;
using System.Collections.Generic;
using Grasshopper.Kernel;
using Rhino;
using Rhino.Geometry;
public class Script_Instance : GH_ScriptInstance
{
private void RunScript(ref object Disallowed_Plugins)
{
// --- Plugin Checking ---
var plugins = new Dictionary<string, string>();
var Allowed_Plugins = new List<string> { "MetaHopper", "Grasshopper-Tekla Link 2024.1.17" };
var Different_Plugins = new List<string>();
// Access the Grasshopper document from the script context
var components = this.Component.OnPingDocument().Objects;
foreach (var obj in components)
{
if (obj is IGH_Component component)
{
var plugin = Grasshopper.Instances.ComponentServer.FindAssemblyByObject(component.ComponentGuid);
if (plugin?.IsCoreLibrary == false &&
!string.IsNullOrEmpty(plugin.Name) &&
plugin.Version != null &&
!plugin.Name.StartsWith("Rhino"))
{
plugins[plugin.Name] = plugin.Version.ToString();
}
}
}
// If no plugins found, set Disallowed_Plugins to "No plugins used"
if (plugins.Count == 0)
{
Disallowed_Plugins = "No plugins used";
}
else
{
foreach (var plugin in plugins)
{
if (!Allowed_Plugins.Contains(plugin.Key))
{
Different_Plugins.Add(plugin.Key);
}
}
Disallowed_Plugins = Different_Plugins.Count == 0 ? "No disallowed plugins used" : Different_Plugins;
}
}
}
Regards!