I would like to use the Plankton Mesh library inside of GHPython. I know that you can use it in C# by Using PlanktonGH, however trying to import PlanktonGH in Python unfortunately doesn’t work the same way. Plankton.dll and PlanktonGh.dll are both installed inside my components folder.
Is this at all possible? I would be interested in some half edge mesh methods.
Would you by any chance also know how to convert a Rhino mesh into a plankton one in Python?
The plankton documentation shows that the PlanktonGh library has a method, called ToPlanktonMesh(source) inside its RhinoSupport class.
However, I’m unable to call it in Python. It gives me a read-only error, when I’m trying to initialise an plankton mesh.
Here’s what I’m trying to do:
import Grasshopper as gh
if gh.Folders.DefaultAssemblyFolder not in sys.path:
pm = PlanktonGh.PlanktonMesh() # initialise plankton mesh
pm.ToPlanktonMesh(mesh_plane) # mesh input from grasshopper to plankton mesh
I’m kinda lost here. Unfortunately, I’m not that familiar with C# and dll files. My guess would be that the read-only error stems from methods being private in C#, but ToPlanktonMesh(source) seems to be public.
import rhinoscriptsyntax as rs
from os import path
plankton_dir = "path/to/folder/with/plankton"
m1 = x.ToPlanktonMesh()
Note a few things:
The Plankton namespace is in Plankton.dll and contains the mesh data structure
The PlanktonGh namespace is in Plankton.gha and contains Grasshopper components and helper methods
There are a bunch of extension methods in PlanktonGh.RhinoSupport. These add methods to RhinoCommon classes, such as Rhino.Geometry.Mesh.ToPlanktonMesh() and can be used in python after calling clr.ImportExtensions(PlanktonGh.RhinoSupport).
I’m using clr.AddReferenceToFileAndPath() but your script above should work the same.
Is there a current C# example of converting an input mesh to PlanktonMesh? I referenced the assembly Plankton.dll and added the line using Plankton, but couldn’t call the extension method ToPlanktonMesh(). Also tried renaming the Plankton.gha to PlantonGH.dll and then added using PlanktonGH with no success either. Thanks for the help!
I’ve included an example C# script that references both Plankton.dll and Plankton.gha and uses the Mesh.ToPlanktonMesh() extension method. I think the reason this wasn’t working for you is that you used using PlanktonGH; instead of using PlanktonGh; (note the lower case “h”).
I’ve also included an example C# script that manually constructs a PlanktonMesh from a Rhino Mesh and supports NGons (this wasn’t available when Plankton was written).
By the way, you’re right, you can reference .gha assemblies in C# scripts without renaming them to .dll first. Here’s how…
Hi Will, it works, thank you very much for the multiple examples!
I have one additional question as illustrated in the screenshot below. This error actually only happened when I added the reference files initially, and disappeared when I tried to delete them in the “manage assembly” popup and added them back again.
I think Plankton.gha is causing the error as the other two scripts seem to work fine when only Plankton.dll is referenced? It seems to have to do with how now Kanagroo is placed somewhere else as discussed below?