thanks for your amazing work!
I’m currently compiling a script that uses some additional .NET .dlls referenced via clr.AddReference().
This works fine as long as the referenced dlls are kept directly in the Libraries directory, however if they are put into an additional folder, they are no longer accessible.
Can I check directly from the script for the path from which the compiled .ghpy is loaded, so I could add it to the sys.path? Quite possibly a noob question.
please start new topics for new conversations. You are entitled!
As far as I understand (this is an IronPython topic, not a Rhino topic, really, per se), sys.path is not used for clr.AddReference, because that is for a .Net assembly, not for a Python package/module.
However, when searching for a reference fails, Rhino is still invoking its own assembly resolver. That one automatically looks into all folders where a plug-in is installed, including the Libraries folder. @will might know more, as I know he has been making adjustments to that lately.
In the clr namespace there are other overloads, like clr.AddReferenceToFileAndPath(), etc. You might need to find the right system that works for your particular installation goal.
My goal is to have the .dlls loaded, as long as they are in the same directory as .ghpy itself.
The reason for it is that from my experience Library forder can get quite crowded and users tend to sort various Plug-ins themself to separate folders. Setup where one folder in Library contains all dependencies and .ghpys for each plug-in seems preferable to me, since it’s harder lose some files by accident.
Anyway, now I tried shoving the .dlls into “…\Rhino 6\Plug-ins\IronPython”, which at least conviently hides them from any careless users that could move or delete them from Libraries by accident, and there are always accesible from clr.AddReference().
Are there any obvious disadvantages to that aproach?
this needs to happen after the component has loaded. So make sure the clr code happens only at request (not when GH loads). To set your component ID as a fixed value, you will need to compile the code yourself, copying the code to the clipboard.
Then, construct the right path and use clr.AddReferenceToFileAndPath().
I hope this helps,
The downside is that this way, you have to import inside every component, instead of importing just once.
There’s also a sort of a hack to this problem.
From my testing, clr.AddReference() will be able to always find the .dll, if there is any .gha assembly loaded from it’s path.
I guess you could create some dummy .gha assembly just to add the reference and distribute it with your .ghpy.
Best regards and thanks again Giulio!
Btw.: What about GhPython.Assemblies.PythonAssemblyInfo.Location? Couldn’t this be used to access the path on GH load?