Skip to content

Instantly share code, notes, and snippets.

@jesterKing
Last active June 12, 2019 07:09
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jesterKing/3977640813c7a40cb31c69a922e59509 to your computer and use it in GitHub Desktop.
Save jesterKing/3977640813c7a40cb31c69a922e59509 to your computer and use it in GitHub Desktop.
F# sample component for testing on Mac Rhino Grasshopper (v6, aka WIP)
namespace GhFsharpTest
open Grasshopper.Kernel
open Grasshopper.Kernel.Types
type Priority() =
inherit GH_AssemblyPriority()
override u.PriorityLoad() =
GH_LoadingInstruction.Proceed
type Info() =
inherit GH_AssemblyInfo()
override u.Name = "GhFsharpTest"
override u.Description = "Quick F# test, NOP component. Sets output to whatever is in the input."
override u.Id = new System.Guid("43472a26-58ad-44a8-9948-137a7eaf3ada") // DON'T USE THIS PARTICULAR GUID
override u.AuthorName = "Nathan 'jesterKing' Letwory"
override u.AuthorContact = "nathan@mcneel.com"
type NopTest() =
inherit GH_Component("F#Ex", "F#Ex", "Example Component in F#", "Test", "F#")
let mutable inpidx = 0
let mutable outpidx = 0
override u.RegisterInputParams(mgr: GH_Component.GH_InputParamManager) =
inpidx <- mgr.AddGenericParameter("I","I","Generic Input",GH_ParamAccess.item)
u.Params.Input.[inpidx].Optional <- true
override u.RegisterOutputParams(mgr: GH_Component.GH_OutputParamManager) =
outpidx <- mgr.AddGenericParameter("O", "O", "Generic Output", GH_ParamAccess.item)
override u.SolveInstance(DA: IGH_DataAccess) =
match u.Params.Input.[inpidx].SourceCount > 0 with
| true ->
let mutable (qc:IGH_Goo) = null
let r = DA.GetData(inpidx, &qc)
if r then
DA.SetData(outpidx, qc) |> ignore
()
| _ -> ()
override u.ComponentGuid = new System.Guid("94b16908-64a8-4562-a634-c9227582e99d") // DON'T USE THIS PARTICULAR GUID
()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment