YAK package manager and Python Grasshopper

Hello,

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.

Thank you.

Hey @Petras_Vestartas ,

You should be able to dynamically add a reference like below.

import clr
import sys
sys.path.append("<dllpath>")
clr.AddReferenceByName("<dllname>.dll")

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.

– cs

1 Like

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’m not as fond of this, but would os.cwd() work?

Nope:
Error: Runtime error (MissingMemberException): ‘module’ object has no attribute ‘cwd’

Could you share the plugin, or a replicated example so I can test some things on my end? :blush:
I’d really love to have this one solved for you
– cs

Hi,

Following are the instructions for installation:

Rhino Installation

This component references the .dll, all of them are user-objects, meaning you can open the contents by double-click:

Thank you for helping me out :slight_smile:

Hello again @Petras_Vestartas,

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 :woman_shrugging:.

1 Like

Thank you very much, even it is not a straight forward solution, it works, and that is the most important :slight_smile:

I will check this on Mac too