0

我不确定为什么会因为输入参数索引太低而收到此错误。当 DA.GetData 调用找不到输入时,我通常会收到此错误。就在一秒钟前我让它工作了。这次输入的名称与 DA.GetData 调用匹配。

如果我能在 Grasshopper 中获得此错误所在的行号,那将有所帮助。我想这将是一个单独的问题。

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);
    }
4

0 回答 0