Esempio n. 1
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);
     }
 }
Esempio n. 2
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);
        }
Esempio n. 3
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);
     }
 }