Python scripting and extension methods

I just discovered a nifty trick for accessing extension methods in (Iron)Python scripts. Namely, clr.ImportExtensions(). The example below leverages the extension methods that add Rhino/GH interoperability to Plankton.

"""Provides a scripting component.
        m: an input Rhino.Geometry.Mesh
        a: a bunch of face polylines"""

import clr
import Plankton
import PlanktonGh

# import class containing extension methods

# import mesh via Rhino.Geometry.Mesh extension method
pmesh = m.ToPlanktonMesh()

# TODO: do something exciting with our new halfedge mesh

# export polylines via Plankton.PlanktonMesh extension method
a = pmesh.ToPolylines()



@DanielPiker @AndersDeleuran @dave_stasiuk @mathias_gmachl

Excellent, there it is. Thanks for the heads-up. About time someone cracked that particular nut :wink:

Hi guys ,
i just copied the script in python component and i got this error :

Runtime error (IOException): Could not add reference to assembly Plankton.dll
line 8, in script

what should i do ?
where should i copy Plankton.dll ?

thank you for help .

Off the top of my head I had added the GH libraries folder to the Python
path in Rhino to make loading these assemblies less painful.

In Rhino 5, bring up the Python script editor (“EditPythonScript”), then go
to Tools > Options… and add %APPDATA%\Grasshopper\Libraries to the list
under the Files tab.

use this for any dll path:

import clr 

1 Like