Example #1
0
        public string formatCurve(HbCurve curve)
        {
            string curveName   = curve.GetType().Name.Substring(2); //Strips the "Hb"
            string buildString = curveName + ": ";

            switch (curveName)
            {
            case "Arc":
                HbArc arc = (HbArc)curve;
                buildString += formatPoints(arc.PointStart, arc.PointEnd, arc.PointMid);
                break;

            case "Line":
                HbLine line = (HbLine)curve;
                buildString += formatPoints(line.PointStart, line.PointEnd);
                break;

            case "Ellipse":
            case "HermiteSpline":
            case "NurbSpline":
            default:
                break;
            }
            return(buildString);
        }
Example #2
0
 private HbCurve UnitsAndTranslation(HbCurve hbCurve)
 {
     try {
         if (hbCurve is HbLine)
         {
             HbLine hbLine = (HbLine)hbCurve;
             return(new HbLine(UnitsAndTranslation(hbLine.PointStart), UnitsAndTranslation(hbLine.PointEnd)));
         }
         else if (hbCurve is HbArc)
         {
             HbArc hbArc = (HbArc)hbCurve;
             return(new HbArc(UnitsAndTranslation(hbArc.PointStart), UnitsAndTranslation(hbArc.PointEnd), UnitsAndTranslation(hbArc.PointMid)));
         }
         else if (hbCurve is HbEllipse)
         {
             HbEllipse hbEllipse = (HbEllipse)hbCurve;
             return(new HbEllipse(UnitsAndTranslation(hbEllipse.PointFirst), UnitsAndTranslation(hbEllipse.PointSecond), hbEllipse.RadiusY * this.unitsFactor, hbEllipse.Mode));
         }
         else if (hbCurve is HbNurbSpline)
         {
             HbNurbSpline hbNurbSpline = (HbNurbSpline)hbCurve;
             List <HbXYZ> listHbXyz    = new List <HbXYZ>();
             foreach (HbXYZ hbXyz in hbNurbSpline.Points)
             {
                 listHbXyz.Add(UnitsAndTranslation(hbXyz));
             }
             return(new HbNurbSpline(listHbXyz));
         }
         else if (hbCurve is HbHermiteSpline)
         {
             HbHermiteSpline hbHermiteSpline = (HbHermiteSpline)hbCurve;
             List <HbXYZ>    listHbXyz       = new List <HbXYZ>();
             foreach (HbXYZ hbXyz in hbHermiteSpline.Points)
             {
                 listHbXyz.Add(UnitsAndTranslation(hbXyz));
             }
             return(new HbHermiteSpline(listHbXyz));
         }
         else
         {
             return(null);
         }
     }
     catch (Exception exception) {
         this.ErrorMessage = "Error in UnitsAndTranslation: " + exception.Message + ".";
         return(null);
     }
 }
Example #3
0
        public HbCurve Hb(LineCurve lineCurveRhino)
        {
            HbCurve hbCurve       = new HbCurve();
            Point3d xyzRhinoStart = lineCurveRhino.PointAtStart;
            Point3d xyzRhinoEnd   = lineCurveRhino.PointAtEnd;

            //Not sure why we get the midpoint here for a line object?
            //Point3d xyzRhinoMid = lineCurveRhino.PointAt(0.5);
            if (lineCurveRhino.IsLinear())
            {
                HbLine hbLineRevit = new HbLine();
                hbLineRevit.PointStart = new HbXYZ(xyzRhinoStart.X, xyzRhinoStart.Y, xyzRhinoStart.Z);
                hbLineRevit.PointEnd   = new HbXYZ(xyzRhinoEnd.X, xyzRhinoEnd.Y, xyzRhinoEnd.Z);
                hbCurve = hbLineRevit;
            }
            return(hbCurve);
        }
Example #4
0
        public bool ReadDataTreeBranch(List <Grasshopper.Kernel.Types.GH_Curve> branches, ref List <List <HbCurve> > curvesListListRevit, bool AllowNurbs, bool NestBranch)
        {
            try {
                Rhino.Geometry.NurbsCurve nurbsCurveRhino;
                Rhino.Geometry.LineCurve  lineCurveRhino;
                Rhino.Geometry.ArcCurve   arcCurveRhino;
                List <HbCurve>            curvesListRevit = new List <HbCurve>();

                for (int i = 0; i < branches.Count; i++)
                {
                    //if (NestBranch)  curvesListRevit.Clear();
                    if (NestBranch)
                    {
                        curvesListRevit = new List <HbCurve>();
                    }
                    GH_Curve branch       = branches[i];
                    Curve    curveBranch  = null;
                    Curve    curveBranch2 = null;
                    GH_Convert.ToCurve(branch, ref curveBranch, GH_Conversion.Both);
                    if (curveBranch == null)
                    {
                        Print("Null branch value in ReadDataTreeBranch() ignored.");
                        continue;
                    }

                    switch (curveBranch.GetType().Name)
                    {
                    case "PolyCurve":
                        // Note:  The simplify functions only used with a PolyCureve so moved inside the switch statement.
                        // Note:  Logic of this step is not clear.  It may be that only the CurveSimplifyOptions.All
                        if (curveBranch.Degree == 1)
                        {
                            curveBranch2 = curveBranch.Simplify(CurveSimplifyOptions.RebuildLines, 0, 0);
                            if (curveBranch2 == null)
                            {
                                Print("Simplify() with CurveSimplifyOptions.RebuildLines returned null.");
                            }
                            else
                            {
                                curveBranch = curveBranch2;
                            }
                        }
                        if (curveBranch.Degree == 2)
                        {
                            curveBranch2 = curveBranch.Simplify(CurveSimplifyOptions.RebuildArcs, 0, 0);
                            if (curveBranch2 == null)
                            {
                                Print("Simplify() with CurveSimplifyOptions.RebuildArcs returned null.");
                            }
                            else
                            {
                                curveBranch = curveBranch2;
                            }
                        }
                        curveBranch2 = curveBranch.Simplify(CurveSimplifyOptions.All, .0001, 1);
                        if (curveBranch2 == null)
                        {
                            Print("Simplify() with CurveSimplifyOptions.All returned null.");
                        }
                        else
                        {
                            curveBranch = curveBranch2;
                        }
                        PolyCurve polyCurve = (PolyCurve)curveBranch;
                        for (int j = 0; j < polyCurve.SegmentCount; j++)
                        {
                            Curve curveRhino = polyCurve.SegmentCurve(j);
                            switch (curveRhino.GetType().Name)
                            {
                            case "LineCurve":
                                lineCurveRhino = (LineCurve)curveRhino;
                                curvesListRevit.Add(Hb(lineCurveRhino));
                                break;

                            case "NurbsCurve":
                                if (!AllowNurbs)
                                {
                                    break;
                                }

                                nurbsCurveRhino = (NurbsCurve)curveRhino;
                                curvesListRevit.Add(Hb(nurbsCurveRhino));
                                break;

                            case "ArcCurve":
                                arcCurveRhino = (ArcCurve)curveRhino;
                                curvesListRevit.Add(Hb(arcCurveRhino));
                                break;

                            case "PolylineCurve":
                                //NurbsCurve nurbsLineCurve = (NurbsCurve)curveBranch.ToNurbsCurve();
                                NurbsCurve nurbsLineCurve = (NurbsCurve)curveRhino.ToNurbsCurve();
                                Rhino.Geometry.Collections.NurbsCurvePointList points = nurbsLineCurve.Points;

                                for (int k = 0; k < points.Count - 1; k++)
                                {
                                    HbLine lineRevit = new HbLine();
                                    Rhino.Geometry.ControlPoint controlPointStart = points[k];
                                    Rhino.Geometry.ControlPoint controlPointEnd   = points[k + 1];
                                    Point3d xyzRhinoStart = controlPointStart.Location;
                                    Point3d xyzRhinoEnd   = controlPointEnd.Location;

                                    HbXYZ xyzRevitStart = new HbXYZ(xyzRhinoStart.X, xyzRhinoStart.Y, xyzRhinoStart.Z);
                                    HbXYZ xyzRevitEnd   = new HbXYZ(xyzRhinoEnd.X, xyzRhinoEnd.Y, xyzRhinoEnd.Z);

                                    lineRevit.PointStart = new HbXYZ(xyzRevitStart.X, xyzRevitStart.Y, xyzRevitStart.Z);
                                    lineRevit.PointEnd   = new HbXYZ(xyzRevitEnd.X, xyzRevitEnd.Y, xyzRevitEnd.Z);
                                    curvesListRevit.Add(lineRevit);
                                }

                                break;

                            default:
                                Print("Unknown Rhino PolyCurve curve type: " + curveRhino.GetType().Name);
                                break;
                            }
                        }
                        break;

                    case "NurbsCurve":
                        if (!AllowNurbs)
                        {
                            break;
                        }

                        nurbsCurveRhino = (NurbsCurve)curveBranch;
                        //if !nurbsCurveRhino.IsClosed()
                        curvesListRevit.Add(Hb(nurbsCurveRhino));
                        break;

                    case "PolylineCurve":
                        NurbsCurve nurbsLineCurve2 = (NurbsCurve)curveBranch.ToNurbsCurve();
                        Rhino.Geometry.Collections.NurbsCurvePointList points2 = nurbsLineCurve2.Points;

                        for (int k = 0; k < points2.Count - 1; k++)
                        {
                            HbLine lineRevit = new HbLine();
                            Rhino.Geometry.ControlPoint controlPointStart = points2[k];
                            Rhino.Geometry.ControlPoint controlPointEnd   = points2[k + 1];
                            Point3d xyzRhinoStart = controlPointStart.Location;
                            Point3d xyzRhinoEnd   = controlPointEnd.Location;

                            HbXYZ xyzRevitStart = new HbXYZ(xyzRhinoStart.X, xyzRhinoStart.Y, xyzRhinoStart.Z);
                            HbXYZ xyzRevitEnd   = new HbXYZ(xyzRhinoEnd.X, xyzRhinoEnd.Y, xyzRhinoEnd.Z);

                            lineRevit.PointStart = new HbXYZ(xyzRevitStart.X, xyzRevitStart.Y, xyzRevitStart.Z);
                            lineRevit.PointEnd   = new HbXYZ(xyzRevitEnd.X, xyzRevitEnd.Y, xyzRevitEnd.Z);
                            curvesListRevit.Add(lineRevit);
                        }

                        break;

                    case "LineCurve":
                        lineCurveRhino = (LineCurve)curveBranch;
                        curvesListRevit.Add(Hb(lineCurveRhino));
                        break;

                    case "ArcCurve":
                        arcCurveRhino = (ArcCurve)curveBranch;
                        curvesListRevit.Add(Hb(arcCurveRhino));
                        break;

                    default:
                        Print("Unknown Rhino curve type: " + curveBranch.GetType().Name);
                        break;
                    }
                    if (NestBranch)
                    {
                        curvesListListRevit.Add(curvesListRevit);
                    }
                }

                if (!NestBranch)
                {
                    curvesListListRevit.Add(curvesListRevit);
                }

                return(true);
            }
            catch (Exception exception) {
                Print("Exception in 'ReadDataTreeBranch' w/ curves: " + exception.Message);
                return(false);
            }
        }
Example #5
0
        public bool CreateOneFamilyExtrusion(CsvWriter csvWriter, double segmentX, double segmentY, double elevation, double height, double currentX, double currentY)
        {
            HbXYZ point01 = new HbXYZ(currentX + segmentX * 1, currentY + segmentY * 2, elevation);
            HbXYZ point02 = new HbXYZ(currentX + segmentX * 3, currentY + segmentY * 2, elevation);
            HbXYZ point03 = new HbXYZ(currentX + segmentX * 4, currentY + segmentY * 0, elevation);
            HbXYZ point04 = new HbXYZ(currentX + segmentX * 5, currentY + segmentY * 2, elevation);
            HbXYZ point05 = new HbXYZ(currentX + segmentX * 7, currentY + segmentY * 2, elevation);
            HbXYZ point06 = new HbXYZ(currentX + segmentX * 7, currentY + segmentY * 3, elevation);
            HbXYZ point07 = new HbXYZ(currentX + segmentX * 8, currentY + segmentY * 4, elevation);
            HbXYZ point08 = new HbXYZ(currentX + segmentX * 7, currentY + segmentY * 5, elevation);
            HbXYZ point09 = new HbXYZ(currentX + segmentX * 7, currentY + segmentY * 6, elevation);
            HbXYZ point10 = new HbXYZ(currentX + segmentX * 5, currentY + segmentY * 7, elevation);
            HbXYZ point11 = new HbXYZ(currentX + segmentX * 4, currentY + segmentY * 6, elevation);
            HbXYZ point12 = new HbXYZ(currentX + segmentX * 3, currentY + segmentY * 7, elevation);
            HbXYZ point13 = new HbXYZ(currentX + segmentX * 1, currentY + segmentY * 6, elevation);
            HbXYZ point14 = new HbXYZ(currentX + segmentX * 1, currentY + segmentY * 5, elevation);
            HbXYZ point15 = new HbXYZ(currentX + segmentX * 0, currentY + segmentY * 4, elevation);
            HbXYZ point16 = new HbXYZ(currentX + segmentX * 1, currentY + segmentY * 3, elevation);

            HbXYZ point17 = new HbXYZ(currentX + segmentX * 2, currentY + segmentY * 4, elevation);
            HbXYZ point18 = new HbXYZ(currentX + segmentX * 6, currentY + segmentY * 4, elevation);

            HbXYZ point19 = new HbXYZ(currentX + segmentX * 1.0, currentY + segmentY * 3.5, elevation);
            HbXYZ point20 = new HbXYZ(currentX + segmentX * 0.5, currentY + segmentY * 4.0, elevation);
            HbXYZ point21 = new HbXYZ(currentX + segmentX * 1.0, currentY + segmentY * 4.5, elevation);
            HbXYZ point22 = new HbXYZ(currentX + segmentX * 1.5, currentY + segmentY * 4.0, elevation);

            HbXYZ point23 = new HbXYZ(currentX + segmentX * 7.0, currentY + segmentY * 3.5, elevation);
            HbXYZ point24 = new HbXYZ(currentX + segmentX * 6.5, currentY + segmentY * 4.0, elevation);
            HbXYZ point25 = new HbXYZ(currentX + segmentX * 7.0, currentY + segmentY * 4.5, elevation);
            HbXYZ point26 = new HbXYZ(currentX + segmentX * 7.5, currentY + segmentY * 4.0, elevation);

            List <List <HbCurve> > curvesCurvesList = new List <List <HbCurve> >();
            List <HbCurve>         curvesList;
            HbLine          line;
            HbArc           arc;
            HbNurbSpline    spline;
            HbEllipse       ellipse;
            HbHermiteSpline hermiteSpline;

            // Outer Loop
            curvesList    = new List <HbCurve>();
            spline        = new HbNurbSpline();
            spline.Points = new List <HbXYZ> {
                point01, point02, point03, point04, point05
            };
            curvesList.Add(spline);

            line = new HbLine(); line.PointStart = point05; line.PointEnd = point06;
            curvesList.Add(line);
            arc = new HbArc(); arc.PointStart = point06; arc.PointMid = point07; arc.PointEnd = point08;
            curvesList.Add(arc);
            line = new HbLine(); line.PointStart = point08; line.PointEnd = point09;
            curvesList.Add(line);

            hermiteSpline        = new HbHermiteSpline();
            hermiteSpline.Points = new List <HbXYZ> {
                point09, point10, point11, point12, point13
            };
            curvesList.Add(hermiteSpline);

            line = new HbLine(); line.PointStart = point13; line.PointEnd = point14;
            curvesList.Add(line);
            arc = new HbArc(); arc.PointStart = point14; arc.PointMid = point15; arc.PointEnd = point16;
            curvesList.Add(arc);
            line = new HbLine(); line.PointStart = point16; line.PointEnd = point01;
            curvesList.Add(line);
            curvesCurvesList.Add(curvesList);

            // Ellipse
            curvesList = new List <HbCurve>();
            ellipse    = new HbEllipse(); ellipse.PointFirst = point17; ellipse.PointSecond = point18; ellipse.RadiusY = segmentY; ellipse.Mode = "Full";
            curvesList.Add(ellipse);
            curvesCurvesList.Add(curvesList);

            // Circles
            curvesList = new List <HbCurve>();
            arc        = new HbArc(); arc.PointStart = point19; arc.PointMid = point20; arc.PointEnd = point21;
            curvesList.Add(arc);
            arc = new HbArc(); arc.PointStart = point21; arc.PointMid = point22; arc.PointEnd = point19;
            curvesList.Add(arc);
            curvesCurvesList.Add(curvesList);
            curvesList = new List <HbCurve>();
            arc        = new HbArc(); arc.PointStart = point23; arc.PointMid = point24; arc.PointEnd = point25;
            curvesList.Add(arc);
            arc = new HbArc(); arc.PointStart = point25; arc.PointMid = point26; arc.PointEnd = point23;
            curvesList.Add(arc);
            curvesCurvesList.Add(curvesList);

            // Extrusion
            csvWriter.SetFamilyExtrusionHeight(height);
            csvWriter.AddFamilyExtrusion(curvesCurvesList, "Bldg", new HbXYZ(0, 0, 0));

            return(true);
        }
Example #6
0
        // ------------------------------------------------------------ Conversion Utilities ---------------------------------------------------------------------

        private bool HbToRhino(Object hbObject, out List <Point3d> points, out Curve curve)
        {
            points = null;
            curve  = null;
            try {
                HbTypes hbType;
                if (hbTypeDictionary.TryGetValue(hbObject.GetType(), out hbType))
                {
                    switch (hbType)
                    {
                    case HbTypes.HbLine:
                        points = new List <Point3d>();
                        HbLine hbLine = (HbLine)hbObject;
                        points.Add(new Point3d(hbLine.PointStart.X, hbLine.PointStart.Y, hbLine.PointStart.Z));
                        points.Add(new Point3d(hbLine.PointEnd.X, hbLine.PointEnd.Y, hbLine.PointEnd.Z));
                        Line rhLine = new Line(points[0], points[1]);
                        curve = new LineCurve(rhLine);
                        break;

                    case HbTypes.HbArc:
                        points = new List <Point3d>();
                        HbArc hbArc = (HbArc)hbObject;
                        points.Add(new Point3d(hbArc.PointStart.X, hbArc.PointStart.Y, hbArc.PointStart.Z));
                        points.Add(new Point3d(hbArc.PointMid.X, hbArc.PointMid.Y, hbArc.PointMid.Z));
                        points.Add(new Point3d(hbArc.PointEnd.X, hbArc.PointEnd.Y, hbArc.PointEnd.Z));
                        curve = new ArcCurve(new Arc(points[0], points[1], points[2]));
                        break;

                    case HbTypes.HbEllipse:
                        //points = new List<Point3d>();
                        //HbEllipse hbEllipse = (HbEllipse)hbObject;
                        //HbXYZ hbXYZ1 = hbEllipse.PointFirst;
                        //HbXYZ hbXYZ2 = hbEllipse.PointSecond;
                        //points.Add(new Point3d(hbXYZ1.X, hbXYZ1.Y, hbXYZ1.Z));
                        //points.Add(new Point3d(hbXYZ1.X, hbXYZ1.Y, hbXYZ1.Z));
                        //double radiusY = hbEllipse.RadiusY;
                        //if (hbEllipse.Mode.ToLower() == "full") {
                        //    Ellipse ellipse = new Ellipse(
                        //}
                        //else {  // "half" case
                        //}
                        //TODO finish; requires some geometry

                        break;

                    case HbTypes.HbNurbSpline:
                        points = new List <Point3d>();
                        HbNurbSpline hbNurbSpline   = (HbNurbSpline)hbObject;
                        int          numberOfPoints = hbNurbSpline.Points.Count;

                        foreach (HbXYZ hbXYZ in hbNurbSpline.Points)
                        {
                            points.Add(new Point3d(hbXYZ.X, hbXYZ.Y, hbXYZ.Z));
                        }
                        curve = NurbsCurve.Create(false, 3, points);
                        break;

                    default:       // Ignore unknown cases

                        break;
                    }
                }
                return(true);
            }
            catch {
                return(false);
            }
        }
Example #7
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            // Set up Utility object and start process
            Utility utility = new Utility(DA);

            utility.Print("Starting Grids.");

            bool   write      = false;
            string folderPath = null;
            string fileName   = null;
            GH_Structure <GH_Curve> dataTree        = null;
            List <string>           instructionData = new List <string>();

            if (!utility.GetInput(0, ref write))                     // Write command is required
            {
                utility.WriteOut();
                return;
            }
            if (!utility.GetInput(1, ref folderPath))                // Folder path is required
            {
                utility.WriteOut();
                return;
            }
            utility.GetInput(2, ref fileName, true, true, true);     // File name is optional
            if (fileName == null)
            {
                fileName = this.DEFAULT_FILE_NAME;
            }

            if (!utility.GetInput(3, out dataTree))                  // curves in Data Tree required
            {
                utility.WriteOut();
                return;
            }

            if (write)
            {
                try {
                    // Create RevitModelBuilderUtility object and link to CSV file
                    CsvWriter csvWriter = new CsvWriter();
                    utility.Print("CsvWriter Version: " + csvWriter.Version);
                    if (!utility.EstablishCsvLink(csvWriter, folderPath, fileName))
                    {
                        utility.Print("EstablishCsvLink() failed");
                        utility.WriteOut();
                        return;
                    }

                    List <List <HbCurve> > curvesListListRevit = new List <List <HbCurve> >();

                    // Loop through the data tree of curves and process each one.
                    for (int i = 0; i < dataTree.Branches.Count; i++)
                    {
                        if (!utility.ReadDataTreeBranch(dataTree.Branches[i], ref curvesListListRevit, false))
                        {
                            return;
                        }
                    }

                    for (int j = 0; j < curvesListListRevit.Count; j++)
                    {
                        List <HbCurve> curvesListRevit = curvesListListRevit[j];
                        for (int k = 0; k < curvesListRevit.Count; k++)
                        {
                            if (curvesListRevit[k].GetType().Name == "HbArc")
                            {
                                HbArc hbArc = (HbArc)curvesListRevit[k];
                                csvWriter.AddGrid(hbArc.PointStart, hbArc.PointEnd, hbArc.PointMid);
                                instructionData.Add("Add Grid-Arc:" + utility.formatPoints(hbArc.PointStart, hbArc.PointEnd, hbArc.PointMid));
                            }
                            else if (curvesListRevit[k].GetType().Name == "HbLine")
                            {
                                HbLine hbLine = (HbLine)curvesListRevit[k];
                                csvWriter.AddGrid(hbLine.PointStart, hbLine.PointEnd);
                                instructionData.Add("Add Grid-Line: " + utility.formatPoints(hbLine.PointStart, hbLine.PointEnd));
                            }
                        }
                        csvWriter.WriteFile();
                    }
                    utility.Print("Grids completed successfully.");
                }

                catch (Exception exception) {
                    utility.Print(exception.Message);
                }
            }
            utility.WriteOut();
            DA.SetDataList(1, instructionData);
        }
Example #8
0
 private bool ConvertHbCurve(HbCurve hbCurve, ref Curve curve)
 {
     try {
         curve = null;
         XYZ xyz1, xyz2, xyz3;
         if (hbCurve is HbLine)
         {
             HbLine hbLine = (HbLine)hbCurve;
             if (!ConvertHbXyz(hbLine.PointStart, out xyz1))
             {
                 return(false);
             }
             if (!ConvertHbXyz(hbLine.PointEnd, out xyz2))
             {
                 return(false);
             }
             curve = Line.CreateBound(xyz1, xyz2);
         }
         else if (hbCurve is HbArc)
         {
             HbArc hbArc = (HbArc)hbCurve;
             if (!ConvertHbXyz(hbArc.PointStart, out xyz1))
             {
                 return(false);
             }
             if (!ConvertHbXyz(hbArc.PointEnd, out xyz2))
             {
                 return(false);
             }
             if (!ConvertHbXyz(hbArc.PointMid, out xyz3))
             {
                 return(false);
             }
             curve = Arc.Create(xyz1, xyz2, xyz3);
         }
         else if (hbCurve is HbEllipse)
         {
             HbEllipse hbEllipse = (HbEllipse)hbCurve;
             if (!ConvertHbXyz(hbEllipse.PointFirst, out xyz1))
             {
                 return(false);
             }
             if (!ConvertHbXyz(hbEllipse.PointSecond, out xyz2))
             {
                 return(false);
             }
             XYZ    center, xVec, yVec;
             double radX, radY, param0, param1;
             CalculateEllipsePoints(xyz1, xyz2, hbEllipse.RadiusY, hbEllipse.Mode, out center, out radX, out radY, out xVec, out yVec, out param0, out param1);
             curve = Ellipse.CreateCurve(center, radX, radY, xVec, yVec, param0, param1);
             //curve = Ellipse.Create(center, radX, radY, xVec, yVec, param0, param1);  //2018 upgrade
         }
         else if (hbCurve is HbNurbSpline)
         {
             HbNurbSpline hbNurbSpline = (HbNurbSpline)hbCurve;
             List <XYZ>   points       = new List <XYZ>();
             foreach (HbXYZ point in hbNurbSpline.Points)
             {
                 if (!ConvertHbXyz(point, out xyz1))
                 {
                     return(false);
                 }
                 points.Add(xyz1);
             }
             List <double> weights = new List <double>();
             // Note that we are just using fixed weights for now.  It doesn't appear that Revit is actually using these values anyway.
             for (int i = 0; i < hbNurbSpline.Points.Count; i++)
             {
                 weights.Add(1.0);
             }
             //curve = NurbSpline.Create(points, weights);  // Fails if < 4 points although manually can create with 2 or 3 points.
             curve = NurbSpline.CreateCurve(points, weights);
             //TODO This failed in older versions if < 4 points although manually can create with 2 or 3 points.  Is this fixed in 2017?
         }
         else if (hbCurve is HbHermiteSpline)
         {
             HbHermiteSpline hbHermiteSpline = (HbHermiteSpline)hbCurve;
             List <XYZ>      points          = new List <XYZ>();
             foreach (HbXYZ point in hbHermiteSpline.Points)
             {
                 if (!ConvertHbXyz(point, out xyz1))
                 {
                     return(false);
                 }
                 points.Add(xyz1);
             }
             curve = HermiteSpline.Create(points, false);
         }
         return(true);
     }
     catch (Exception exception) {
         this.ErrorMessage = "Error in ConvertHbCurve: " + exception.Message + ".";
         curve             = null;
         return(false);
     }
 }
Example #9
0
        // ******************************************************** Private Functions ********************************************************
        private bool RunProcess()
        {
            Cursor.Current = Cursors.WaitCursor;
            try {
                CsvWriter csvWriter = new CsvWriter();

                // ********************************************************************************************************************************
                // ************************************* HummingbirdUtility Basic Function Signatures ***************************************
                // ********************************************************************************************************************************
                //
                // "Version" is a property of the ExcelWriter object.

                // Revit classes "XYZ", "Line", "Arc", "Ellipse", "NurbSpline", and "HermiteSpline" have corresponding classes in Hummingbird named
                // "HbXYZ", "HbLine", "HbArc", "HbEllipse", "HbNurbSpline", and "HbHermiteSpline" which derive from a parent class of "HbItem".
                // These have constructors:
                // HbXYZ(double x, double y, double z)
                // HbLine(HbXYZ pointStart, HbXYZ pointEnd)
                // HbArc(HbXYZ pointStart, HbXYZ pointEnd, HbXYZ pointMid)
                // HbEllipse(HbXYZ pointFirst, HbXYZ pointSecond, double radiusY, string mode)  radiusY is perpendicular to points; mode "Half" or "Full".
                // HbNurbSpline(List<HbXYZ> points)
                // HbHermiteSpline(List<HbXYZ> points)
                // (Note, these also have a default constructor with no parameters and properties that correspond to the parameters that must be set individually.)
                // They also have special functions specifically for use with Autodesk DesignScript
                // static HbXYZ New(double x, double y, double z)
                // static HbLine New(HbXYZ pointStart, HbXYZ pointEnd)
                // static HbArc New(HbXYZ pointStart, HbXYZ pointEnd, HbXYZ pointMid)
                // static HbEllipse New(HbXYZ pointFirst, HbXYZ pointSecond, double radiusY, string mode)  radiusY is perpendicular to points; mode "Half" or "Full".
                // static HbNurbSpline New(List<HbXYZ> points)
                // static HbHermiteSpline New(List<HbXYZ> points)
                // There are also some list functions that workaround the lack of a native "List" object in DesignScript
                // HbItemList()
                // static void Add(HbItemList list, HbItem hbItem)
                // HbItemListList()
                // static void Add(HbItemListList listList, HbItemList list)
                //
                // The following are methods of the ExcelWriter object.
                //
                // List of worksheet names:
                // List<string> GetWorksheetNames()
                //
                // Set Actions:
                // void SetLevel(string levelName)
                // void SetWallType(string wallTypeName)
                // void SetWallHeight(double height)
                // void SetFloorType(string floorTypeName)
                // void SetFamilyType(string familyName, string typeName)
                // void SetFamilyFlipped(bool flipHand, bool flipFacing)
                // void SetFamilyMirrored(bool mirrorX, bool mirrorY)
                // void SetFamilyRotation(double rotation)
                // void SetColumnMode(string mode, string familyName, string typeName)
                // void SetColumnHeight(double height)
                // void SetColumnRotation(double rotation)
                // void SetBeamType(string familyName, string typeName)
                // void SetBeamJustification(string justification) {
                // void SetBeamRotation(double rotation) {
                // void SetAdaptiveComponentType(string familyName, string typeName)
                // void SetFamilyExtrusionHeight(double height)
                // void SetMullionType(string familyName, string typeName)
                //
                // Add Actions:
                // void AddGrid(HbXYZ point1, HbXYZ point2)                  // Line case
                // void AddGrid(HbXYZ point1, HbXYZ point2, HbXYZ point3)    // Arc case (point1 = start; point2 = end; point3 = any point in arc.)
                // void AddLevel(double elevation, string name = null) {     // name is optional
                // void AddDetailLine(HbXYZ point1, HbXYZ point2)
                // void AddDetailArc(HbXYZ point1, HbXYZ point2, HbXYZ point3)
                // void AddDetailEllipse(HbXYZ point1, HbXYZ point2, double radiusY, string mode)
                // void AddDetailNurbsSpline(HbXYZ point1, HbXYZ point2, HbXYZ point3 = null, HbXYZ point4 = null) // points 3 and 4 are optional
                // void AddDetailNurbsSpline(List<HbXYZ> points)
                // void AddDetailCurves(List<HbItem> curves)
                // void AddModelLine(HbXYZ point1, HbXYZ point2)
                // void AddModelArc(HbXYZ point1, HbXYZ point2, HbXYZ point3)
                // void AddModelEllipse(HbXYZ point1, HbXYZ point2, double radiusY, string mode)
                // void AddModelNurbsSpline(HbXYZ point1, HbXYZ point2, HbXYZ point3 = null, HbXYZ point4 = null) // points 3 and 4 are optional
                // void AddModelNurbsSpline(List<HbXYZ> points)
                // void AddModelCurves(List<HbItem> curves)
                // void AddTopographySurface(HbXYZ point1, HbXYZ point2, HbXYZ point3, HbXYZ point4 = null) {
                // void AddTopographySurface(List<HbXYZ> points) {

                // void AddWall(HbXYZ point1, HbXYZ point2)                   // Straight line in plan.
                // void AddWall(HbXYZ point1, HbXYZ point2, HbXYZ point3)  // Arc in plan
                // void AddWall(List<HbItem> curvesList)                         // List of lines, arcs, ellipses, or splines in plan
                // void AddWall(List<List<HbItem>> curvesList)                   // List of Lists controls profile in elevation
                // void AddFloor(HbXYZ point1, HbXYZ point2, HbXYZ point3, HbXYZ point4)
                // void AddFloor(List<List<HbItem>> curvesList)
                // void AddFamilyInstance(HbXYZ point1)
                // void AddColumn(HbXYZ point1)
                // void AddColumn(HbXYZ point1, HbXYZ point2)
                // void AddBeam(HbXYZ point1, HbXYZ point2)
                // void AddAdaptiveComponent(HbXYZ point1, HbXYZ point2 = null, HbXYZ point3 = null, HbXYZ point4 = null)   // points 2, 3, and 4 are optional
                // void AddAdaptiveComponent(List<HbXYZ> points)
                // void AddAreaBoundaryLine(HbXYZ point1, HbXYZ point2)                                // Line case
                // void AddAreaBoundaryLine(HbXYZ point1, HbXYZ point2, HbXYZ point3)               // Arc case
                // void AddAreaBoundaryLine(HbXYZ point1, HbXYZ point2, double radiusY, string mode)   // Ellipse case
                // void AddAreaBoundaryLine(List<HbXYZ> points)                                           // Spline case
                // void AddAreaBoundaryLine(List<HbItem> curves)                                          // List of lines, arcs, ellipses, or splines in plan
                // void AddRoomSeparationLine(HbXYZ point1, HbXYZ point2)                              // Line case
                // void AddRoomSeparationLine(HbXYZ point1, HbXYZ point2, HbXYZ point3)             // Arc case
                // void AddRoomSeparationLine(HbXYZ point1, HbXYZ point2, double radiusY, string mode) // Ellipse case
                // void AddRoomSeparationLine(List<HbXYZ> points)                                         // Spline case
                // void AddRoomSeparationLine(List<HbItem> curves)                                        // List of lines, arcs, ellipses, or splines in plan
                // void AddArea(HbXYZ point1);
                // void AddRoom(HbXYZ point1);
                // void AddReferencePoint(HbXYZ point)
                // void AddCurveByPoints(List<HbXYZ> points)
                // void AddloftForm(List<List<HbXYZ>> points)
                // void AddFamilyExtrusion(List<List<HbItem>> curvesList, string nameFamily = null, HbXYZ pointInsert = null) {
                // void AddFamilyExtrusion(List<List<HbItem>> curvesList, HbXYZ pointInsert) {
                //
                // Modify Actions:
                // void ModifyParameterSet(string parameterName, string value)
                // void ModifyCurtainGridUAdd(double offsetPrimary);
                // void ModifyCurtainGridUAdd(double offsetPrimary, double offsetSecondary);
                // void ModifyCurtainGridVAdd(double offsetPrimary);
                // void ModifyCurtainGridVAdd(double offsetPrimary, double offsetSecondary);
                // void ModifyMullionUAdd(double offsetPrimary);
                // void ModifyMullionUAdd(double offsetPrimary, double offsetSecondary);
                // void ModifyMullionVAdd(double offsetPrimary);
                // void ModifyMullionVAdd(double offsetPrimary, double offsetSecondary);

                // ************************************************************************************************************************************
                // ************************************* RevitModelBuilderUtility Component Function Signatures ***************************************
                // ************************************************************************************************************************************
                //
                // Users will typically avoid using these in favor of the basic forms.  Provided here only for completeness
                //
                // Use-Add Actions:
                // void UsePoints(HbXYZ point1, HbXYZ point2 = null, HbXYZ point3 = null, HbXYZ point4 = null) { // points 2, 3, and 4 are optional
                // void UsePoints(List<HbXYZ> points) // General form of more than four points
                // void AddDetailNurbsSpline()  // Must follow UsePoints
                // void AddModelNurbsSpline()   // Must follow UsePoints
                // void AddAdaptiveComponent()  // Must follow UsePoints
                // void AddAreaBoundaryLine()   // Spline - Must follow UsePoints (Note: no simple form of spline is currently offered
                // void AddRoomSeparationLine() // Spline - Must follow UsePoints (Note: no simple form of spline is currently offered
                // void AddCurveByPoints()      // Must follow UsePoints
                // void AddTopographySurface()  // Must follow UsePoints
                //
                // Draw-Use-Add Actions:
                // (Also see UsePoints() above)
                // void DrawCurveArray()
                // void DrawLine(HbXYZ point1, HbXYZ point2)
                // void DrawArc(HbXYZ point1, HbXYZ point2, HbXYZ point3)
                // void AddWall()
                // void AddFloor()
                // void AddFamilyExtrusion(string nameFamily, HbXYZ pointInsert = null) {  // Must follow a Curve Array Set
                // void DrawCurveArray(List<HbItem> curves) {   // Combined form; curves must be HbItem type
                //
                // Model-Use-Add Actions:
                // (Also see UsePoints() above)
                // void ModelReferenceArray()  // Must be first statement
                // void AddLoftForm()          // Must follow ModelReferenceArray() and UsePoints()
                //

                // ****************************************************************************************************************
                // ******************************************* Start of Sample Code Section ***************************************
                // ****************************************************************************************************************
                //
                // This is the portion of the code that is typically emulated for a particular project use.

                // Sample Revit hb items and lists
                HbXYZ        point11 = new HbXYZ(0, 0, 0); HbXYZ point12 = new HbXYZ(10, 0, 0); HbXYZ point13 = new HbXYZ(20, 0, 0); HbXYZ point14 = new HbXYZ(15, 5, 0);
                HbXYZ        point21 = new HbXYZ(0, 10, 0); HbXYZ point22 = new HbXYZ(10, 10, 0); HbXYZ point23 = new HbXYZ(20, 10, 0); HbXYZ point24 = new HbXYZ(15, 15, 0);
                List <HbXYZ> pointsList1 = new List <HbXYZ>(); pointsList1.Add(point11); pointsList1.Add(point12); pointsList1.Add(point13); pointsList1.Add(point14);
                List <HbXYZ> pointsList2 = new List <HbXYZ>(); pointsList2.Add(point21); pointsList2.Add(point22); pointsList2.Add(point23); pointsList2.Add(point24);
                //List<HbXYZ> pointsList3 = new List<HbXYZ>(); pointsList3.Add(point21); pointsList3.Add(point22); pointsList3.Add(point23);
                //                                                   pointsList3.Add(point24); pointsList3.Add(point24); pointsList3.Add(point24);
                List <List <HbXYZ> > pointsListList = new List <List <HbXYZ> >(); pointsListList.Add(pointsList1); pointsListList.Add(pointsList2);
                HbLine       line1       = new HbLine(); line1.PointStart = point11; line1.PointEnd = point12;
                HbLine       line2       = new HbLine(); line2.PointStart = point21; line2.PointEnd = point22;
                HbArc        arc1        = new HbArc(); arc1.PointStart = point11; arc1.PointEnd = point12; arc1.PointMid = point13;
                HbArc        arc2        = new HbArc(); arc2.PointStart = point21; arc2.PointEnd = point22; arc2.PointMid = point23;
                HbNurbSpline nurbSpline1 = new HbNurbSpline(); nurbSpline1.Points.Add(point21); nurbSpline1.Points.Add(point12); nurbSpline1.Points.Add(point23);
                HbNurbSpline nurbSpline2 = new HbNurbSpline(); nurbSpline2.Points.Add(point11); nurbSpline2.Points.Add(point22); nurbSpline2.Points.Add(point13);
                HbNurbSpline nurbSpline3 = new HbNurbSpline(); nurbSpline3.Points.Add(point11); nurbSpline3.Points.Add(point22); nurbSpline3.Points.Add(point13);
                nurbSpline3.Points.Add(point11); nurbSpline3.Points.Add(point22); nurbSpline3.Points.Add(point13);
                List <HbCurve>         curvesList1    = new List <HbCurve>(); curvesList1.Add(line1); curvesList1.Add(arc1); curvesList1.Add(nurbSpline1);
                List <HbCurve>         curvesList2    = new List <HbCurve>(); curvesList2.Add(line2); curvesList2.Add(arc2); curvesList2.Add(nurbSpline3);
                List <List <HbCurve> > curvesListList = new List <List <HbCurve> >(); curvesListList.Add(curvesList1); curvesListList.Add(curvesList2);

                double levelElevation = 100;    //  for Level
                string levelName      = "A New Level";

                double radiusY = 10;   // for ellipse
                string mode    = "Full";

                double offsetPrimary   = 5; // for curtain gridds and mullions
                double offsetSecondary = 10;

                // Display the version
                MessageBox.Show("csvWriter.Version: " + csvWriter.Version);

                // Start .csv file
                textBoxCsvFolder.Text = textBoxCsvFolder.Text.Trim();
                if (!textBoxCsvFolder.Text.EndsWith(@"\"))
                {
                    textBoxCsvFolder.Text = textBoxCsvFolder.Text + @"\";
                }
                this.csvFolderPath      = textBoxCsvFolder.Text;
                textBoxCsvFileName.Text = textBoxCsvFileName.Text.Trim();
                if (!textBoxCsvFileName.Text.ToLower().EndsWith(".csv"))
                {
                    textBoxCsvFileName.Text = textBoxCsvFileName.Text + ".csv";
                }
                this.csvFileName = textBoxCsvFileName.Text;
                this.csvFilePath = this.csvFolderPath + this.csvFileName;
                string returnMMessage = csvWriter.ConnectToFile(this.csvFilePath);
                if (returnMMessage != "")
                {
                    MessageBox.Show(returnMMessage);
                    return(false);
                }

                // If checked, get ID values
                if (checkBoxPreserveId.Checked)
                {
                    // Note that if file doesn't exist yet we ignore option to preserve ID values
                    if (File.Exists(this.csvFilePath))
                    {
                        try {
                            string returnValue = csvWriter.ReadElementIds();
                            if (returnValue != "")
                            {
                                MessageBox.Show("csvWriter.ReadElementIds() failed: " + returnValue, PROGRAM_NAME);
                                return(false);
                            }
                        }
                        catch (Exception exception) {
                            MessageBox.Show("Exception in RunProcess() at csvWriter.ReadElementIds(): " + exception.Message, PROGRAM_NAME);
                            return(false);
                        }
                    }
                }

                // Set Actions:
                csvWriter.SetLevel("Level 1");
                csvWriter.SetWallType("WallTypeName");
                csvWriter.SetWallHeight(10);
                csvWriter.SetFloorType("FloorTypeName");
                csvWriter.SetFamilyType("FamilyFamilyName", "FamilyTypeName");
                csvWriter.SetFamilyFlipped(true, false);
                csvWriter.SetFamilyMirrored(false, true);
                csvWriter.SetFamilyRotation(45);
                csvWriter.SetColumnMode("Architectural", "ColumnFamilyName", "ColumnTypeName");
                csvWriter.SetColumnHeight(10);
                csvWriter.SetColumnRotation(45);
                csvWriter.SetBeamType("BeamFamilyName", "BeamTypeName");
                csvWriter.SetBeamJustification("Top");
                csvWriter.SetBeamRotation(45);
                csvWriter.SetAdaptiveComponentType("ACompFamilyName", "ACompTypeName");
                csvWriter.SetFamilyExtrusionHeight(40);
                csvWriter.SetMullionType("AMullionFamilyName", "AMullionTypeName");
                //
                // Add Actions:
                csvWriter.AddGrid(point11, point12);          // Line case
                csvWriter.AddGrid(point11, point12, point13); // Arc case
                levelElevation = 100;                         //  for Level
                csvWriter.AddLevel(levelElevation, levelName);
                csvWriter.AddLevel(levelElevation);           // name is optional
                csvWriter.AddDetailLine(point11, point12);
                csvWriter.AddDetailArc(point11, point12, point13);
                csvWriter.AddDetailEllipse(point11, point12, radiusY, mode);
                csvWriter.AddDetailNurbsSpline(point11, point12, point13, point14);
                csvWriter.AddDetailNurbsSpline(pointsList1);
                csvWriter.AddDetailCurves(curvesList1);
                csvWriter.AddDetailCurves(curvesList2);
                csvWriter.AddModelLine(point11, point12);
                csvWriter.AddModelArc(point11, point12, point13);
                csvWriter.AddModelEllipse(point11, point12, radiusY, mode);
                csvWriter.AddModelNurbsSpline(point11, point12);   // points 3 and 4 are optional
                csvWriter.AddModelNurbsSpline(point11, point12, point13);
                csvWriter.AddModelNurbsSpline(point11, point12, point13, point14);
                csvWriter.AddModelNurbsSpline(pointsList1);
                csvWriter.AddModelCurves(curvesList1);
                csvWriter.AddTopographySurface(point11, point12, point13);
                csvWriter.AddTopographySurface(point11, point12, point13, point14);
                csvWriter.AddTopographySurface(pointsList1);
                csvWriter.AddWall(point11, point12);
                csvWriter.AddWall(point11, point12, point13);
                csvWriter.AddWall(curvesList1);     // Plan list
                csvWriter.AddWall(curvesListList);  // Profile list of lists
                csvWriter.AddFloor(point11, point12, point13, point14);
                csvWriter.AddFloor(curvesListList);
                csvWriter.AddFamilyInstance(point11);
                csvWriter.AddColumn(point11);
                csvWriter.AddColumn(point11, point12);
                csvWriter.AddBeam(point11, point12);
                csvWriter.AddAdaptiveComponent(point11);  // points 2, 3, and 4 are optional
                csvWriter.AddAdaptiveComponent(point11, point12);
                csvWriter.AddAdaptiveComponent(point11, point12, point13);
                csvWriter.AddAdaptiveComponent(point11, point12, point13, point14);
                csvWriter.AddAdaptiveComponent(pointsList1);
                csvWriter.AddAreaBoundaryLine(point11, point12);                  // Line case
                csvWriter.AddAreaBoundaryLine(point11, point12, point13);         // Arc case
                csvWriter.AddAreaBoundaryLine(point11, point12, radiusY, mode);   // Ellipse case
                csvWriter.AddAreaBoundaryLine(pointsList1);                       // Spline case
                csvWriter.AddAreaBoundaryLine(curvesList1);                       // List of lines, arcs, ellipses, or splines in plan
                csvWriter.AddRoomSeparationLine(point11, point12);                // Line case
                csvWriter.AddRoomSeparationLine(point11, point12, point13);       // Arc case
                csvWriter.AddRoomSeparationLine(point11, point12, radiusY, mode); // Ellipse case
                csvWriter.AddRoomSeparationLine(pointsList1);                     // Spline case
                csvWriter.AddRoomSeparationLine(curvesList1);                     // List of lines, arcs, ellipses, or splines in plan
                csvWriter.AddArea(point11);
                csvWriter.AddRoom(point11);
                csvWriter.AddReferencePoint(point11);
                csvWriter.AddCurveByPoints(pointsList1);
                csvWriter.AddLoftForm(pointsListList);
                ////TODO Not handling this case for now.  It is not allowed in the specification and not sure how it got inot the sample data
                //csvWriter.AddFamilyExtrusion(curvesListList, "ExtrusionFamilyName", point11);
                //csvWriter.AddFamilyExtrusion(curvesListList, "ExtrusionFamilyName");
                //csvWriter.AddFamilyExtrusion(curvesListList, point11);
                //csvWriter.AddFamilyExtrusion(curvesListList);
                //
                // Modify Actions:
                csvWriter.ModifyParameterSet("ParameterName", "Value");
                csvWriter.ModifyCurtainGridUAdd(offsetPrimary);
                csvWriter.ModifyCurtainGridUAdd(offsetPrimary, offsetSecondary);
                csvWriter.ModifyCurtainGridVAdd(offsetPrimary);
                csvWriter.ModifyCurtainGridVAdd(offsetPrimary, offsetSecondary);
                csvWriter.ModifyMullionUAdd(offsetPrimary);
                csvWriter.ModifyMullionUAdd(offsetPrimary, offsetSecondary);
                csvWriter.ModifyMullionVAdd(offsetPrimary);
                csvWriter.ModifyMullionVAdd(offsetPrimary, offsetSecondary);

                // These commands can also be used but it is proably better to try to use one of the more compact forms above.

                // Use-Add Actions:
                csvWriter.UsePoints(point11, point12, point13, point14);
                csvWriter.UsePoints(pointsList1);
                csvWriter.AddDetailNurbsSpline();
                csvWriter.UsePoints(pointsList1);
                csvWriter.AddModelNurbsSpline();
                csvWriter.UsePoints(pointsList1);
                csvWriter.AddAdaptiveComponent();
                csvWriter.UsePoints(pointsList1);
                csvWriter.AddAreaBoundaryLine();   // Spline - Must follow UsePoints (Note: no simple form of spline is currently offered
                csvWriter.UsePoints(pointsList1);
                csvWriter.AddRoomSeparationLine(); // Spline - Must follow UsePoints (Note: no simple form of spline is currently offered
                csvWriter.UsePoints(pointsList1);
                csvWriter.AddCurveByPoints();

                // Draw-Use-Add Actions:
                csvWriter.DrawCurveArray();          //This is non-combined form
                csvWriter.DrawLine(point11, point12);
                csvWriter.DrawArc(point11, point12, point13);
                csvWriter.AddWall();
                csvWriter.DrawCurveArray();
                csvWriter.DrawLine(point11, point12);
                csvWriter.DrawArc(point11, point12, point13);
                csvWriter.AddFloor();
                csvWriter.DrawCurveArray();
                csvWriter.DrawLine(point11, point12);
                csvWriter.DrawArc(point11, point12, point13);
                csvWriter.AddFamilyExtrusion("ExtrusionFamilyName", point11);
                csvWriter.DrawCurveArray();
                csvWriter.DrawLine(point11, point12);
                csvWriter.DrawArc(point11, point12, point13);
                csvWriter.AddFamilyExtrusion("ExtrusionFamilyName");
                csvWriter.DrawCurveArray(curvesList1);  //This is combined form
                csvWriter.AddFamilyExtrusion();

                // Model-Use-Add Actions:
                // (These examples are not complete)
                csvWriter.ModelReferenceArray();
                csvWriter.AddLoftForm();

                //  Write the file
                csvWriter.WriteFile();


                // ****************************************************************************************************************
                // ******************************************** End of Sample Code Section ****************************************
                // ****************************************************************************************************************

                MessageBox.Show("Process Completed", PROGRAM_NAME);

                return(true);
            }
            catch (Exception exception) {
                MessageBox.Show("Error in 'RunProcess()'.\nSystem message: " + exception.Message, PROGRAM_NAME);
                return(false);
            }
            finally {
                Cursor.Current = Cursors.Default;
            }
        }
Example #10
0
        // ************************************************** Private Functions ****************************************************
        private void Process()
        {
            listBoxResults.Items.Clear();
            listBoxResults.Items.Add("");

            CsvReader csvReader = new CsvReader();

            csvReader.ConnectToFile(textBoxPathCsv.Text);
            string returnValue = csvReader.ReadFile();

            if (returnValue != "")
            {
                MessageBox.Show(returnValue);
            }
            returnValue = csvReader.GetInput();
            if (returnValue != "")
            {
                MessageBox.Show(returnValue);
            }
            else
            {
                //csvReader.
                List <HbInputItem> inputItems = csvReader.HbInputItems;
                foreach (HbInputItem inputItem in inputItems)
                {
                    string valueElementId;
                    if (inputItem.ElementId == null)
                    {
                        valueElementId = "NULL";
                    }
                    else
                    {
                        valueElementId = inputItem.ElementId.ElementIdValue.ToString();
                    }
                    listBoxResults.Items.Add("RowId: " + inputItem.RowId + " || ElementId: " + valueElementId);
                    listBoxResults.Items.Add(inputItem.CommandAction + " || " + inputItem.CommandObject + " || " + inputItem.CommandModifier);
                    if (inputItem.ListHbXYZ == null)
                    {
                        listBoxResults.Items.Add("ListHbXYZ = NULL");
                    }
                    else
                    {
                        listBoxResults.Items.Add("ListHbXYZ:");
                        foreach (HbXYZ hbXyz in inputItem.ListHbXYZ)
                        {
                            if (hbXyz == null)
                            {
                                listBoxResults.Items.Add("     (Null value for hbXyz.)");
                            }
                            else
                            {
                                listBoxResults.Items.Add("     (" + hbXyz.X.ToString() + ", " + hbXyz.Y.ToString() + ", " + hbXyz.Z.ToString() + ")");
                            }
                        }
                    }
                    if (inputItem.HbCurveArrArray == null)
                    {
                        listBoxResults.Items.Add("HbCurveArrayArray = NULL");
                    }
                    else
                    {
                        listBoxResults.Items.Add("HbCurveArrayArray:");
                        foreach (HbCurveArray hbCurveArray in inputItem.HbCurveArrArray)
                        {
                            listBoxResults.Items.Add("     CurveArray:" + hbCurveArray.ToString());
                            foreach (HbCurve hbCurve in hbCurveArray)
                            {
                                string hbName = hbCurve.ToString();
                                string hbType = hbName.Substring(hbName.LastIndexOf(".") + 1);
                                switch (hbType)
                                {
                                case "HbLine":
                                    HbLine hbLine = (HbLine)hbCurve;
                                    listBoxResults.Items.Add("          HbLine: (" + hbLine.PointStart.X.ToString() + ", " + hbLine.PointStart.Y.ToString() + ", " + hbLine.PointStart.Z.ToString() + ") "
                                                             + "(" + hbLine.PointEnd.X.ToString() + ", " + hbLine.PointEnd.Y.ToString() + ", " + hbLine.PointEnd.Z.ToString() + ")");
                                    break;

                                case "HbArc":
                                    HbArc hbArc = (HbArc)hbCurve;
                                    listBoxResults.Items.Add("          HbArc: (" + hbArc.PointStart.X.ToString() + ", " + hbArc.PointStart.Y.ToString() + ", " + hbArc.PointStart.Z.ToString() + ") "
                                                             + "(" + hbArc.PointMid.X.ToString() + ", " + hbArc.PointMid.Y.ToString() + ", " + hbArc.PointMid.Z.ToString() + ") "
                                                             + "(" + hbArc.PointEnd.X.ToString() + ", " + hbArc.PointEnd.Y.ToString() + ", " + hbArc.PointEnd.Z.ToString() + ")");
                                    break;

                                default:
                                    listBoxResults.Items.Add("          " + hbCurve.ToString());
                                    break;
                                }
                            }
                        }
                    }
                    if (inputItem.HbReferenceArrayArray == null)
                    {
                        listBoxResults.Items.Add("HbReferenceArrayArray = NULL");
                    }
                    else
                    {
                        listBoxResults.Items.Add("HbReferenceArrayArray:");
                        foreach (HbReferenceArray hbReferenceArray in inputItem.HbReferenceArrayArray)
                        {
                            listBoxResults.Items.Add("     " + hbReferenceArray.ToString());
                        }
                    }
                    //if (inputItem.Variables == null) listBoxResults.Items.Add("Variables = NULL");
                    //else {
                    //    listBoxResults.Items.Add("Variables:");
                    //    foreach (string variable in inputItem.Variables) {
                    //        listBoxResults.Items.Add("     " + variable);
                    //    }
                    //}
                    listBoxResults.Items.Add("");
                    listBoxResults.Items.Add("-------------------------------------------------------------------------------------------------");
                    listBoxResults.Items.Add("");
                    //string valueElementId;
                    //string valuesListHbXYZ;
                    //string valuesHbCurveArrayArray;
                    //string valuesHbReferenceArrayArray;
                    //string valuesVariables;
                    //string valueElementId;
                    //string valuesListHbXYZ;
                    //string valuesHbCurveArrayArray;
                    //string valuesHbReferenceArrayArray;
                    //string valuesVariables;
                    //if (inputItem.ElementId == null) valueElementId = "NULL";
                    //else valueElementId = inputItem.ElementId.ElementIdValue.ToString();
                    //if (inputItem.ListHbXYZ == null) valuesListHbXYZ = "ListHbXYZ = NULL";
                    //else {
                    //    valuesListHbXYZ = "ListHbXYZ:";
                    //    foreach (HbXYZ hbXyz in inputItem.ListHbXYZ) {
                    //        valuesListHbXYZ += "\n     (" + hbXyz.X.ToString() + ", " + hbXyz.Y.ToString() + ", " + hbXyz.Z.ToString() + ")";
                    //    }
                    //}
                    //if (inputItem.HbCurveArrayArray == null) valuesHbCurveArrayArray = "HbCurveArrayArray = NULL";
                    //else {
                    //    valuesHbCurveArrayArray = "HbCurveArrayArray:";
                    //    foreach (HbCurveArray hbCurveArray in inputItem.HbCurveArrayArray) {
                    //        valuesHbCurveArrayArray += "\n     " + hbCurveArray.ToString();
                    //    }
                    //}
                    //if (inputItem.HbReferenceArrayArray == null) valuesHbReferenceArrayArray = "HbReferenceArrayArray = NULL";
                    //else {
                    //    valuesHbReferenceArrayArray = "HbReferenceArrayArray:";
                    //    foreach (HbReferenceArray hbReferenceArray in inputItem.HbReferenceArrayArray) {
                    //        valuesHbReferenceArrayArray += "\n     " + hbReferenceArray.ToString();
                    //    }
                    //}
                    //if (inputItem.Variables == null) valuesVariables = "Variables = NULL";
                    //else {
                    //    valuesVariables = "Variables:";
                    //    foreach (string variable in inputItem.Variables) {
                    //        valuesVariables += "\n     " + variable;
                    //    }
                    //}
                    //DialogResult result = MessageBox.Show(
                    //    "RowId: " + inputItem.RowId + " || ElementId: " + valueElementId + "\n"
                    //  + inputItem.CommandAction + " || " + inputItem.CommandObject + " || " + inputItem.CommandModifier + "\n"
                    //  + valuesListHbXYZ + "\n"
                    //  + valuesHbCurveArrayArray + "\n"
                    //  + valuesHbReferenceArrayArray + "\n"
                    //  + valuesVariables + "\n"
                    //    , constantProgramName, MessageBoxButtons.OKCancel);
                    //if (result != DialogResult.OK) break;
                }
            }
        }