GenePool to Array

Hi guys,

A. I m trying to figure out why getting the data from a GalapagosGeneListObject is not successful with the first attempt of the following code. Luckily the second attempt worked, but I am curious to know more about their differences.

    protected override void RegisterInputParams(GH_Component.GH_InputParamManager pManager) {
        pManager.AddGenericParameter("Gene pool parameters", "genePool", "The genePool to get the parameters from", GH_ParamAccess.item);
    }
    protected override void RegisterOutputParams(GH_Component.GH_OutputParamManager pManager) {
        pManager.AddGenericParameter("Array of parameters", "params", "The list of genes as a list of parameters", GH_ParamAccess.item);
    }

    protected override void SolveInstance(IGH_DataAccess DA) {
        double[] parameters = new double[] { };

        // ATTEMPT #1: FAILED
        /*
        if (DA.TryGetItem(0, out GalapagosGeneListObject provided_params)) {
            parameters = new double[] { (double)provided_params[0], (double)provided_params[1], (double)provided_params[2] };
        }
        */

        // ATTEMPT #2: WORKED
        foreach (IGH_Param param in Params.Input[0].Sources) {
            GalapagosGeneListObject provided_params = param as GalapagosGeneListObject;
            parameters = new double[] { (double)provided_params[0], (double)provided_params[1], (double)provided_params[2] };
        }

        DA.SetData(0, parameters);

    }

B. As shown at the figure, for a GalapagosGeneListObject with 3 genes I created 3 arrays. I simply wanted one array which contains the genes. Any ideas what I am doing wrong?

Thanks

How about something like this?

protected override void RegisterInputParams(GH_InputParamManager pManager)
{
  pManager.AddNumberParameter("Input", "I", "Input", GH_ParamAccess.list);
}
protected override void RegisterOutputParams(GH_OutputParamManager pManager)
{
   pManager.AddNumberParameter("Output", "O", "Input", GH_ParamAccess.list);
}
protected override void SolveInstance(IGH_DataAccess da)
{
   var data = new List<double>();
   da.GetDataList(0, data);
   da.SetDataList(0, data);
}

GetGenePoolData.zip (22.6 KB)

1 Like

Neat! Makes sense. Thanks a lot.