Пример #1
0
        protected override void SolveInstance(IGH_DataAccess dataAccess)
        {
            if (!dataAccess.GetDataTree(0, out GH_Structure <GH_Brep> breps))
            {
                return;
            }
            if (!dataAccess.GetDataTree(1, out GH_Structure <GH_String> materials))
            {
                return;
            }
            if (!dataAccess.GetDataTree(2, out GH_Structure <GH_Integer> stories))
            {
                return;
            }

            if (breps.Paths.Count != materials.Paths.Count || (breps.Paths.Count != stories.Paths.Count && !stories.IsEmpty))
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Geometries, materials and stories must have the same number of items");
                return;
            }

            var filteredBreps = new GH_Structure <GH_Brep> [4];

            for (var i = 0; i < 4; i++)
            {
                filteredBreps[i] = new GH_Structure <GH_Brep>();
            }

            FilterValue(breps, stories, materials, filteredBreps);

            for (var i = 0; i < 4; i++)
            {
                dataAccess.SetDataTree(i, filteredBreps[i]);
            }
        }
Пример #2
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            GH_Structure <GH_Brep> breps   = null;
            GH_Structure <GH_Brep> cutters = null;

            //Brep brep = null;
            //List<Brep> cutters = new List<Brep>();

            if (!DA.GetDataTree("Brep", out breps))
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Invalid Brep input.");
                return;
            }
            if (!DA.GetDataTree("Cutters", out cutters))
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Invalid cutter input.");
                return;
            }

            GH_Structure <GH_Brep> resTree = new GH_Structure <GH_Brep>();

            foreach (var path in breps.Paths)
            {
                resTree.EnsurePath(path);
            }

            List <string> errors = new List <string>();

            Parallel.For(0, breps.Paths.Count, index =>
            {
                GH_Path path = breps.Paths[index];
                if (cutters.PathExists(path) && breps[path].Count > 0)
                {
                    resTree[path].Add(new GH_Brep(breps[path][0].Value.Cut(
                                                      cutters[path].Select(x => x.Value))));
                }
                else if (cutters.PathCount == 1 && breps[path].Count > 0) // Handle a single list of cutters
                {
                    try
                    {
                        if (cutters[0].Count > 0 && breps[path][0] != null)
                        {
                            resTree[path].Add(new GH_Brep(breps[path][0].Value.Cut(
                                                              cutters[cutters.Paths[0]].Select(x => x.Value))));
                        }
                    }
                    catch (Exception ex)
                    {
                        errors.Add(ex.Message);
                    }
                }
                else
                {
                    resTree[path].AddRange(breps[path]);
                }
            });

            DA.SetDataTree(0, resTree);
            DA.SetDataList("Errors", errors);
        }
Пример #3
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            CrowNetBP net = new CrowNetBP();

            if (!networkLoaded)
            {
                int cycles = 1000;

                GH_Structure <GH_Number> tiv = new GH_Structure <GH_Number>();
                GH_Structure <GH_Number> tov = new GH_Structure <GH_Number>();

                DA.GetData(0, ref cycles);
                DA.GetData(1, ref net);
                DA.GetDataTree(2, out tiv);
                DA.GetDataTree(3, out tov);

                double[][] trainInVectors  = Utils.GHTreeToMultidimensionalArray(tiv);
                double[][] trainOutVectors = Utils.GHTreeToMultidimensionalArray(tov);


                int trainVectorCount = trainInVectors.Length;
                if (trainVectorCount != trainOutVectors.Length)
                {
                    AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Please supply an equal amount of input and output training vectors!");
                }

                int trainInVectorDimension  = trainInVectors[0].Length;
                int trainOutVectorDimension = trainOutVectors[0].Length;

                BackpropagationNetwork network = net.network(trainInVectorDimension, trainOutVectorDimension);


                // set Trainingset
                TrainingSet trainingSet = new TrainingSet(trainInVectorDimension, trainOutVectorDimension);

                for (int i = 0; i < trainVectorCount; i++)
                {
                    trainingSet.Add(new TrainingSample(trainInVectors[i], trainOutVectors[i]));
                }

                // train
                network.Learn(trainingSet, cycles);
                this.Network = network;
            }
            if (this.Network != null)
            {
                DA.SetData(0, this.Network.MeanSquaredError.ToString("0.0000000000"));

                CrowNetBPP nn = new CrowNetBPP(this.Network);
                nn.hiddenLayerList = net.hiddenLayerList;
                nn.layerStructure  = net.layerStructure;
                nn.neuronCount     = net.neuronCount;
                DA.SetData(1, nn);
            }

            networkLoaded = false;
        }
Пример #4
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            Vector3d rotation(Vector3d a, Vector3d b, double theta)
            {
                double rad = theta * Math.PI / 180;
                double s = Math.Sin(rad); double c = Math.Cos(rad);

                b /= Math.Sqrt(Vector3d.Multiply(b, b));
                double   b1 = b[0]; double b2 = b[1]; double b3 = b[2];
                Vector3d m1 = new Vector3d(c + Math.Pow(b1, 2) * (1 - c), b1 * b2 * (1 - c) - b3 * s, b1 * b3 * (1 - c) + b2 * s);
                Vector3d m2 = new Vector3d(b2 * b1 * (1 - c) + b3 * s, c + Math.Pow(b2, 2) * (1 - c), b2 * b3 * (1 - c) - b1 * s);
                Vector3d m3 = new Vector3d(b3 * b1 * (1 - c) - b2 * s, b3 * b2 * (1 - c) + b1 * s, c + Math.Pow(b3, 2) * (1 - c));

                return(new Vector3d(Vector3d.Multiply(m1, a), Vector3d.Multiply(m2, a), Vector3d.Multiply(m3, a)));
            }

            IList <List <GH_Number> > r; IList <List <GH_Number> > ij;
            List <Vector3d>           l_vec = new List <Vector3d>();
            int m; int e;

            if (!DA.GetDataTree(0, out GH_Structure <GH_Number> _r))
            {
            }
            else
            {
                r = _r.Branches;
                if (!DA.GetDataTree(1, out GH_Structure <GH_Number> _ij))
                {
                }
                else
                {
                    ij = _ij.Branches; m = ij.Count;
                    for (e = 0; e < m; e++)
                    {
                        int      i = (int)ij[e][0].Value; int j = (int)ij[e][1].Value; double a_e = ij[e][4].Value;
                        Vector3d x = new Vector3d(r[j][0].Value - r[i][0].Value, r[j][1].Value - r[i][1].Value, r[j][2].Value - r[i][2].Value);
                        if (Math.Abs(x[0]) <= 5e-3 && Math.Abs(x[1]) <= 5e-3)
                        {
                            Vector3d y = rotation(x, new Vector3d(0, 1, 0), 90);
                            Vector3d z = rotation(y, x, 90 + a_e);
                            Vector3d l = z / Math.Sqrt(Vector3d.Multiply(z, z));
                            l_vec.Add(l);
                        }
                        else
                        {
                            Vector3d y = rotation(x, new Vector3d(0, 0, 1), 90);
                            y[2] = 0.0;
                            Vector3d z = rotation(y, x, 90 + a_e);
                            Vector3d l = z / Math.Sqrt(Vector3d.Multiply(z, z));
                            l_vec.Add(l);
                        }
                    }
                    DA.SetDataList("element axis vector", l_vec);
                }
            }
        }
Пример #5
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            GH_Structure <GH_Number> joint = new GH_Structure <GH_Number>();

            DA.GetDataTree("nodal_coordinates", out GH_Structure <GH_Number> _r);
            DA.GetDataTree("element_node_relationship(shell)", out GH_Structure <GH_Number> _ijkl);
            if (_r.Branches[0][0].Value != -9999 && _ijkl.Branches[0][0].Value != -9999)
            {
                var r = _r.Branches; var ijkl = _ijkl.Branches;
                var x = new List <double>(); DA.GetDataList("x coordinates of element center point", x); var y = new List <double>(); DA.GetDataList("y coordinates of element center point", y); var z = new List <double>(); DA.GetDataList("z coordinates of element center point", z);
                var ki = new List <double>(); DA.GetDataList("axial spring for node_i", ki); var kj = new List <double>(); DA.GetDataList("axial spring for node_j", kj);
                var ri = new List <double>(); DA.GetDataList("rotational spring for node_i", ri); var rj = new List <double>(); DA.GetDataList("rotational spring for node_j", rj);
                var kxi = ki[0]; var kyi = ki[1]; var kzi = ki[2]; var rxi = ri[0]; var ryi = ri[1]; var rzi = ri[2];
                var kxj = kj[0]; var kyj = kj[1]; var kzj = kj[2]; var rxj = rj[0]; var ryj = rj[1]; var rzj = ri[2];
                int k = 0;
                for (int j = 0; j < Math.Max(Math.Max(x.Count, y.Count), z.Count); j++)
                {
                    for (int e = 0; e < ijkl.Count; e++)
                    {
                        var ni = (int)ijkl[e][0].Value; var nj = (int)ijkl[e][1].Value; var nk = (int)ijkl[e][2].Value; var nl = (int)ijkl[e][3].Value;
                        var xi = r[ni][0].Value; var yi = r[ni][1].Value; var zi = r[ni][2].Value;
                        var xj = r[nj][0].Value; var yj = r[nj][1].Value; var zj = r[nj][2].Value;
                        var xk = r[nk][0].Value; var yk = r[nk][1].Value; var zk = r[nk][2].Value;
                        var xc = 0.0; var yc = 0.0; var zc = 0.0;
                        if (nl < 0)
                        {
                            xc = (xi + xj + xk) / 3.0; yc = (yi + yj + yk) / 3.0; zc = (zi + zj + zk) / 3.0;
                        }
                        else
                        {
                            var xl = r[nl][0].Value; var yl = r[nl][1].Value; var zl = r[nl][2].Value;
                            xc = (xi + xj + xk + xl) / 4.0; yc = (yi + yj + yk + yl) / 4.0; zc = (zi + zj + zk + zl) / 4.0;
                        }
                        if (Math.Abs(xc - x[Math.Min(j, x.Count - 1)]) < 1e-8 || x[0] == -9999)
                        {
                            if (Math.Abs(yc - y[Math.Min(j, y.Count - 1)]) < 1e-8 || y[0] == -9999)
                            {
                                if (Math.Abs(zc - z[Math.Min(j, z.Count - 1)]) < 1e-8 || z[0] == -9999)
                                {
                                    List <GH_Number> jlist = new List <GH_Number>();
                                    jlist.Add(new GH_Number(e));
                                    jlist.Add(new GH_Number(1000 * I + 100 * J + 10 * K + L));
                                    jlist.Add(new GH_Number(kxi)); jlist.Add(new GH_Number(kyi)); jlist.Add(new GH_Number(kzi));
                                    jlist.Add(new GH_Number(rxi)); jlist.Add(new GH_Number(ryi)); jlist.Add(new GH_Number(rzi));
                                    jlist.Add(new GH_Number(kxj)); jlist.Add(new GH_Number(kyj)); jlist.Add(new GH_Number(kzj));
                                    jlist.Add(new GH_Number(rxj)); jlist.Add(new GH_Number(ryj)); jlist.Add(new GH_Number(rzj));
                                    joint.AppendRange(jlist, new GH_Path(k));
                                    k += 1;
                                }
                            }
                        }
                    }
                }
                DA.SetDataTree(0, joint);
            }
        }///ここからGUIの作成*****************************************************************************************
Пример #6
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            var vec = new Vector3d(1, 0, 0); DA.GetData("A vector that is the basis for rotation", ref vec); var angle = 90.0; DA.GetData("rotate angle", ref angle); var center = new Point3d(0, 0, 0); DA.GetData("center point of rotation", ref center); var offset = new Vector3d(0, 0, 0); DA.GetData("offset after rotation", ref offset);
            GH_Structure <GH_Number> r2 = new GH_Structure <GH_Number>(); GH_Structure <GH_Point> p2 = new GH_Structure <GH_Point>();

            Vector3d rotation(Vector3d a, Vector3d b, double theta)
            {
                double rad = theta * Math.PI / 180;
                double s = Math.Sin(rad); double c = Math.Cos(rad);

                b /= Math.Sqrt(Vector3d.Multiply(b, b));
                double   b1 = b[0]; double b2 = b[1]; double b3 = b[2];
                Vector3d m1 = new Vector3d(c + Math.Pow(b1, 2) * (1 - c), b1 * b2 * (1 - c) - b3 * s, b1 * b3 * (1 - c) + b2 * s);
                Vector3d m2 = new Vector3d(b2 * b1 * (1 - c) + b3 * s, c + Math.Pow(b2, 2) * (1 - c), b2 * b3 * (1 - c) - b1 * s);
                Vector3d m3 = new Vector3d(b3 * b1 * (1 - c) - b2 * s, b3 * b2 * (1 - c) + b1 * s, c + Math.Pow(b3, 2) * (1 - c));

                return(new Vector3d(Vector3d.Multiply(m1, a), Vector3d.Multiply(m2, a), Vector3d.Multiply(m3, a)));
            }

            DA.GetDataTree("nodal_coordinates", out GH_Structure <GH_Number> _r);
            if (_r.Branches[0][0].Value != -9999)
            {
                var r = _r.Branches; var n = r.Count;
                for (int i = 0; i < n; i++)
                {
                    var rvec  = new Vector3d(r[i][0].Value - center[0], r[i][1].Value - center[1], r[i][2].Value - center[2]);
                    var r2vec = rotation(rvec, vec, angle);
                    var rlist = new List <GH_Number>(); rlist.Add(new GH_Number(r2vec[0] + offset[0])); rlist.Add(new GH_Number(r2vec[1] + offset[1])); rlist.Add(new GH_Number(r2vec[2] + offset[2]));
                    r2.AppendRange(rlist, new GH_Path(i));
                }
                DA.SetDataTree(0, r2);
            }
            else
            {
                DA.GetDataTree("grid points", out GH_Structure <GH_Point> _p);
                var p = _p.Branches;
                for (int i = 0; i < p.Count; i++)
                {
                    var plist = new List <GH_Point>();
                    for (int j = 0; j < p[i].Count; j++)
                    {
                        var r     = p[i][j].Value;
                        var rvec  = new Vector3d(r[0] - center[0], r[1] - center[1], r[2] - center[2]);
                        var r2vec = rotation(rvec, vec, angle);
                        var pj    = new Point3d(r2vec[0] + offset[0], r2vec[1] + offset[1], r2vec[2] + offset[2]);
                        plist.Add(new GH_Point(pj));
                    }
                    p2.AppendRange(plist, new GH_Path(i));
                }
                DA.SetDataTree(1, p2);
            }
        }
Пример #7
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            GH_Structure <IGH_Goo> primary;
            GH_Structure <IGH_Goo> secondary;

            var hasPrimary   = DA.GetDataTree("Primary Data", out primary);
            var hasSecondary = DA.GetDataTree("Backup Data", out secondary);

            var primaryisNullOrEmpty = !primary.AllData(true).Any();

            var passPrimary = hasPrimary && !primaryisNullOrEmpty;

            DA.SetDataTree(0, passPrimary ? primary : secondary);
        }
Пример #8
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            GH_Structure <GH_Number> e_load = new GH_Structure <GH_Number>();

            DA.GetDataTree("nodal_coordinates", out GH_Structure <GH_Number> _r);
            DA.GetDataTree("element_node_relationship", out GH_Structure <GH_Number> _ij);
            if (_r.Branches[0][0].Value != -9999 && _ij.Branches[0][0].Value != -9999)
            {
                var r = _r.Branches; var ij = _ij.Branches;
                var x = new List <double>(); DA.GetDataList("x coordinates of element center point", x); var y = new List <double>(); DA.GetDataList("y coordinates of element center point", y); var z = new List <double>(); DA.GetDataList("z coordinates of element center point", z);
                var wx = 0.0; DA.GetData("distributed load of x axis direction", ref wx); var wy = 0.0; DA.GetData("distributed load of y axis direction", ref wy); var wz = 0.0; DA.GetData("distributed load of z axis direction", ref wz); int kk = 0;
                for (int e = 0; e < ij.Count; e++)
                {
                    var ni = (int)ij[e][0].Value; var nj = (int)ij[e][1].Value;
                    var xi = r[ni][0].Value; var yi = r[ni][1].Value; var zi = r[ni][2].Value;
                    var xj = r[nj][0].Value; var yj = r[nj][1].Value; var zj = r[nj][2].Value;
                    var xc = (xi + xj) / 2.0; var yc = (yi + yj) / 2.0; var zc = (zi + zj) / 2.0;
                    int k = 0;
                    for (int j = 0; j < x.Count; j++)
                    {
                        if (Math.Abs(x[j] - xc) < 5e-3 || x[j] == -9999)
                        {
                            k += 1; break;
                        }
                    }
                    for (int j = 0; j < y.Count; j++)
                    {
                        if (Math.Abs(y[j] - yc) < 5e-3 || y[j] == -9999)
                        {
                            k += 1; break;
                        }
                    }
                    for (int j = 0; j < z.Count; j++)
                    {
                        if (Math.Abs(z[j] - zc) < 5e-3 || z[j] == -9999)
                        {
                            k += 1; break;
                        }
                    }
                    if (k == 3)
                    {
                        List <GH_Number> elist = new List <GH_Number>();
                        elist.Add(new GH_Number(e)); elist.Add(new GH_Number(wx)); elist.Add(new GH_Number(wy)); elist.Add(new GH_Number(wz));
                        e_load.AppendRange(elist, new GH_Path(kk)); kk += 1;
                    }
                }
            }
            DA.SetDataTree(0, e_load);
        }
Пример #9
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            GH_Structure <IGH_Goo> telepathy = null;
            bool stop = false;

            DA.GetDataTree(0, out telepathy);
            DA.GetData(1, ref stop);
            if (stop)
            {
                return;
            }

            OutComponents = FindTelepathyOut(NickName);
            foreach (GH_TelepathyOut c in OutComponents)
            {
                if (deepDuplicate)
                {
                    c.telepathy = telepathy.Duplicate();
                }
                else
                {
                    c.telepathy = telepathy;
                }
                c.ExpireSolution(true);
            }
        }
Пример #10
0
 static void CollectDataHelper2 <T, GHT>(IGH_DataAccess DA,
                                         string inputName,
                                         GH_ParamAccess access,
                                         ref int inputCount,
                                         DataTree <ResthopperObject> dataTree) where GHT : GH_Goo <T>
 {
     if (access == GH_ParamAccess.tree)
     {
         var tree = new Grasshopper.Kernel.Data.GH_Structure <GHT>();
         if (DA.GetDataTree(inputName, out tree))
         {
             foreach (var path in tree.Paths)
             {
                 string pathString = path.ToString();
                 var    items      = tree[path];
                 foreach (var item in items)
                 {
                     dataTree.Append(new ResthopperObject(item.Value), pathString);
                 }
             }
         }
     }
     else
     {
         CollectDataHelper <T>(DA, inputName, access, ref inputCount, dataTree);
     }
 }
Пример #11
0
        internal static (string Name, ObjectProperty Property) RetrieveProperties(IGH_DataAccess DA, int paramIndex, IGH_Component @this)
        {
            var            param = @this.Params.Input[paramIndex];
            ObjectProperty prop;
            var            name = param.NickName;

            if (param.Access == GH_ParamAccess.item)
            {
                IGH_Goo item = null;
                if (!DA.GetData(paramIndex, ref item))
                {
                    @this.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, $"{name} has no input and has been assigned null data");
                }
                prop = new ObjectProperty(item);
            }
            else if (param.Access == GH_ParamAccess.list)
            {
                var items = new List <IGH_Goo>();
                DA.GetDataList(paramIndex, items);
                prop = new ObjectProperty(items);
            }
            else //tree access
            {
                DA.GetDataTree(paramIndex, out GH_Structure <IGH_Goo> itemTree);
                prop = new ObjectProperty(itemTree);
            }
            return(name, prop);
        }
Пример #12
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            string dir = ""; DA.GetData("directoryname", ref dir); string fname = "data.csv"; DA.GetData("outputfilename", ref fname);

            DA.GetDataTree("Tree", out GH_Structure <GH_Number> _data); var data = _data.Branches;
            if (on_off == 1 && data[0][0].Value != -9999)
            {
                if (dir == "default")
                {
                    dir = Directory.GetCurrentDirectory();
                }
                var doc = RhinoDoc.ActiveDoc;
                var w1  = new StreamWriter(@dir + "/" + fname, false);
                for (int i = 0; i < data.Count; i++)
                {
                    var texts = "";
                    for (int j = 0; j < data[0].Count; j++)
                    {
                        texts += (data[i][j].Value).ToString() + ",";
                    }
                    w1.WriteLine(texts);
                }
                w1.Flush();
            }
        }
Пример #13
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            GH_Structure <IGH_GeometricGoo> iMeshTree = new GH_Structure <IGH_GeometricGoo>();

            DA.GetDataTree <IGH_GeometricGoo>(0, out iMeshTree);

            GH_Structure <IGH_GeometricGoo> oDualMeshTree      = new GH_Structure <IGH_GeometricGoo>();
            GH_Structure <IGH_GeometricGoo> oDualMeshCurveTree = new GH_Structure <IGH_GeometricGoo>();


            for (int i = 0; i < iMeshTree.PathCount; i++)
            {
                GH_Path path = iMeshTree.get_Path(i);

                for (int j = 0; j < iMeshTree.Branches[i].Count; j++)
                {
                    Mesh mesh;
                    if (!iMeshTree.Branches[i][j].CastTo <Mesh>(out mesh))
                    {
                        continue;
                    }
                    else
                    {
                        oDualMeshTree.Append(
                            GH_Convert.ToGeometricGoo(mesh.ToPlanktonMesh().Dual(0).ToRhinoMesh()),
                            path);
                    }
                }
            }

            DA.SetDataTree(0, oDualMeshTree);
        }
Пример #14
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            //Input
            Mesh mesh = new Mesh();

            DA.GetData(0, ref mesh);
            int iteration = DA.Iteration;

            GH_Structure <GH_Integer> pairs = new GH_Structure <GH_Integer>();

            DA.GetDataTree(1, out pairs);

            //Solution

            int[][] p = new int[pairs.PathCount][];


            //Grasshopper datatree to int[] {a,b}
            for (int i = 0; i < pairs.PathCount; i++)
            {
                p[i] = (new int[] { pairs[i][0].Value, pairs[i][1].Value });
            }



            var edges = mesh.FindMeshEdgeByNGonPair(p);

            //Output

            DA.SetDataList(0, edges.Item2);
            DA.SetDataList(1, edges.Item3);
            DA.SetDataList(2, edges.Item1);
        }
Пример #15
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            GH_Structure <IGH_Goo> data;
            bool hasData = DA.GetDataTree(0, out data);

            DA.SetData(0, data.Branches.Count != 0);
        }
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            List <string>            headers = new List <string>();
            GH_Structure <GH_String> values;

            D3jsLib.Domain domain = null;

            if (!DA.GetDataList <string>(0, headers))
            {
                return;
            }
            if (!DA.GetDataTree(1, out values))
            {
                return;
            }
            DA.GetData <D3jsLib.Domain>(2, ref domain);

            List <DataPoint2> dataPoints = Mandrill_Grasshopper.Utilities.Utilities.Data2FromTree(headers, values);

            GroupedBarChartData data = new GroupedBarChartData();

            data.Data   = dataPoints;
            data.Domain = domain;

            DA.SetData(0, data);
        }
Пример #17
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            var A = new GH_Structure <GH_Number>(); int e = 0;

            for (int k = 0; k < n; k++)
            {
                if (!DA.GetDataTree(k, out GH_Structure <GH_Number> _T))
                {
                }
                else if (_T.Branches[0][0].Value != -9999)
                {
                    var T = _T.Branches;
                    var ni = T.Count; var nj = T[0].Count;
                    for (int i = 0; i < ni; i++)
                    {
                        var tlist = new List <GH_Number>();
                        for (int j = 0; j < nj; j++)
                        {
                            tlist.Add(new GH_Number(T[i][j].Value));
                        }
                        A.AppendRange(tlist, new GH_Path(e));
                        e += 1;
                    }
                }
            }
            DA.SetDataTree(0, A);
        }
Пример #18
0
        protected override void TrySolveInstance(IGH_DataAccess DA)
        {
            if (!DA.GetDataTree <Types.Element>("Elements", out var elementsTree))
            {
                return;
            }

            var elementsToDelete = Parameters.Element.
                                   ToElementIds(elementsTree).
                                   GroupBy(x => x.Document).
                                   ToArray();

            foreach (var group in elementsToDelete)
            {
                StartTransaction(group.Key);

                try
                {
                    var deletedElements = group.Key.Delete(group.Select(x => x.Id).ToArray());

                    if (deletedElements.Count == 0)
                    {
                        AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "No elements were deleted");
                    }
                    else
                    {
                        AddRuntimeMessage(GH_RuntimeMessageLevel.Remark, $"{elementsToDelete.Length} elements and {deletedElements.Count - elementsToDelete.Length} dependant elements were deleted.");
                    }
                }
                catch (Autodesk.Revit.Exceptions.ArgumentException)
                {
                    AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "One or more of the elements cannot be deleted.");
                }
            }
        }
Пример #19
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            System.Drawing.Color f  = System.Drawing.Color.White;
            System.Drawing.Color b  = System.Drawing.Color.Red;
            System.Drawing.Color lc = System.Drawing.Color.Black;
            int w = 1;

            DA.GetData(1, ref f);
            DA.GetData(2, ref b);
            //DA.GetData(3, ref w);
            DA.GetData(3, ref lc);


            Grasshopper.Kernel.Data.GH_Structure <GH_Mesh> tree = new Grasshopper.Kernel.Data.GH_Structure <GH_Mesh>();
            DA.GetDataTree(0, out tree);

            Mesh mesh = new Mesh();

            foreach (GH_Mesh m in tree)
            {
                mesh.Append(m.Value);
            }

            this.PreparePreview(mesh, DA.Iteration, null, true, null, null, b.R, b.G, b.B, null, f.R, f.G, f.B, w, true, lc.R, lc.G, lc.B);

            // DA.SetDataTree(0, tree);
        }
Пример #20
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            GH_Structure <IGH_Goo> T = new GH_Structure <IGH_Goo>();

            if (!DA.GetDataTree(0, out T))
            {
                return;
            }
            int i = 0;

            DA.GetData(1, ref i);
            GH_Path        P    = new GH_Path();
            List <IGH_Goo> data = new List <IGH_Goo>();

            if (T.Branches.Count > 0)
            {
                int ind = i % T.Branches.Count;

                P    = T.Paths[ind];
                data = T.Branches[ind];
            }

            DA.SetData(0, P);
            DA.SetDataList(1, data);
        }
Пример #21
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            bool condition = new bool();
            GH_Structure <IGH_Goo> data      = new GH_Structure <IGH_Goo>();
            AnteloopDoComponent    loopStart = new AnteloopDoComponent();

            if (!DA.GetData(0, ref condition))
            {
                return;
            }
            if (!DA.GetDataTree(1, out data))
            {
                return;
            }
            if (!DA.GetData(2, ref loopStart))
            {
                return;
            }


            if (condition)
            {
                loopStart.Params.Input[0].ClearData();
                loopStart.Params.Input[0].AddVolatileDataTree(data);

                // Dangerous
                loopStart.ExpireSolution(true);
            }
            else
            {
                DA.SetDataTree(0, data);
            }
        }
Пример #22
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            GH_Structure <IGH_Goo> objects = new GH_Structure <IGH_Goo>();

            if (!DA.GetDataTree(0, out objects))
            {
                return;
            }
            /////////////////////////////////////////////////////////////////////////////
            DataTree <object> newobj = new DataTree <object>();
            int        num           = objects.PathCount;
            List <int> index         = new List <int>();//////每个分支的长度

            for (int i = 0; i < num; i++)
            {
                index.Add(objects.Branches[i].Count);
            }
            index.Sort();                        /////排序长度,找出最大值
            int maxnum = index[index.Count - 1]; /////找出数据最长分支的长度

            for (int i = 0; i < maxnum; i++)
            {
                for (int j = 0; j < num; j++)
                {
                    List <object> obb  = new List <object>(objects.Branches[j]);
                    int           num2 = obb.Count;
                    if (num2 >= i + 1)/////////////////////如果分支的数据长度大于序号,则进入
                    {
                        newobj.Add(obb[i], new GH_Path(0, i));
                    }
                }
            }
            DA.SetDataTree(0, newobj);
        }
Пример #23
0
        /// <summary>
        /// Fetch structure with name
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="DA"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        static public GH_Structure <T> FetchTree <T>(this IGH_DataAccess DA, string name) where T : IGH_Goo
        {
            GH_Structure <T> temp;

            DA.GetDataTree <T>(name, out temp);
            return(temp);
        }
Пример #24
0
        private object GetTreeFromParameter(IGH_DataAccess DA, int index, bool addIntoGhDoc)
        {
            GH_Structure <IGH_Goo> structure;

            DA.GetDataTree(index, out structure);
            IGH_TypeHint typeHint = ((Param_ScriptVariable)_component.Params.Input[index]).TypeHint;
            var          tree     = new DataTree <object>();

            for (int i = 0; i < structure.PathCount; i++)
            {
                GH_Path        path = structure.get_Path(i);
                List <IGH_Goo> list = structure.Branches[i];
                List <object>  data = new List <object>();

                for (int j = 0; j < list.Count; j++)
                {
                    object cast = this.TypeCast(list[j], typeHint);
                    DocumentSingle(ref cast, addIntoGhDoc);

                    data.Add(cast);
                }
                tree.AddRange(data, path);
            }
            return(tree);
        }
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            GH_Structure <IGH_Goo> tree;

            if (!DA.GetDataTree(0, out tree))
            {
                return;
            }

            int index = 0;

            if (!DA.GetData(1, ref index))
            {
                return;
            }

            List <IGH_Goo> branch = new List <IGH_Goo>();

            if (tree.Branches.Count > 0)
            {
                index  = Math.Max(Math.Min(index, tree.Branches.Count - 1), 0);
                branch = tree.Branches[index];
            }

            DA.SetDataList(0, branch);
        }
Пример #26
0
        /// <summary>
        /// Fetch structure with position
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="DA"></param>
        /// <param name="position"></param>
        /// <returns></returns>
        static public GH_Structure <T> FetchTree <T>(this IGH_DataAccess DA, int position) where T : IGH_Goo
        {
            GH_Structure <T> temp;

            DA.GetDataTree <T>(position, out temp);
            return(temp);
        }
Пример #27
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            var tree = new GH_Structure <GH_Number>();

            if (!DA.GetDataTree(0, out tree))
            {
                return;
            }

            var X = new double[tree.Branches.Count][];

            for (int d = 0; d < tree.Branches.Count; d++)
            {
                X[d] = new double[tree.Branches[d].Count];
                for (int i = 0; i < tree.Branches[d].Count; i++)
                {
                    X[d][i] = tree.Branches[d][i].Value;
                }
            }

            var labels = new List <string>();

            if (!DA.GetDataList(1, labels))
            {
                ghGrid = new GH_Grid(X);
            }
            else
            {
                ghGrid = new GH_Grid(X, labels);
            }

            DA.SetData(0, ghGrid.Value.Info());
            DA.SetData(1, ghGrid);
        }
Пример #28
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            GH_Structure <GH_Integer> ind = new GH_Structure <GH_Integer>();

            //List<Vector3d> nor = new List<Vector3d>();

            DA.GetDataTree(0, out ind);
            //DA.GetDataList(1, nor);



            List <int> indices = new List <int>();

            foreach (List <GH_Integer> i in ind.Branches)
            {
                indices.Add(i[0].Value);
                indices.Add(i[1].Value);
                indices.Add(i[2].Value);
            }

            /*List<float> normals = new List<float>();
             * foreach(Vector3d v in nor)
             * {
             *  normals.Add((float)v.X);
             *  normals.Add((float)v.Y);
             *  normals.Add((float)v.Z);
             * }*/

            //DA.SetData(0, new ConstraintSystem(indices.ToArray(), normals.ToArray()));
            DA.SetData(0, new ConstraintSystem(indices.ToArray(), true));
        }
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            // Define i/o parameters
            bool s = false;

            // Read inputs
            if (!DA.GetDataTree("Vectors", out GH_Structure <GH_Vector> vectorTree))
            {
                return;
            }
            if (!DA.GetData("Strict", ref s))
            {
                return;
            }

            // Exceptions
            if (vectorTree.GetType() != typeof(GH_Structure <GH_Vector>))
            {
                throw new Exception("Invalid vectorTree");
            }
            if (vectorTree.IsEmpty)
            {
                throw new Exception("Empty vectorTree");
            }
            if (vectorTree.PathCount < 1)
            {
                throw new Exception("This vectorTree is to small");
            }

            DA.SetDataTree(0, vectorTree.SplitVectors(s));
        }
Пример #30
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            GH_Structure <GH_Curve> inputSkeleton = new GH_Structure <GH_Curve>();
            double radius      = 0;
            double jointHeight = 0;
            double jointRadius = 0;
            double layerHeight = 0;

            if (!DA.GetDataTree(0, out inputSkeleton))
            {
                return;
            }
            if (!DA.GetData(1, ref radius))
            {
                return;
            }
            if (!DA.GetData(2, ref jointHeight))
            {
                return;
            }
            if (!DA.GetData(3, ref jointRadius))
            {
                return;
            }
            if (!DA.GetData(4, ref layerHeight))
            {
                return;
            }

            StemBuilder sb = new StemBuilder(inputSkeleton, radius, jointHeight, jointRadius, layerHeight);
        }
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            //---- Declareing -------------------------------------------------------------------------------

            GH_Structure<GH_Point> SofistikPts;
            DA.GetDataTree("SofistikPoints", out SofistikPts);

            List<Point3d> flatclean = new List<Point3d>();
            DA.GetDataList<Point3d>("Flatten Points", flatclean);

            DataTree<int> SofistikInt = new DataTree<int>();

            //---- End Declareing ---------------------------------------------------------------------------

            //---- Functions --------------------------------------------------------------------------------

            for (int i = 0; i < flatclean.Count; i++)
            {
                Point3d fpoint = flatclean[i];

                for (int j = 0; j < SofistikPts.Paths.Count; j++)
                {
                    GH_Path pth = SofistikPts.Paths[j];
                    for (int k = 0; k < SofistikPts[pth].Count; k++)
                    {
                        GH_Point ghp = SofistikPts[pth][k];

                        if ((Math.Abs(fpoint.X - ghp.Value.X) <= 0.01) &&
                                (Math.Abs(fpoint.Y - ghp.Value.Y) <= 0.01) &&
                                (Math.Abs(fpoint.Z - ghp.Value.Z) <= 0.01))
                        {
                            SofistikInt.Add(i, pth.AppendElement(k));
                        }
                    }

                }
            }

            //---- End Functions ----------------------------------------------------------------------------

            //---- Set Output -----------------------------------------------------------------------------

            DA.SetDataTree(0, SofistikInt);

            //---- End Set Output -----------------------------------------------------------------------------
        }
Пример #32
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            //declare input variables to load into

            AuthToken authToken = new AuthToken();
            string sheetName = "";
            string worksheet = "";
            bool rowsColumns = false;

            GH_Structure<GH_String> addresses = new GH_Structure<GH_String>();
            GH_Structure<GH_String> data = new GH_Structure<GH_String>();
            bool write = false;

            //declare output variables
            GH_Structure<GH_String> addressesOut = new GH_Structure<GH_String>();

            //get data from inputs
            if (!DA.GetData<AuthToken>("Token", ref authToken))
            {
                return; //exit if no token given
            }
            if (!authToken.IsValid)
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "The provided authentication token appears to be invalid. Try re-running the Google Authenticator component.");
                return; //exit if token invalid
            }

            if (!DA.GetData<string>("Name", ref sheetName))
            {
                return; //exit if no name given
            }
            DA.GetData<string>("Worksheet", ref worksheet);

            DA.GetData<bool>("Organize by Rows or Columns", ref rowsColumns);
            DA.GetDataTree<GH_String>("Address", out addresses);
            DA.GetDataTree<GH_String>("Data", out data);
            DA.GetData<bool>("Write", ref write);

            if (!write) return; //exit if write is not true

            //check each specified address for validity
            foreach (GH_String address in addresses.AllData(true))
            {
                if (!GDriveUtil.isValidAddress(address.ToString()))
                {
                    AddRuntimeMessage(GH_RuntimeMessageLevel.Error,"Not all addresses are specified in a valid format.");
                    return;
                }
            }

            //setup auth and factory
            //set up oAuth parameters
            OAuth2Parameters parameters = GDriveUtil.GetParameters(authToken);
            SpreadsheetsService service = GDriveUtil.GetSpreadsheetsService(parameters);

            //find spreadsheet by name
            SpreadsheetEntry spreadsheet = GDriveUtil.findSpreadsheetByName(sheetName, service);
            if (spreadsheet == null) //if the spreadsheet is not found
            {
                if (createNewSpreadsheets) //if the user has elected to create new spreadsheets
                {
                   List<string> worksheets = new List<string>();
                   if (!String.IsNullOrEmpty(worksheet))
                   {
                       worksheets.Add(worksheet); //create a 1-item list with the worksheet name
                   }
                    spreadsheet = CreateSpreadsheet.createNewSpreadsheet(this, authToken, sheetName, worksheets, false); //create the spreadsheet
                }
                else
                {
                    AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Specified spreadsheet not found.");
                    return;
                }
            }
            //find worksheet by name
            WorksheetEntry worksheetEntry = GDriveUtil.findWorksheetByName(worksheet, spreadsheet);
            if (worksheetEntry == null)
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Specified worksheet not found.");
                return;
            }

            uint maxRow = 0;
            uint maxCol = 0;
            // set up dictionary<Cell address, cell input>
            // associate each input value with a corresponding address
            Dictionary<string, string> writeMap = constructWriteMap(addresses, data, rowsColumns, ref maxRow, ref maxCol, ref addressesOut);

                //expand worksheet if necessary
                if (worksheetEntry.Rows < maxRow)
                {

                        worksheetEntry.Rows = maxRow;
                        worksheetEntry.Etag = "*"; //required for compatibility with "new" google sheets (see:  http://stackoverflow.com/questions/22719170/updating-cell-in-google-spreadsheets-returns-error-missing-resource-version-id)
                        worksheetEntry.Update();

                }

                if (worksheetEntry.Cols < maxCol)
                {

                        worksheetEntry.Cols = maxCol;
                        worksheetEntry.Etag = "*"; //required for compatibility with "new" google sheets (see:  http://stackoverflow.com/questions/22719170/updating-cell-in-google-spreadsheets-returns-error-missing-resource-version-id)
                        worksheetEntry.Update();

                }

                //set bounds of cell query
                CellQuery cellQuery = new CellQuery(worksheetEntry.CellFeedLink);
                cellQuery.MinimumColumn = 0;
                cellQuery.MinimumRow = 0;
                cellQuery.MaximumColumn = maxCol;
                cellQuery.MaximumRow = maxRow;
                cellQuery.ReturnEmpty = ReturnEmptyCells.yes;

                //retrieve cellfeed
                CellFeed cellFeed = service.Query(cellQuery);

                //convert cell entries to dictionary
               Dictionary<string,AtomEntry> cellDict = cellFeed.Entries.ToDictionary(k => k.Title.Text);

                CellFeed batchRequest = new CellFeed(cellQuery.Uri, service);

                //set up batchrequest
                foreach (KeyValuePair<string, string> entry in writeMap)
                {
                    AtomEntry atomEntry;
                    cellDict.TryGetValue(entry.Key, out atomEntry);
                    CellEntry batchEntry = atomEntry as CellEntry;
                    batchEntry.InputValue = entry.Value;
                    batchEntry.Etag = "*"; //required for compatibility with "new" google sheets (see:  http://stackoverflow.com/questions/22719170/updating-cell-in-google-spreadsheets-returns-error-missing-resource-version-id)
                    batchEntry.BatchData = new GDataBatchEntryData(GDataBatchOperationType.update);

                    batchRequest.Entries.Add(batchEntry);
                }
                CellFeed batchResponse = (CellFeed)service.Batch(batchRequest, new Uri(cellFeed.Batch));

                // Check the results
                bool isSuccess = true;
                foreach (CellEntry entry in batchResponse.Entries)
                {
                    string batchId = entry.BatchData.Id;
                    if (entry.BatchData.Status.Code != 200)
                    {
                        isSuccess = false;
                        GDataBatchStatus status = entry.BatchData.Status;
                    }
                }

                if (!isSuccess)
                {
                    AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Update operations failed");
                }

            //output addresses
            DA.SetDataTree(0, addressesOut); //write addressesOut to first output parameter
        }
Пример #33
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            Grasshopper.Kernel.Data.GH_Structure<DHr> hourTreeIn = new Grasshopper.Kernel.Data.GH_Structure<DHr>();

            if (DA.GetDataTree(0, out hourTreeIn)) {
                Plane plane = new Plane(new Point3d(0, 0, 0), new Vector3d(0, 0, 1));
                DA.GetData(1, ref plane);

                Grasshopper.Kernel.Types.UVInterval ival2d = new Grasshopper.Kernel.Types.UVInterval();
                if (!DA.GetData(2, ref ival2d)) {
                    ival2d.U0 = 0.0;
                    ival2d.U1 = 1.0;
                    ival2d.V0 = 0.0;
                    ival2d.V1 = 2.0;
                }
                if (ival2d.U.IsDecreasing) ival2d.U.Swap();
                if (ival2d.V.IsDecreasing) ival2d.V.Swap();

                double barWidthScale = 1.0;
                DA.GetData(3, ref barWidthScale);

                Grasshopper.Kernel.Data.GH_Structure<DHr> hourTreeOut = new Grasshopper.Kernel.Data.GH_Structure<DHr>();
                Grasshopper.Kernel.Data.GH_Structure<Grasshopper.Kernel.Types.GH_Point> points = new Grasshopper.Kernel.Data.GH_Structure<Grasshopper.Kernel.Types.GH_Point>();
                Grasshopper.Kernel.Data.GH_Structure<Grasshopper.Kernel.Types.GH_Rectangle> srects = new Grasshopper.Kernel.Data.GH_Structure<Grasshopper.Kernel.Types.GH_Rectangle>();
                List<Rectangle3d> rects = new List<Rectangle3d>();
                List<Mesh> meshes = new List<Mesh>();

                int i = 0;//keeps track of which branch we're on... note, this assumes we've been passed a list of lists and nothing 'deeper'
                int maxHourCount = hourTreeIn.Branches[0].Count;
                foreach (List<DHr> hourList in hourTreeIn.Branches) if (hourList.Count > maxHourCount) maxHourCount = hourList.Count;
                Rectangle3d brect = new Rectangle3d(plane, new Interval(0, ival2d.U1), new Interval(0, ival2d.V.ParameterAt((double)hourTreeIn.DataCount / maxHourCount)));
                DA.SetData(5, brect);

                double dx = ival2d.U.Length / hourTreeIn.Branches.Count * barWidthScale;
                double dy = ival2d.V.Length / maxHourCount;
                foreach (List<DHr> hourList in hourTreeIn.Branches) {
                    Grasshopper.Kernel.Data.GH_Path path = new Grasshopper.Kernel.Data.GH_Path(i);
                    hourTreeOut.EnsurePath(path);
                    points.EnsurePath(path);
                    srects.EnsurePath(path);

                    double x = ival2d.U.ParameterAt((i + 0.5) / hourTreeIn.Branches.Count);
                    for (int j = 0; j < hourList.Count; j++) {
                        DHr dhour = hourList[j];

                        double y = ival2d.V.ParameterAt((j + 0.5) / maxHourCount);
                        Point3d pt = plane.PointAt(x, y);
                        dhour.pos = new Point3d(x, y, 0);
                        points.Append(new Grasshopper.Kernel.Types.GH_Point(pt), path);
                        hourTreeOut.Append(dhour, path);

                        Plane pln = new Plane(plane);
                        pln.Origin = plane.PointAt(x - dx / 2, y - dy / 2);
                        Rectangle3d rct = new Rectangle3d(pln, dx, dy);
                        srects.Append(new Grasshopper.Kernel.Types.GH_Rectangle(rct), path);
                    }

                    // make meshes & big rectangles
                    if (hourList.Count > 0) {
                        Mesh mesh = new Mesh();
                        // add bottom pts
                        mesh.Vertices.Add(plane.PointAt(x - dx / 2, 0));
                        mesh.VertexColors.Add(hourList[0].color);
                        mesh.Vertices.Add(plane.PointAt(x + dx / 2, 0));
                        mesh.VertexColors.Add(hourList[0].color);

                        for (int j = 0; j < hourList.Count; j++) {
                            double y = ival2d.V.ParameterAt((j + 0.5) / maxHourCount);
                            mesh.Vertices.Add(plane.PointAt(x - dx / 2, y));
                            mesh.VertexColors.Add(hourList[j].color);
                            mesh.Vertices.Add(plane.PointAt(x + dx / 2, y));
                            mesh.VertexColors.Add(hourList[j].color);
                        }

                        // add top pts
                        double yy = ival2d.V.ParameterAt((float)hourList.Count / maxHourCount);
                        mesh.Vertices.Add(plane.PointAt(x - dx / 2, yy));
                        mesh.VertexColors.Add(hourList[hourList.Count - 1].color);
                        mesh.Vertices.Add(plane.PointAt(x + dx / 2, yy));
                        mesh.VertexColors.Add(hourList[hourList.Count - 1].color);

                        for (int n = 2; n < mesh.Vertices.Count; n = n + 2) mesh.Faces.AddFace(n - 2, n - 1, n + 1, n);
                        meshes.Add(mesh);

                        Plane pln = new Plane(plane);
                        pln.Origin = plane.PointAt(x - dx / 2, 0);
                        Rectangle3d rct = new Rectangle3d(pln, dx, yy);
                        rects.Add(rct);
                    }

                    i++;
                }

                DA.SetDataTree(0, hourTreeOut);
                DA.SetDataTree(1, points);
                DA.SetDataList(2, srects);
                DA.SetDataList(3, rects);
                DA.SetDataList(4, meshes);

            }
        }
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            //---- Declareing ---------------------------------------------------------------------------
            GH_Structure<GH_Point> PtL01;
            DA.GetDataTree("Layer 01 Points", out PtL01);

            GH_Structure<GH_Point> PtL02;
            DA.GetDataTree("Layer 02 Points", out PtL02);

            GH_Structure<GH_Integer> TopoPtIdx;
            DA.GetDataTree("Topology Points", out TopoPtIdx);

            GH_Structure<GH_Integer> NFIdx;
            DA.GetDataTree("Neighbour Face Index", out NFIdx);

            GH_Structure<GH_Integer> All_TopoEdges;
            DA.GetDataTree("Face Topology Edge Indexies", out All_TopoEdges);

            GH_Structure<GH_Point> EdgeCentreL01;
            DA.GetDataTree("Edge Centre L01", out EdgeCentreL01);

            GH_Structure<GH_Point> EdgeCentreL02;
            DA.GetDataTree("Edge Centre L02", out EdgeCentreL02);

            List<double> CtrlPSc = new List<double>();
            DA.GetDataList<double>("Curve Control Point Tangent Scalar", CtrlPSc);

            List<double> PentPSc = new List<double>();
            DA.GetDataList<double>("Planar Pentagon Point Tangent Scalar", PentPSc);

            List<bool> openclosed = new List<bool>();
            DA.GetDataList<bool>("Plate?", openclosed);

            // ==================================================================================================
            // Gene Added

            DA.GetData<bool>("Allow PolySrf", ref iAllowPolySrf);
            // ==================================================================================================

            List<Tri_Loop_Component> All_Components = new List<Tri_Loop_Component>();

            //---- End Declareing -----------------------------------------------------------------------

            //---- Functions ----------------------------------------------------------------------------

            for (int i = 0; i < PtL01.Branches.Count; i++)
            {
                // List 01
                List<Point3d> _ptL01 = new List<Point3d>();
                foreach (GH_Point pt in PtL01[i])
                    _ptL01.Add(pt.Value);

                // List 02
                List<Point3d> _ptL02 = new List<Point3d>();
                foreach (GH_Point pt in PtL02[i])
                    _ptL02.Add(pt.Value);

                // List TopoPtIdx
                List<int> _topoVidx = new List<int>();
                foreach (GH_Integer integer in TopoPtIdx[i])
                    _topoVidx.Add(integer.Value);

                // List TopoPtIdx
                List<int> _nFIdx = new List<int>();
                foreach (GH_Integer integer in NFIdx[i])
                    _nFIdx.Add(integer.Value);

                // List TopoEdges
                List<int> _topoEdges = new List<int>();
                foreach (GH_Integer integer in All_TopoEdges[i])
                    _topoEdges.Add(integer.Value);

                // EdgeCentreL01
                List<Point3d> _edgeCentreL01 = new List<Point3d>();
                foreach (GH_Point cntr in EdgeCentreL01[i])
                    _edgeCentreL01.Add(cntr.Value);

                // EdgeCentreL02
                List<Point3d> _edgeCentreL02 = new List<Point3d>();
                foreach (GH_Point cntr in EdgeCentreL02[i])
                    _edgeCentreL02.Add(cntr.Value);

                // Create Components
                //Tri_Loop_Component component = new Tri_Loop_Component(_ptL01, _ptL02, _topoVidx, _nFIdx, _topoEdges, _edgeCentreL01, _edgeCentreL02, i);

                // ======================================================================================================================
                // Gene Added with documentTolerance
                Tri_Loop_Component component = new Tri_Loop_Component(_ptL01, _ptL02, _topoVidx, _nFIdx, _topoEdges, _edgeCentreL01, _edgeCentreL02, i, documentTolerance);
                // ======================================================================================================================

                component.Run(PentPSc, CtrlPSc, openclosed);

                // ======================================================================================================================
                // Gene Added with documentTolerance
                if (!iAllowPolySrf)
                    component.RunSingle();
                // ======================================================================================================================

                // add to component list
                All_Components.Add(component);
            }
            //---- End Functions --------------------------------------------------------------------------

            //---- Set Output -----------------------------------------------------------------------------

            DA.SetDataList(0, All_Components);

            //---- End Set Output -------------------------------------------------------------------------
        }
Пример #35
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            GH_Structure<IGH_Goo> Input = new GH_Structure<IGH_Goo>();
            DA.GetDataTree("Input", out Input);

            GH_Structure<HashType> Output = new GH_Structure<HashType>();
            bool bEnumerate = false;
            DA.GetData("Enumerate", ref bEnumerate);
            // iterate through all the sources by the Params.input value (and thus bypass the DA object, is this ugly?)

            foreach (IGH_Param Param in this.Params.Input[0].Sources)
            {

                foreach (GH_Path path in Input.Paths)
                {
                    String nickname = Param.NickName;
                    if (nickname.Length == 0)
                    {
                        this.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Nickname of the connected component is empty");
                        nickname = "Anonymous";
                    }
                    List<object> DataList = new List<object>();
                    IEnumerable Data = Param.VolatileData.get_Branch(path);
                    if (Data != null)
                    {
                        foreach (object item in Data)
                        {
                            if (item != null)
                            {
                                DataList.Add(item);
                            }
                            else
                            {
                                DataList.Add("");
                            }
                        }
                    }
                    //
                    // Add the data to the list. If result is a tree or something similar: this means the results will be flattened.

                    if (Data == null || DataList.Count == 0)
                    {

                    }
                    else if (DataList.Count == 1)
                    {
                        // If the component has a single output: name it singular
                        Output.Append(new HashType(nickname, DataList[0]), path);
                    }
                    else if (DataList.Count > 1)
                    {
                        // .. otherwise: add a
                        int j = 0;
                        if (bEnumerate)
                        {
                            foreach (object item in DataList)
                            {
                                Output.Append(new HashType(String.Format("{0}_{1}", nickname, j), item), path);
                                j++;
                            }
                        }
                        else
                        {
                            Output.Append(new HashType(nickname, DataList), path);
                        }
                    }
                }
            }
            DA.SetDataTree(0, Output);
        }
Пример #36
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            this.JSONIsPopulated = false;
            this.JSONString = "";
            Grasshopper.Kernel.Data.GH_Structure<Grasshopper.Kernel.Types.IGH_Goo> tree = new Grasshopper.Kernel.Data.GH_Structure<Grasshopper.Kernel.Types.IGH_Goo>();
            if (!DA.GetDataTree(0, out tree)) { return; }

            String JSONOpen = "";
            String JSONClose = "";
            JSONOpen = @"""" + this.ComponentName + @""":{";
            JSONClose = "}";

            DataStructure dim;
            if (tree.PathCount == 1) {
                if (tree.DataCount == 1) dim = DataStructure.Singleton; // a singleton
                else dim = DataStructure.List; // a list
            } else dim = DataStructure.Tree; // a tree
            JSONOpen += @"""DataStructure"":""" + dim.ToString() + @""",";

            String UniformType = "";
            bool IsUniform = JSONConverter.UniformDataType(tree, ref UniformType);
            if (IsUniform) JSONOpen += @"""Type"":""" + UniformType + @""",";

            if (dim == DataStructure.Singleton) {
                // SINGLETONS
                //
                String ObjString = "";
                IGH_Goo obj = tree.get_FirstItem(false);
                if ((obj != null)&&(JSONConverter.ObjectToJSON(obj, ref ObjString,false))){
                    this.JSONString = JSONOpen + @"""Value"":"+ObjString + JSONClose;
                    DA.SetData(0, "{" + this.JSONString + "}");
                    this.JSONIsPopulated = true;
                    return;
                } else {
                    // TODO: return failed item
                    this.JSONIsPopulated = false;
                    return;
                }
            } else if (dim == DataStructure.List) {
                // LISTS
                //

                JSONOpen += @"""Items"":{";
                JSONClose += "}";

                List<IGH_Goo> failures = new List<IGH_Goo>();
                List<String> ObjStrings = JSONConverter.ObjectsToJSON(tree.get_Branch(tree.Paths[0]), ref failures, !IsUniform);
                if (failures.Count > 0) AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Some items failed to be converted to JSON.");
                if (ObjStrings.Count == 0) {
                    AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Nothing was successfully converted to JSON.");
                    this.JSONIsPopulated = false;
                    return;
                }

                this.JSONString = JSONOpen + String.Join(",", ObjStrings.ToArray()) + JSONClose;
                DA.SetData(0, "{"+this.JSONString+"}");
                this.JSONIsPopulated = true;
                // TODO: return failed items
                return;
            } else {
                // TREES
                //
                JSONOpen += @"""BranchCount"":" + tree.Branches.Count + @",""DataCount"":" + tree.DataCount + @", ""Paths"":{";
                JSONClose += "}";

                List<IGH_Goo> failures = new List<IGH_Goo>();
                List<String> BranchStrings = new List<string>();

                foreach (Grasshopper.Kernel.Data.GH_Path path in tree.Paths) {
                    String BRANCHOpen = @"""" + path.ToString() + @""":{";
                    String BRANCHClose = "}";

                    List<String> ObjStrings = JSONConverter.ObjectsToJSON(tree.get_Branch(path), ref failures, !IsUniform);
                    if (ObjStrings.Count >= 0) {
                        BranchStrings.Add(BRANCHOpen + String.Join(",", ObjStrings.ToArray()) + BRANCHClose);
                    } else {
                        AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "An entire branch failed to be converted to JSON.");
                    }
                }

                if (failures.Count > 0) AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Some items failed to be converted to JSON.");

                this.JSONString = JSONOpen + String.Join(",", BranchStrings.ToArray()) + JSONClose;
                DA.SetData(0, "{" + this.JSONString + "}");
                this.JSONIsPopulated = true;
                // TODO: return failed items
                return;
            }
            //if (JSONConverter.ObjectToJSON(obj, ref JSONString)) DA.SetData(0, JSONString);
            //DA.SetData(0, tree.PathCount.ToString());
        }
Пример #37
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            bool runCommand = false;
            GH_Structure<GH_Point> origPoints = new GH_Structure<GH_Point>();
            GH_Structure<GH_Point> adaptPoints = new GH_Structure<GH_Point>();
            GH_Structure<GH_Curve> curves = new GH_Structure<GH_Curve>();
            GH_Structure<GH_Vector> orientations = new GH_Structure<GH_Vector>();
            GH_Structure<GH_Vector> faceOrientations = new GH_Structure<GH_Vector>();
            DA.GetData(0, ref runCommand);
            DA.GetDataTree(1, out origPoints);
            DA.GetDataTree(2, out adaptPoints);
            DA.GetDataTree(3, out curves);
            DA.GetDataTree(4, out orientations);
            DA.GetDataTree(5, out faceOrientations);

            // Make sure the family and type is set before running the command.
            if (runCommand && (familyName == null || familyName == "Not Selected"))
            {
                message = "Please select a family/type by double-clicking on the component before running the command.";
            }
            else if (runCommand)
            {
                // Get the scale
                GHInfo ghi = new GHInfo();
                GHScale scale = ghi.GetScale(Rhino.RhinoDoc.ActiveDoc);

                // Send to Revit
                LyrebirdChannel channel = new LyrebirdChannel(appVersion);
                channel.Create();

                if (channel != null)
                {
                    string documentName = channel.DocumentName();
                    if (documentName != null)
                    {
                        // Create RevitObjects
                        List<RevitObject> obj = new List<RevitObject>();

                        #region OriginPoint Based
                        if (origPoints != null && origPoints.Branches.Count > 0)
                        {
                            List<RevitObject> tempObjs = new List<RevitObject>();
                            // make sure the branches match the datacount
                            if (origPoints.Branches.Count == origPoints.DataCount)
                            {
                                for (int i = 0; i < origPoints.Branches.Count; i++)
                                {
                                    GH_Point ghpt = origPoints[i][0];
                                    LyrebirdPoint point = new LyrebirdPoint
                                    {
                                        X = ghpt.Value.X,
                                        Y = ghpt.Value.Y,
                                        Z = ghpt.Value.Z
                                    };

                                    RevitObject ro = new RevitObject
                                    {
                                        Origin = point,
                                        FamilyName = familyName,
                                        TypeName = typeName,
                                        Category = category,
                                        CategoryId = categoryId,
                                        GHPath = origPoints.Paths[i].ToString(),
                                        GHScaleFactor = scale.ScaleFactor,
                                        GHScaleName = scale.ScaleName
                                    };

                                    tempObjs.Add(ro);
                                }
                                obj = tempObjs;
                            }
                            else
                            {
                                // Inform the user they need to graft their inputs.  Only one point per branch
                                System.Windows.Forms.MessageBox.Show("Warning:\n\nEach Branch represents an object, " +
                                    "so origin point based elements should be grafted so that each point is on it's own branch.");
                            }
                        }
                        #endregion

                        #region AdaptiveComponents
                        else if (adaptPoints != null && adaptPoints.Branches.Count > 0)
                        {
                            // generate adaptive components
                            List<RevitObject> tempObjs = new List<RevitObject>();
                            for (int i = 0; i < adaptPoints.Branches.Count; i++)
                            {
                                RevitObject ro = new RevitObject();
                                List<LyrebirdPoint> points = new List<LyrebirdPoint>();
                                for (int j = 0; j < adaptPoints.Branches[i].Count; j++)
                                {
                                    LyrebirdPoint point = new LyrebirdPoint(adaptPoints.Branches[i][j].Value.X, adaptPoints.Branches[i][j].Value.Y, adaptPoints.Branches[i][j].Value.Z);
                                    points.Add(point);
                                }
                                ro.AdaptivePoints = points;
                                ro.FamilyName = familyName;
                                ro.TypeName = typeName;
                                ro.Origin = null;
                                ro.Category = category;
                                ro.CategoryId = categoryId;
                                ro.GHPath = adaptPoints.Paths[i].ToString();
                                ro.GHScaleFactor = scale.ScaleFactor;
                                ro.GHScaleName = scale.ScaleName;
                                tempObjs.Add(ro);
                            }
                            obj = tempObjs;

                        }
                        #endregion

                        #region Curve Based
                        else if (curves != null && curves.Branches.Count > 0)
                        {
                            // Get curves for curve based components

                            // Determine if we're profile or line based
                            if (curves.Branches.Count == curves.DataCount)
                            {
                                // Determine if the curve is a closed planar curve
                                Curve tempCrv = curves.Branches[0][0].Value;
                                if (tempCrv.IsPlanar(0.00000001) && tempCrv.IsClosed)
                                {
                                    // Closed planar curve
                                    List<RevitObject> tempObjs = new List<RevitObject>();
                                    for (int i = 0; i < curves.Branches.Count; i++)
                                    {
                                        Curve crv = curves[i][0].Value;
                                        List<Curve> rCurves = new List<Curve>();
                                        bool getCrvs = CurveSegments(rCurves, crv, true);
                                        if (rCurves.Count > 0)
                                        {
                                            RevitObject ro = new RevitObject();
                                            List<LyrebirdCurve> lbCurves = new List<LyrebirdCurve>();
                                            for (int j = 0; j < rCurves.Count; j++)
                                            {
                                                LyrebirdCurve lbc;
                                                lbc = GetLBCurve(rCurves[j]);
                                                lbCurves.Add(lbc);
                                            }
                                            ro.Curves = lbCurves;
                                            ro.FamilyName = familyName;
                                            ro.Category = category;
                                            ro.CategoryId = categoryId;
                                            ro.TypeName = typeName;
                                            ro.Origin = null;
                                            ro.GHPath = curves.Paths[i].ToString();
                                            ro.GHScaleFactor = scale.ScaleFactor;
                                            ro.GHScaleName = scale.ScaleName;
                                            tempObjs.Add(ro);
                                        }
                                    }
                                    obj = tempObjs;

                                }
                                else if (!tempCrv.IsClosed)
                                {
                                    // Line based.  Can only be arc or linear curves
                                    List<RevitObject> tempObjs = new List<RevitObject>();
                                    for (int i = 0; i < curves.Branches.Count; i++)
                                    {

                                        Curve ghc = curves.Branches[i][0].Value;
                                        // Test that there is only one curve segment
                                        PolyCurve polycurve = ghc as PolyCurve;
                                        if (polycurve != null)
                                        {
                                            Curve[] segments = polycurve.Explode();
                                            if (segments.Count() != 1)
                                            {
                                                break;
                                            }
                                        }
                                        if (ghc != null)
                                        {
                                            //List<LyrebirdPoint> points = new List<LyrebirdPoint>();
                                            LyrebirdCurve lbc = GetLBCurve(ghc);
                                            List<LyrebirdCurve> lbcurves = new List<LyrebirdCurve> { lbc };

                                            RevitObject ro = new RevitObject
                                            {
                                                Curves = lbcurves,
                                                FamilyName = familyName,
                                                Category = category,
                                                CategoryId = categoryId,
                                                TypeName = typeName,
                                                Origin = null,
                                                GHPath = curves.Paths[i].ToString(),
                                                GHScaleFactor = scale.ScaleFactor,
                                                GHScaleName = scale.ScaleName
                                            };

                                            tempObjs.Add(ro);
                                        }
                                    }
                                    obj = tempObjs;
                                }
                            }
                            else
                            {
                                // Make sure all of the curves in each branch are closed
                                bool allClosed = true;
                                DataTree<CurveCheck> crvTree = new DataTree<CurveCheck>();
                                for (int i = 0; i < curves.Branches.Count; i++)
                                {
                                    List<GH_Curve> ghCrvs = curves.Branches[i];
                                    List<CurveCheck> checkedcurves = new List<CurveCheck>();
                                    GH_Path path = new GH_Path(i);
                                    for (int j = 0; j < ghCrvs.Count; j++)
                                    {
                                        Curve c = ghCrvs[j].Value;
                                        if (c.IsClosed)
                                        {
                                            AreaMassProperties amp = AreaMassProperties.Compute(c);
                                            if (amp != null)
                                            {
                                                double area = amp.Area;
                                                CurveCheck cc = new CurveCheck(c, area);
                                                checkedcurves.Add(cc);
                                            }
                                        }
                                        else
                                        {
                                            allClosed = false;
                                        }
                                    }
                                    if (allClosed)
                                    {
                                        // Sort the curves by area
                                        checkedcurves.Sort((x, y) => x.Area.CompareTo(y.Area));
                                        checkedcurves.Reverse();
                                        foreach (CurveCheck cc in checkedcurves)
                                        {
                                            crvTree.Add(cc, path);
                                        }
                                    }
                                }

                                if (allClosed)
                                {
                                    // Determine if the smaller profiles are within the larger
                                    bool allInterior = true;
                                    List<RevitObject> tempObjs = new List<RevitObject>();
                                    for (int i = 0; i < crvTree.Branches.Count; i++)
                                    {
                                        try
                                        {
                                            List<int> crvSegmentIds = new List<int>();
                                            List<LyrebirdCurve> lbCurves = new List<LyrebirdCurve>();
                                            List<CurveCheck> checkedCrvs = crvTree.Branches[i];
                                            Curve outerProfile = checkedCrvs[0].Curve;
                                            double outerArea = checkedCrvs[0].Area;
                                            List<Curve> planarCurves = new List<Curve>();
                                            planarCurves.Add(outerProfile);
                                            double innerArea = 0.0;
                                            for (int j = 1; j < checkedCrvs.Count; j++)
                                            {
                                                planarCurves.Add(checkedCrvs[j].Curve);
                                                innerArea += checkedCrvs[j].Area;
                                            }
                                            // Try to create a planar surface
                                            IEnumerable<Curve> surfCurves = planarCurves;
                                            Brep[] b = Brep.CreatePlanarBreps(surfCurves);
                                            if (b.Count() == 1)
                                            {
                                                // Test the areas
                                                double brepArea = b[0].GetArea();
                                                double calcArea = outerArea - innerArea;
                                                double diff = (brepArea - calcArea) / calcArea;

                                                if (diff < 0.1)
                                                {
                                                    // The profiles probably are all interior
                                                    foreach (CurveCheck cc in checkedCrvs)
                                                    {
                                                        Curve c = cc.Curve;
                                                        List<Curve> rCurves = new List<Curve>();
                                                        bool getCrvs = CurveSegments(rCurves, c, true);

                                                        if (rCurves.Count > 0)
                                                        {
                                                            int crvSeg = rCurves.Count;
                                                            crvSegmentIds.Add(crvSeg);
                                                            foreach (Curve rc in rCurves)
                                                            {
                                                                LyrebirdCurve lbc;
                                                                lbc = GetLBCurve(rc);
                                                                lbCurves.Add(lbc);
                                                            }
                                                        }
                                                    }
                                                    RevitObject ro = new RevitObject();
                                                    ro.Curves = lbCurves;
                                                    ro.FamilyName = familyName;
                                                    ro.Category = category;
                                                    ro.CategoryId = categoryId;
                                                    ro.TypeName = typeName;
                                                    ro.Origin = null;
                                                    ro.GHPath = crvTree.Paths[i].ToString();
                                                    ro.GHScaleFactor = scale.ScaleFactor;
                                                    ro.GHScaleName = scale.ScaleName;
                                                    ro.CurveIds = crvSegmentIds;
                                                    tempObjs.Add(ro);
                                                }
                                            }
                                            else
                                            {
                                                allInterior = false;
                                                message = "Warning:\n\nEach Branch represents an object, " +
                                                "so curve based elements should be grafted so that each curve is on it's own branch, or all curves on a branch should " +
                                                "be interior to the largest, outer boundary.";
                                            }
                                        }
                                        catch
                                        {
                                            allInterior = false;
                                            // Inform the user they need to graft their inputs.  Only one curve per branch
                                            message = "Warning:\n\nEach Branch represents an object, " +
                                                "so curve based elements should be grafted so that each curve is on it's own branch, or all curves on a branch should " +
                                                "be interior to the largest, outer boundary.";
                                        }
                                    }
                                    if (tempObjs.Count > 0)
                                    {
                                        obj = tempObjs;
                                    }
                                }
                            }
                        }
                        #endregion

                        // Orientation
                        if (orientations != null && orientations.Branches.Count > 0)
                        {
                            List<RevitObject> tempList = AssignOrientation(obj, orientations);
                            obj = tempList;
                        }

                        // face orientation
                        if (faceOrientations != null && faceOrientations.Branches.Count > 0)
                        {
                            List<RevitObject> tempList = AssignFaceOrientation(obj, faceOrientations);
                            obj = tempList;
                        }

                        // Parameters...
                        if (Params.Input.Count > 6)
                        {
                            List<RevitObject> currentObjs = obj;
                            List<RevitObject> tempObjs = new List<RevitObject>();
                            for (int r = 0; r < currentObjs.Count; r++)
                            {
                                RevitObject ro = currentObjs[r];
                                List<RevitParameter> revitParams = new List<RevitParameter>();
                                for (int i = 6; i < Params.Input.Count; i++)
                                {

                                    RevitParameter rp = new RevitParameter();
                                    IGH_Param param = Params.Input[i];
                                    string paramInfo = param.Description;
                                    string[] pi = paramInfo.Split(new[] { "\n", ":" }, StringSplitOptions.None);
                                    string paramName = null;
                                    try
                                    {
                                        paramName = pi[1].Substring(1);
                                        string paramStorageType = pi[5].Substring(1);
                                        rp.ParameterName = paramName;
                                        rp.StorageType = paramStorageType;
                                    }
                                    catch (Exception ex)
                                    {
                                        Debug.WriteLine(ex.Message);
                                    }
                                    if (paramName != null)
                                    {
                                        GH_Structure<IGH_Goo> data = null;
                                        try
                                        {
                                            DA.GetDataTree(i, out data);
                                        }
                                        catch (Exception ex)
                                        {
                                            Debug.WriteLine(ex.Message);
                                        }
                                        if (data != null)
                                        {
                                            string value = data[r][0].ToString();
                                            rp.Value = value;
                                            revitParams.Add(rp);
                                        }
                                    }

                                }
                                ro.Parameters = revitParams;
                                tempObjs.Add(ro);
                            }
                            obj = tempObjs;
                        }

                        // Send the data to Revit to create and/or modify family instances.
                        if (obj != null && obj.Count > 0)
                        {
                            try
                            {
                                string docName = channel.DocumentName();
                                if (docName == null || docName == string.Empty)
                                {
                                    message = "Could not contact the lyrebird server.  Make sure it's running and try again.";
                                }
                                else
                                {
                                    string nn = NickName;
                                    if (nn == null || nn.Length == 0)
                                    {
                                        nn = "LBOut";
                                    }
                                    channel.CreateOrModify(obj, InstanceGuid, NickName);
                                    message = obj.Count.ToString() + " objects sent to the lyrebird server.";
                                }
                            }
                            catch
                            {
                                message = "Could not contact the lyrebird server.  Make sure it's running and try again.";
                            }
                        }
                        channel.Dispose();
                        try
                        {
                        }
                        catch (Exception ex)
                        {
                            Debug.WriteLine(ex.Message);
                        }
                    }
                    else
                    {
                        message = "Error\n" + "The Lyrebird Service could not be found.  Ensure Revit is running, the Lyrebird server plugin is installed, and the server is active.";
                    }
                }
            }
            else
            {
                message = null;
            }

            // Check if the revit information is set
            if (familyName != null || (familyName != "Not Selected" && typeName != "Not Selected"))
            {
                StringBuilder sb = new StringBuilder();
                sb.AppendLine("Family: " + familyName);
                sb.AppendLine("Type: " + typeName);
                sb.AppendLine("Category: " + category);
                for (int i = 0; i < inputParameters.Count; i++)
                {
                    RevitParameter rp = inputParameters[i];
                    string type = "Instance";
                    if (rp.IsType)
                    {
                        type = "Type";
                    }
                    sb.AppendLine(string.Format("Parameter{0}: {1}  /  {2}  /  {3}", (i + 1).ToString(CultureInfo.InvariantCulture), rp.ParameterName, rp.StorageType, type));
                }
                objMessage = sb.ToString();
            }
            else
            {
                objMessage = "No data type set.  Double-click to set data type";
            }

            DA.SetData(0, objMessage);
            DA.SetData(1, message);
        }
Пример #38
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            Grasshopper.Kernel.Data.GH_Structure<DHr> hourTreeIn = new Grasshopper.Kernel.Data.GH_Structure<DHr>();
            String key = "";
            if (DA.GetDataTree(0, out hourTreeIn) && DA.GetData(1, ref key)) {

                Interval ival_y = new Interval();
                float[] garbage = new float[0];
                if (!(DA.GetData(2, ref ival_y))) DHr.get_domain(key, hourTreeIn.ToArray(), ref garbage, ref ival_y); // vals are no good here, we would need a tree of values

                Plane plane = new Plane(new Point3d(0, 0, 0), new Vector3d(0, 0, 1));
                DA.GetData(3, ref plane);

                Grasshopper.Kernel.Types.UVInterval ival2d = new Grasshopper.Kernel.Types.UVInterval();
                if (!DA.GetData(4, ref ival2d)) {
                    ival2d.U0 = 0.0;
                    ival2d.U1 = 12.0;
                    ival2d.V0 = 0.0;
                    ival2d.V1 = 1.0;
                }

                double barWidth = 1.0;
                DA.GetData(5, ref barWidth);

                Grasshopper.Kernel.Data.GH_Structure<DHr> hourTreeOut = new Grasshopper.Kernel.Data.GH_Structure<DHr>();
                Grasshopper.Kernel.Data.GH_Structure<Grasshopper.Kernel.Types.GH_Point> points = new Grasshopper.Kernel.Data.GH_Structure<Grasshopper.Kernel.Types.GH_Point>();
                Grasshopper.Kernel.Data.GH_Structure<Grasshopper.Kernel.Types.GH_Rectangle> rects = new Grasshopper.Kernel.Data.GH_Structure<Grasshopper.Kernel.Types.GH_Rectangle>();

                double ival2d_u_delta = ival2d.U.Length / hourTreeIn.Branches.Count;

                for (int b = 0; b < hourTreeIn.Branches.Count; b++) {
                    List<DHr> hours = hourTreeIn.Branches[b];
                    Grasshopper.Kernel.Data.GH_Path path = new Grasshopper.Kernel.Data.GH_Path(b);
                    hourTreeOut.EnsurePath(path);
                    points.EnsurePath(path);
                    rects.EnsurePath(path);

                    Grasshopper.Kernel.Types.UVInterval ival2d_sub = new Grasshopper.Kernel.Types.UVInterval(new Interval(b * ival2d_u_delta, (b + 1) * ival2d_u_delta), ival2d.V);
                    double t0_sub = ival2d_sub.U.Mid - (ival2d_sub.U.Mid - ival2d_sub.U.T0) * barWidth;
                    double t1_sub = ival2d_sub.U.Mid + (ival2d_sub.U.T1 - ival2d_sub.U.Mid) * barWidth;
                    ival2d_sub.U = new Interval(t0_sub, t1_sub);

                    for (int h = 0; h < hours.Count; h++) {
                        Point3d gpt = GraphPoint(hours[h].hr % 24, hours[h].val(key), plane, ival_y, ival2d_sub); // returns a point in graph coordinates
                        hours[h].pos = gpt; // the hour records the point in graph coordinates
                        hourTreeOut.Append(hours[h], path);

                        Point3d wpt = plane.PointAt(gpt.X, gpt.Y);
                        points.Append(new Grasshopper.Kernel.Types.GH_Point(wpt), path);  // adds this point in world coordinates

                        double delta_x2 = (Math.Abs(ival2d_sub.U.Length) / 24.0 / 2.0);
                        Interval ival_gx = new Interval(gpt.X - delta_x2, gpt.X + delta_x2); // interval of horz space occupied by this hour in graphic units
                        Interval ival_gy = new Interval(ival2d_sub.V0, gpt.Y); // interval of vertical space occupied by this hour in graphic units

                        Rectangle3d rect = new Rectangle3d(plane, ival_gx, ival_gy);
                        rects.Append(new Grasshopper.Kernel.Types.GH_Rectangle(rect), path);

                    }
                }

                DA.SetDataTree(0, hourTreeOut);
                DA.SetDataTree(1, points);
                DA.SetDataTree(2, rects);

            }
        }
Пример #39
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            Grasshopper.Kernel.Data.GH_Structure<DHr> hourTreeIn = new Grasshopper.Kernel.Data.GH_Structure<DHr>();
            string key = "";
            int subdivs = 0;
            if ((DA.GetDataTree(0, out hourTreeIn)) && (DA.GetData(1, ref key)) && (DA.GetData(3, ref subdivs)))
            {
                Interval ival_overall = new Interval();
                if (!DA.GetData(2, ref ival_overall)) {
                    // go thru the given hours and find the max and min value for the given key
                    ival_overall.T0 = MDHr.INVALID_VAL;
                    ival_overall.T1 = MDHr.INVALID_VAL;
                    foreach (DHr dhr in hourTreeIn.AllData(true)) {
                        float val = dhr.val(key);
                        if ((ival_overall.T0 == MDHr.INVALID_VAL) || (val < ival_overall.T0)) ival_overall.T0 = val;
                        if ((ival_overall.T1 == MDHr.INVALID_VAL) || (val > ival_overall.T1)) ival_overall.T1 = val;
                    }
                }

                Grasshopper.Kernel.Data.GH_Structure<DHr> hourTreeOut = new Grasshopper.Kernel.Data.GH_Structure<DHr>();
                Grasshopper.Kernel.Data.GH_Structure<Grasshopper.Kernel.Types.GH_Integer> freqTreeOut = new Grasshopper.Kernel.Data.GH_Structure<Grasshopper.Kernel.Types.GH_Integer>();
                Grasshopper.Kernel.Data.GH_Structure<Grasshopper.Kernel.Types.GH_Interval> ivalTreeOut = new Grasshopper.Kernel.Data.GH_Structure<Grasshopper.Kernel.Types.GH_Interval>();

                List<Interval> ivalList = new List<Interval>();
                if (ival_overall.IsDecreasing) ival_overall.Swap();
                double delta = ival_overall.Length / subdivs;
                for (int n = 0; n < subdivs; n++) {  ivalList.Add(new Interval(ival_overall.T0 + n * delta, ival_overall.T0 + ((n + 1) * delta)));  }

                for (int b = 0; b < hourTreeIn.Branches.Count; b++)
                {
                    Grasshopper.Kernel.Data.GH_Structure<DHr> hourBranch = new Grasshopper.Kernel.Data.GH_Structure<DHr>();
                    for (int n = 0; n < subdivs; n++) { hourBranch.EnsurePath(n); }
                    List<int> freqOut = new List<int>();

                    List<DHr> hrsIn = hourTreeIn.Branches[b];
                    foreach (DHr dhr in hrsIn)
                    {
                        if (dhr.val(key) < ivalList[0].T0)
                        {
                            hourBranch.Append(dhr, new Grasshopper.Kernel.Data.GH_Path(0));
                            continue;
                        }
                        if (dhr.val(key) > ivalList[ivalList.Count - 1].T1)
                        {
                            hourBranch.Append(dhr, new Grasshopper.Kernel.Data.GH_Path(ivalList.Count - 1));
                            continue;
                        }
                        for (int n = 0; n < subdivs; n++)
                        {
                            if (ivalList[n].IncludesParameter(dhr.val(key)))
                            {
                                hourBranch.Append(dhr,new Grasshopper.Kernel.Data.GH_Path(n));
                                break;
                            }
                        }
                    }

                    for (int bb = 0; bb < hourBranch.Branches.Count; bb++)
                    {
                        Grasshopper.Kernel.Data.GH_Path branch_path = hourTreeIn.Paths[b].AppendElement(bb);
                        hourTreeOut.AppendRange(hourBranch.Branches[bb], branch_path);
                        Grasshopper.Kernel.Types.GH_Integer freq = new Grasshopper.Kernel.Types.GH_Integer(hourBranch.Branches[bb].Count);
                        freqTreeOut.Append(freq, branch_path);
                        Grasshopper.Kernel.Types.GH_Interval ival = new Grasshopper.Kernel.Types.GH_Interval(ivalList[bb]);
                        ivalTreeOut.Append(ival, branch_path);
                    }

                }

                hourTreeOut.Simplify(Grasshopper.Kernel.Data.GH_SimplificationMode.CollapseAllOverlaps);
                freqTreeOut.Simplify(Grasshopper.Kernel.Data.GH_SimplificationMode.CollapseAllOverlaps);
                ivalTreeOut.Simplify(Grasshopper.Kernel.Data.GH_SimplificationMode.CollapseAllOverlaps);

                DA.SetDataTree(0, freqTreeOut);
                DA.SetDataTree(1, ivalTreeOut);
                DA.SetDataTree(2, hourTreeOut);
            }
        }
Пример #40
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            List<int> hrs = new List<int>();
            List<string> keys = new List<string>();
            Grasshopper.Kernel.Data.GH_Structure<Grasshopper.Kernel.Types.GH_Number> valtree = new Grasshopper.Kernel.Data.GH_Structure<Grasshopper.Kernel.Types.GH_Number>();
            if ((DA.GetDataList(1, keys)) && (DA.GetDataTree(2, out valtree)) && (DA.GetDataList(0, hrs)))
            {

                bool has_color = false;
                List<Color> colors = new List<Color>();
                has_color = DA.GetDataList(4, colors);

                bool has_pt = false;
                List<Point3d> points = new List<Point3d>();
                has_pt = DA.GetDataList(4, points);

                if (hrs.Count != valtree.Branches.Count) this.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "List matching error.  Hours and Vals must match.  If you pass in more than one hour number, then you must pass in a tree of values with one branch per hour number, and vice-versa.");
                else foreach (List<GH_Number> branch in valtree.Branches) if (keys.Count != branch.Count) this.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "List matching error.  Keys and Vals must offer lists of the same length.  If you pass in a tree of values, each branch must contain a list of the same length as the list of keys.");
                        else
                        {
                            if (((has_color) && (colors.Count != hrs.Count)) || ((has_pt) && (points.Count != hrs.Count)))
                            {
                                this.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "List matching error.");
                                return;
                            }
                            List<DHr> hours = new List<DHr>();
                            for (int n = 0; n < valtree.Branches.Count; n++)
                            {
                                DHr hr = new DHr(hrs[n]);
                                for (int m = 0; m < keys.Count; m++) hr.put(keys[m], (float)valtree.Branches[n][m].Value);
                                if (has_color) hr.color = colors[n];
                                if (has_pt) hr.pos = points[n];
                                hours.Add(hr);
                            }
                            DA.SetDataList(0, hours);
                        }
            }
        }
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            // getting input
            DA.GetData<SpringMesh>("Spring Mesh", ref iSpringMesh);
            DA.GetDataList<Curve>("PolyLine", iPolyLine);
            DA.GetDataList<int>("PolyLine ID", iPolyLineID);
            DA.GetDataList<double>("Thickness", iThickness);
            DA.GetDataList<bool>("Vertex status", iVertexStatus);
            DA.GetData<bool>("Allow PolySrf", ref iPolySrf);
            DA.GetData<double>("TangentScale Min", ref iTangentScaleMin);
            DA.GetData<double>("TangentScale Max", ref iTangentScaleMax);
            DA.GetDataList<Point3d>("Attractors", iAttractors);
            DA.GetDataList<bool>("Vertex Panel2", iVertexPanel2);
            DA.GetData<double>("PlanarOffset Min", ref iPlanarOffsetScaleMin);
            DA.GetData<double>("PlanarOffset Max", ref iPlanarOffsetScaleMax);
            DA.GetData<double>("Curve Pointiness Min", ref CurvePointinessMin);
            DA.GetData<double>("Curve Pointiness Max", ref CurvePointinessMax);

            DA.GetData<double>("Opening Width Min", ref iOpeningWidthMin);
            DA.GetData<double>("Opening Width Max", ref iOpeningWidthMax);
            DA.GetDataTree<GH_Number>("Manual Adjustments", out ManualValueTree);
            DA.GetData<int>("Curve Degree", ref curveDegree);
            DA.GetData<double>("Ground Level", ref iGroundPos);

            DA.GetData<bool>("Super Normalization", ref iSuperNormalization);
            //------------------------------------------------------------

            // get all Vertex indexies that are manual adjusted
            for (int i = 0; i < ManualValueTree.Branches.Count; i++)
            { ManualAdjustedVertexIndexies.Add(ManualValueTree.Paths[i].Indices[0]); }

            storePlatesTPI();

            calculateVerticesValues();
            calculateVertexNormals();
            calculateVertexCps();
            //calculateVerticesValues();

            triLoop();

            half_dualLoop();

            oDebugList = vertexNormals;

            //------------------------------------------------------------

            // setting output
            DA.SetData("Info", oInfo);
            DA.SetDataList("General List", oDebugList);
            DA.SetDataTree(2, oTriLoop);
            DA.SetDataTree(3, oTriLoopID);
            DA.SetDataTree(4, oTriLoopCurves);
            DA.SetDataTree(5, oDualLoop1);
            DA.SetDataTree(6, oDualLoop2);
            DA.SetDataTree(7, oDualLoop1ID);
            DA.SetDataTree(8, oDualLoop2ID);
            DA.SetDataTree(9, oDualLoop1Curves);
            DA.SetDataTree(10, oDualLoop2Curves);
            DA.SetDataTree(11, oClosedPanel);
            DA.SetDataTree(12, oTriLoopPlanCrv);
            DA.SetDataTree(13, oTriLoopEffectorHoles);

            // -----------------------------------------------------------
        }
Пример #42
0
        protected override void SafeSolveInstance(IGH_DataAccess DA)
        {
            this.InitalizePrivateData();
            GH_Structure<Grasshopper.Kernel.Types.IGH_Goo> geom_tree = new GH_Structure<Grasshopper.Kernel.Types.IGH_Goo>();
            GH_Structure<Decodes_Attributes> attr_tree = new GH_Structure<Decodes_Attributes>();
            if ((DA.GetDataTree<Grasshopper.Kernel.Types.IGH_Goo>(0, out geom_tree)) && (DA.GetDataTree<Decodes_Attributes>(1, out attr_tree)))
            {
                if (geom_tree.PathCount != attr_tree.Branches.Count) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "geometry and property inputs do not have the same number of branches.  check your inputs."); return; }

                for (int b = 0; b < geom_tree.Branches.Count; b++)
                {
                    List<Grasshopper.Kernel.Types.IGH_Goo> geom_given = geom_tree.Branches[b];
                    List<Decodes_Attributes> attr_given = attr_tree.Branches[b];

                    if (geom_given.Count != attr_given.Count) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "geometry and property inputs are not lists of the same length.  check your inputs."); return; }

                    for (int i = 0; i < geom_given.Count; i++)
                    {
                        if (!(geom_given[i] is Grasshopper.Kernel.Types.IGH_GeometricGoo)) { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Did you give me something that isn't geometry?"); continue; }
                        try
                        {
                            m_obj.Add((Grasshopper.Kernel.Types.IGH_GeometricGoo)geom_given[i]);
                            if (!(attr_given[i] is Decodes_Attributes)) m_att.Add(new Decodes_Attributes());
                            else
                            {
                                m_att.Add(attr_given[i]);
                                if (!required_layers.Contains(attr_given[i].layer)) required_layers.Add(attr_given[i].layer);
                            }
                            m_branch_index.Add(b);
                        }
                        catch (Exception e)
                        {
                            AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Did you give me something that looks like geometry, but isn't?\n" + e.Message);
                        }

                    }
                }
            }
        }
Пример #43
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            //---- Declareing ---------------------------------------------------------------------------
            GH_Structure<GH_Brep> AllStripes;
            DA.GetDataTree("Triloop Stipes", out AllStripes);

            GH_Structure<GH_Point> AllPoints;
            DA.GetDataTree("Points", out AllPoints);

            bool Reorient = false;
            DA.GetData<bool>("Merge Stripes", ref Reorient);

            bool Switch = false;
            DA.GetData<bool>("Switch", ref Switch);

            int Seam = 0;
            DA.GetData<int>("Seam", ref Seam);

            DataTree<Brep> AllUnrolledBreps = new DataTree<Brep>();
            DataTree<Brep> ForReorientBreps = new DataTree<Brep>();
            DataTree<Plane> AllOrientPlanes = new DataTree<Plane>();
            DataTree<Curve> AllSharedCurves = new DataTree<Curve>();
            DataTree<Point3d> AllUnrolledPoints = new DataTree<Point3d>();

            //---- End Declareing -----------------------------------------------------------------------
            //---- Functions ----------------------------------------------------------------------------

            #region Unroll

            for (int i = 0; i < AllStripes.Branches.Count; i++)
            {
                GH_Path pth = new GH_Path(i);
                GH_Path originalPath = AllStripes.Paths[i];
                int stripecounter = 0;

                foreach (GH_Brep gbrep in AllStripes[i])
                {
                    Unroller unroll = new Unroller(gbrep.Value);
                    // Add points to unroll with
                    if (AllPoints.Branches.Count != 0)
                    {
                        foreach (GH_Point pt in AllPoints[i])
                        { unroll.AddFollowingGeometry(pt.Value); }
                    }

                    unroll.ExplodeOutput = false;

                    Curve[] curves;
                    Point3d[] unrolledPoints;
                    TextDot[] dots;
                    Brep[] unrolledBreps = unroll.PerformUnroll(out curves, out unrolledPoints, out dots);

                    if (Reorient == false)
                    {
                        foreach (Brep b in unrolledBreps)
                        { AllUnrolledBreps.Add(b, originalPath); }

                        foreach (Point3d p in unrolledPoints)
                        { AllUnrolledPoints.Add(p, originalPath); }
                    }

                    else
                    {
                        foreach (Brep b in unrolledBreps)
                        { AllUnrolledBreps.Add(b, pth.AppendElement(stripecounter)); }
                    }

                    // For reorientation
                    if (Reorient == true)
                    { ForReorientBreps.Add(unrolledBreps[Seam], pth); }

                    stripecounter++;
                }
            }
            #endregion unroll

            if (Reorient == true)
            {
                //ForReorientBreps.Branch(0)[0].Curves3D[0].PointAtEnd;

                for (int i = 0; i < ForReorientBreps.BranchCount; i++)
                {
                    GH_Path pth = new GH_Path(i);

                    foreach (Curve crv0 in ForReorientBreps.Branch(i)[0].Curves3D)
                    {
                        foreach (Curve crv1 in ForReorientBreps.Branch(i)[1].Curves3D)
                        {
                            double l0 = crv0.GetLength();
                            double l1 = crv1.GetLength();

                            if (Math.Abs(l0 - l1) < 0.00001)
                            {

                                // orient crv0
                                Plane origin0 = new Plane(new Point3d(0, 0, 0), new Vector3d(1, 0, 0), new Vector3d(0, 1, 0));
                                Plane target0 = new Plane(origin0);
                                AllOrientPlanes.Add(origin0, pth.AppendElement(0));
                                AllOrientPlanes.Add(target0, pth.AppendElement(0));

                                // orient crv1
                                Vector3d vect0 = crv1.TangentAtStart;
                                Vector3d vect1 = Vector3d.CrossProduct(vect0, new Vector3d(0.0, 0.0, 1.0));
                                Plane origin1 = new Plane(crv1.PointAtStart, vect0, vect1);

                                Vector3d vect2 = new Vector3d();
                                Vector3d vect3 = new Vector3d();
                                Plane target1 = new Plane();

                                if (Switch == true)
                                {
                                    vect2 = crv0.TangentAtStart;
                                    vect3 = Vector3d.CrossProduct(vect2, new Vector3d(0.0, 0.0, 1.0));
                                    target1 = new Plane(crv0.PointAtStart, vect2, vect3);
                                }

                                else
                                {
                                    vect2 = crv0.TangentAtStart;
                                    vect3 = Vector3d.CrossProduct(-vect2, new Vector3d(0.0, 0.0, 1.0));
                                    target1 = new Plane(crv0.PointAtEnd, -vect2, vect3);
                                }

                                AllOrientPlanes.Add(origin1, pth.AppendElement(1));
                                AllOrientPlanes.Add(target1, pth.AppendElement(1));
                                // shared curve of stripe0 and stripe 1
                                AllSharedCurves.Add(crv0, pth.AppendElement(0));
                                AllSharedCurves.Add(crv1, pth.AppendElement(0));

                            }
                        }

                        // orient crv2
                        foreach (Curve crv2 in ForReorientBreps.Branch(i)[2].Curves3D)
                        {
                            double l0 = crv0.GetLength();
                            double l1 = crv2.GetLength();

                            if (Math.Abs(l0 - l1) < 0.00001)
                            {
                                Vector3d vect0 = crv2.TangentAtStart;
                                Vector3d vect1 = Vector3d.CrossProduct(vect0, new Vector3d(0.0, 0.0, 1.0));
                                Plane origin2 = new Plane(crv2.PointAtStart, vect0, vect1);

                                Vector3d vect2 = new Vector3d();
                                Vector3d vect3 = new Vector3d();
                                Plane target2 = new Plane();

                                if (Switch == true)
                                {
                                    vect2 = crv0.TangentAtStart;
                                    vect3 = Vector3d.CrossProduct(vect2, new Vector3d(0.0, 0.0, 1.0));
                                    target2 = new Plane(crv0.PointAtStart, vect2, vect3);
                                }

                                else
                                {
                                    vect2 = crv0.TangentAtStart;
                                    vect3 = Vector3d.CrossProduct(-vect2, new Vector3d(0.0, 0.0, 1.0));
                                    target2 = new Plane(crv0.PointAtEnd, -vect2, vect3);
                                }

                                AllOrientPlanes.Add(origin2, pth.AppendElement(2));
                                AllOrientPlanes.Add(target2, pth.AppendElement(2));
                                // shared curve of stripe0 and stripe 2
                                AllSharedCurves.Add(crv2, pth.AppendElement(2));
                                AllSharedCurves.Add(crv0, pth.AppendElement(2));
                            }
                        }

                    }
                    // find the shared curve oft stripe 1 and stripe 2
                    foreach (Curve crv1 in ForReorientBreps.Branch(i)[1].Curves3D)
                    {
                        foreach (Curve crv2 in ForReorientBreps.Branch(i)[2].Curves3D)
                        {
                            double l1 = crv1.GetLength();
                            double l2 = crv2.GetLength();

                            // shared curve of stripe1 and stripe 2
                            if (Math.Abs(l1 - l2) < 0.00001)
                            {
                                AllSharedCurves.Add(crv1, pth.AppendElement(1));
                                AllSharedCurves.Add(crv2, pth.AppendElement(1));
                            }

                        }

                    }
                }

            }

            //---- End Functions --------------------------------------------------------------------------
            //----Set Output-------------------------------------------------------------------------------

            DA.SetDataTree(0, AllUnrolledBreps);
            DA.SetDataTree(1, AllOrientPlanes);
            DA.SetDataTree(2, AllSharedCurves);
            DA.SetDataTree(3, AllUnrolledPoints);

            //----End Set Output---------------------------------------------------------------------------
        }