The two methods I’ve been going with for implementing .NET assemblies in GHPython (Kangaroo2, Plankton etc) has been:
-
Assuming the path where the .dll file lives is already in the Rhino Python path. Which can be either hardcoded through the
editpythonscripteditor
options menu, or defined in the code using thesys.path.append()
method. -
Assuming the .dll file lives in the default Grasshopper libraries folder. Get this path, append the assembly name onto it and reference the full path plus filename (this is neat in that it should work across all systems and requires no fiddling with the
editpythonscripteditor
or manual referencing like with the C# script editor).
Example 1:
import clr
clr.AddReferenceToFile("KangarooSolver.dll")
import KangarooSolver as ks
Example 2:
import clr
import Grasshopper as gh
clr.AddReferenceToFileAndPath(gh.Folders.DefaultAssemblyFolder + "KangarooSolver.dll")
import KangarooSolver as ks
Both these methods should circumvent any .dll hellishness, especially the latter as it can only point to one unique file.