@stevescott517 wrote:
Repost from Stack Overflow: Stack Overflow Question
I am not sure why I am getting this error for the input parameter index being too low. I usually get this error when the DA.GetData call can’t find an input. I had it working just a second ago. This time the names of the inputs match the DA.GetData calls.
I am using Visual Studio to write this grasshopper component.
It would help if I could get a line number in Grasshopper where this error was. I guess that would be a separate question though.
namespace MyProject1 { public class NormalDist : GH_Component { public NormalDist() : base("Normal Distribution", "NormalDist", "Generates a normal distribution of points.", "Extras", "Normal Distribution") { } protected override void RegisterInputParams(GH_Component.GH_InputParamManager pManager) { pManager.AddIntegerParameter("Seed", "Seed", "integer seed for random number generator", GH_ParamAccess.item); pManager.AddNumberParameter("StdDev", "StdDev", "Standard Deviation", GH_ParamAccess.item); pManager.AddNumberParameter("Mean", "Mean", "Mean of the normal distribution", GH_ParamAccess.item); } /// Registers all the output parameters for this component. protected override void RegisterOutputParams(GH_Component.GH_OutputParamManager pManager) { pManager.AddNumberParameter("Output", "output", "A collection of normally distributed points", GH_ParamAccess.item); } /// This is the method that actually does the work. protected override void SolveInstance(IGH_DataAccess DA) { int seed = 0; double std = 0; double mean = 0; DA.GetData<int>("Seed", ref seed); DA.GetData<double>("StdDev", ref std); DA.GetData<double>("Mean", ref mean); Random rand = new Random(seed); double u1 = 1.0 - rand.NextDouble(); double u2 = 1.0 - rand.NextDouble(); double randStdNormal = Math.Sqrt(-2.0 * Math.Log(u1)) * Math.Sin(2.0 * Math.PI * u2); double randNormal = mean + std * randStdNormal; DA.SetData("Output", randNormal); }
Posts: 2
Participants: 2