Closed goswinr closed 6 years ago
Hey @goswinr, sorry for the delay in replying!
Here's a working example, using Plankton via a RhinoPython script to generate a dual mesh...
import clr
import os
import rhinoscriptsyntax as rs
from Rhino.Commands import Result
from Rhino.DocObjects import ObjectType
from Rhino.Input.Custom import GetObject, GeometryAttributeFilter
from scriptcontext import doc
# get path to Grasshopper "Libraries" dir
clr.AddReferenceByName('Grasshopper')
import Grasshopper
lib_dir = Grasshopper.Folders.DefaultAssemblyFolder
# import Plankton (assuming the files are in the Grasshopper "Libraries" dir)
clr.AddReferenceToFileAndPath(os.path.join(lib_dir, "Plankton.dll"))
import Plankton
# import Plankton.gha (contains extension methods which convert to/from RhinoCommon types)
clr.AddReferenceToFileAndPath(os.path.join(lib_dir, "Plankton.gha"))
import PlanktonGh
clr.ImportExtensions(PlanktonGh.RhinoSupport)
def RunCommand():
gm = GetObject()
gm.SetCommandPrompt("Select manifold mesh")
gm.GeometryFilter = ObjectType.Mesh
gm.Get()
if gm.CommandResult() != Result.Success:
return Result.Failure
mesh = gm.Object(0).Mesh()
if mesh == None:
return Result.Failure
# TODO: check that mesh is manifold and fully welded
# convert rhino mesh to plankton mesh
pmesh = mesh.ToPlanktonMesh() # extension method
# dual mesh and "bake"
dual = pmesh.Dual()
doc.Objects.AddMesh(dual.ToRhinoMesh())
doc.Views.Redraw()
return Result.Success
if __name__ == "__main__":
RunCommand()
ah! thanks. the extension Method ToPlanktonMesh()
was what I did not find in Plankton.dll
In Python I prefer static methods because they have intellisense, so i do:
import rhinoscriptsyntax as rs
import scriptcontext
import clr
clr.AddReferenceToFileAndPath(r"C:\dev\Plankton.dll") # take from github
clr.AddReferenceToFileAndPath(r"C:\dev\Plankton.gha")
import PlanktonGh.RhinoSupport as prs
mObj = rs.GetObject()
mGeo = rs.coercemesh(mObj)
# TODO: check that mesh is manifold and fully welded
# convert rhino mesh to plankton mesh
planktonMesh = prs.ToPlanktonMesh(mGeo) # static method
This is not an issue, just a question. I hope its OK to ask here. Can I use Plankton as well via Rhino Python Scripting (without Grasshopper)? How can I convert a Rhinomesh to a Plankton HEDS? (If you reply with an example, C# is fine too)