algorithmic modeling for Rhino
I am creating a custom component using C# that will be used for a variety of data-types - numbers, strings, points, etc - to be determined at runtime. I would like to add a "type hint" menu similar to that used by the Python and C# scripting components. Does anyone know where to start with this?
Thanks,
Ned R
Tags:
Can you tell me how I would do this ?
public class myParam:GH_Param<T>{...}
what would be T in this case given the incoming data format is not fixed ?
T should be the most generic type available, which in the case of parameters is IGH_Goo. ALL data in Grasshopper ultimately implements this interface, so this will allow you to create a parameter which can contain all types of data.
This is where I've gotten. Is this the best way?
protected override void RegisterInputParams(GH_Component.GH_InputParamManager pManager)
{
pManager.Register_GenericParam("G", "G", "Object to test.", GH_ParamAccess.item);
}
protected override void RegisterOutputParams(GH_Component.GH_OutputParamManager pManager)
{
pManager.Register_GenericParam("S", "S", "Type of object.", GH_ParamAccess.item);
pManager.Register_GenericParam("V", "V", "Value", GH_ParamAccess.item);
}
protected override void SolveInstance(IGH_DataAccess DA)
{
object obj_in = new object();
object out_val = new object();
if (!DA.GetData(0, ref obj_in)) return;
if (obj_in.GetType() == typeof(GH_Number)) {
double n = new double();
DA.GetData(0, ref n);
out_val = n;
}
if (obj_in.GetType() == typeof(GH_String)) {
string s = "";
DA.GetData(0, ref s);
out_val = s;
}
var t_string = obj_in.GetType().ToString();
DA.SetData(0, t_string);
DA.SetData(1, out_val);
Welcome to
Grasshopper
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
© 2024 Created by Scott Davidson. Powered by