How to modify referenced assemblies in a C# script component with another C# script component

Dear Experts,

I’m trying to figure out how i can modify referenced assemblies in a C# script component from within another C# script component.
Reason for this, is that together with Grasshopper I am also using an external software for which i have written some short C# scripts in Grasshopper.

The assemblies in my own written C# script are now only referencing to a specific version of the external software. This is what I would be able to modify, depending of which version of the external software I am using since the Namespaces, Classes etc. don’t usually change that much…

Modify assemblies.gh (6.8 KB)

I have figured out how to get the C# scripts of the Grasshopper document, but the type I get is ScriptComponents.Component_CSNET_Script. How can I get the Namespace for this?

B r, Kristoffer

Hello

you must have ScriptComponents.gha referenced in the component.

    foreach(var obj in GrasshopperDocument.Objects)
    {
      var script = obj as ScriptComponents.Component_AbstractScript;
      if ( script != null && script.NickName == "UniqueName" )
      {
        switch ( version )
        {
          case "1.0.0":
            path = "Path/to/version-1.0.0.dll";
            break;
          case "1.1.0":
            path = "Path/to/version-1.1.0.gha";
            break;
        }
        if ( !script.ScriptSource.References.Contains(path) )
        {
          script.ScriptSource.References.Add(path);
          script.ScriptAssembly = null;
          //script.ExpireSolution(true)
        }
      }
1 Like

Hello,

thanks for the reply and help.
I got it to work.(not as pretty as your solution, but it is working at least…)

Anyway, attached is the .gh file if anyone would find it helpful.

Modify assemblies.gh (14.6 KB)