This is at least in part outside the scope of the project, because:
- the SDK/compilation support was added in order to allow GH_Component classes to be compiled
- all geometry types in Rhino should be already handled by Grasshopper natively, when that is possible
Yet, the GhPython loader mechanism is not looking specifically for custom parameters, and all instantiation happens in components setup, so they are intrinsically entirely possible.
Once compiled with the instructions at: Tutorial: creating a Grasshopper component with the Python GHPY compiler - #9 by Willem (step 2.5), this file will provide a sample of an overridden brep picker:
custompickingpython.py (2.8 KB)
from ghpythonlib.componentbase import dotnetcompiledcomponent as component
import Grasshopper, GhPython
import System
import Rhino
import rhinoscriptsyntax as rs
import Rhino.Geometry as rg
class ParamBrepPick(Grasshopper.Kernel.Parameters.Param_Brep):
# use a line like the one below here to see require signature
# Grasshopper.Kernel.Parameters.Param_Brep.Prompt_Singular(
def Prompt_Singular(self, result):
#result is System.Runtime.CompilerServices.StrongBox[Brep]
try:
g1 = Rhino.Input.RhinoGet.GetOneObject("Personal brep selection", False, Rhino.DocObjects.ObjectType.Brep)
if g1[0] == Rhino.Input.GetResult.Object:
geometry = g1[1].Geometry()
if isinstance(geometry, Rhino.Geometry.Brep):
# use a line like the one below here to see require signature
# Rhino.Geometry.Brep.
result.Value = Grasshopper.Kernel.Types.GH_Brep(g1[1].ObjectId)
return Grasshopper.Kernel.GH_GetterResult.success
except Exception as ex:
System.Windows.Forms.MessageBox.Show(ex, "Error in picking code")
return Grasshopper.Kernel.GH_GetterResult.cancel
class PreviewEx(component):
def __new__(cls):
instance = Grasshopper.Kernel.GH_Component.__new__(cls,
"Pick", "PickEx", """Component to pick something off Rhino""", "Pick", "Pick")
return instance
def get_ComponentGuid(self):
return System.Guid("ae9ec8cd-f30d-48fc-9c89-04820b652268")
def SetUpParam(self, p, name, nickname, description):
p.Name = name
p.NickName = nickname
p.Description = description
p.Optional = True
def RegisterInputParams(self, pManager):
p = ParamBrepPick()
self.SetUpParam(p, "t", "t", "Pick one brep")
p.Access = Grasshopper.Kernel.GH_ParamAccess.item
self.Params.Input.Add(p)
def RegisterOutputParams(self, pManager):
p = Grasshopper.Kernel.Parameters.Param_GenericObject()
self.SetUpParam(p, "a", "a", "Pick one result.")
self.Params.Output.Add(p)
def SolveInstance(self, DA):
p0 = self.marshal.GetInput(DA, 0)
result = self.RunScript(p0)
def RunScript(self, t):
return t
class AssemblyInfo(GhPython.Assemblies.PythonAssemblyInfo):
def get_AssemblyName(self):
return "pickingsample"
def get_AssemblyDescription(self):
return """A picking sample"""
def get_AssemblyVersion(self):
return "0.1"
def get_AuthorName(self):
return "giulio@mcneel.com"
def get_Id(self):
return System.Guid("66c54542-da0d-478d-a5a4-5dc0fc173feb")
So, this is possible, yet I do not think it is entirely useful except maybe for some corner cases. In general, I think this type of Grasshopper-SDK-related work is better suited to a strongly-typed language such as C#.
Thanks,
Giulio
–
Giulio Piacentino
for Robert McNeel & Associates
giulio@mcneel.com