I have a Grasshopper plugin structured as follows:
a) It is written in the IronPython language.
b) The plugin consists of user objects as components.
c) These components utilize a compiled .dll file, which is accessed using ctypes.
Now, my question is:
At present, I have to manually specify the path to the .dll file using EditPythonScript. Is there a way to automate this process? Specifically, does the path of the plugin installed via YAK get automatically added to the module path?
Since each PC has a different path, locating the YAK path is not a straightforward task.
I’m not exactly sure how all of this works in Rhino/Grasshopper but you should be able to get the files absolute location with __file__ , and get the directory of this to pass into the above code.
The file does not work and I really do not want to specify dllpath manually each time. It would be awesome if the yak plugin installation folder would be added to python search paths. Apparently it is not.
I spent a good while looking into this, I’m not too familiar with python gh components, but I’ve certainly learnt some things. I cannot find a way to get a path to a .ghuser component. Is there any reason not to compile components into .ghpy? They seem to have IDs which seems handy.
My only solution is something like this:
import os
import sys
import clr
app_data = os.getenv('APPDATA')
vers = Rhino.RhinoApp.Version.Major
plugin_name = 'compas_wood'
plugin_path = "{0}\McNeel\Rhinoceros\packages\{1}.0\{2}".format(app_data, vers, plugin_name)
print plugin_path
for _path in os.walk(plugin_path):
if os.path.isdir(_path[0]):
print _path[0]
sys.path.append(_path[0])
for _file in _path[2]:
if _file.endswith('.dll'):
print _file
cdll.LoadLibrary(_file)
I’m not too satisfied with this however, and I’m also not currently on a mac so I can’t test this on that.
But Rhino packages are a consistent path so this might be safe .