Example #1
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            List <GH_Glulam> inputs = new List <GH_Glulam>();

            if (!DA.GetDataList <GH_Glulam>("Glulam", inputs))
            {
                this.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "No glulam blank connected.");
                return;
            }

            int type = 0;

            DA.GetData("Type", ref type);

            DataTree <object> output  = new DataTree <object>();
            DataTree <string> species = new DataTree <string>();
            DataTree <Guid>   ids     = new DataTree <Guid>();

            for (int i = 0; i < inputs.Count; ++i)
            {
                Glulam g = inputs[i].Value;

                GH_Path path;
                int     j = 0;
                switch (type)
                {
                case (1):
                    var meshes = g.GetLamellaMeshes();

                    if (meshes.Count < 1)
                    {
                        throw new NotImplementedException();
                    }

                    for (int x = 0; x < g.Data.NumWidth; ++x)
                    {
                        path = new GH_Path(i, x);
                        for (int y = 0; y < g.Data.NumHeight; ++y)
                        {
                            output.Add(meshes[j], path);
                            if (g.Data.Lamellae[x, y] != null)
                            {
                                species.Add(g.Data.Lamellae[x, y].Species, path);
                                ids.Add(g.Data.Lamellae[x, y].Reference, path);
                            }
                            j++;
                        }
                    }
                    break;

                case (2):
                    var breps = g.GetLamellaBreps();

                    for (int x = 0; x < g.Data.NumWidth; ++x)
                    {
                        path = new GH_Path(i, x);
                        for (int y = 0; y < g.Data.NumHeight; ++y)
                        {
                            output.Add(breps[j], path);
                            if (g.Data.Lamellae[x, y] != null)
                            {
                                species.Add(g.Data.Lamellae[x, y].Species, path);
                                ids.Add(g.Data.Lamellae[x, y].Reference, path);
                            }
                            j++;
                        }
                    }
                    break;

                default:
                    var crvs = g.GetLamellaCurves();

                    for (int x = 0; x < g.Data.NumWidth; ++x)
                    {
                        path = new GH_Path(i, x);
                        for (int y = 0; y < g.Data.NumHeight; ++y)
                        {
                            output.Add(crvs[j], path);
                            if (g.Data.Lamellae[x, y] != null)
                            {
                                species.Add(g.Data.Lamellae[x, y].Species, path);
                                ids.Add(g.Data.Lamellae[x, y].Reference, path);
                            }
                            j++;
                        }
                    }
                    break;
                }
            }

            DA.SetDataTree(0, output);
            DA.SetDataTree(1, species);
            DA.SetDataTree(2, ids);
        }