Exemplo n.º 1
0
 public HbEllipse(HbXYZ pointFirst, HbXYZ pointSecond, double radiusY, string mode)
 {
     PointFirst  = pointFirst;
     PointSecond = pointSecond;
     RadiusY     = radiusY;
     Mode        = mode;
 }
Exemplo n.º 2
0
        public string formatPoints(HbXYZ point1, HbXYZ point2)
        {
            string string1 = formatPoint(point1);
            string string2 = formatPoint(point2);

            return(string1 + ", " + string2);
        }
Exemplo n.º 3
0
        // ************************************************* Data Output Functions ******************************************************************

        public string formatPoint(HbXYZ point)
        {
            string x = point.X.ToString();
            string y = point.Y.ToString();
            string z = point.Z.ToString();

            return("(" + x + ", " + y + ", " + z + ")");
        }
Exemplo n.º 4
0
        public string formatPoints(HbXYZ point1, HbXYZ point2, HbXYZ point3, HbXYZ point4)
        {
            string string1 = formatPoint(point1);
            string string2 = formatPoint(point2);
            string string3 = formatPoint(point3);
            string string4 = formatPoint(point4);

            return(string1 + ", " + string2 + ", " + string3 + ", " + string4);
        }
Exemplo n.º 5
0
        public bool CreateLoftForm()
        {
            string    filePath    = this.csvFolderPath + FILE_NAME_FORM;
            CsvWriter csvWriter   = new CsvWriter();
            string    returnValue = csvWriter.ConnectToFile(filePath);

            if (returnValue != "")
            {
                MessageBox.Show(returnValue);
                return(false);
            }
            if (this.preserveId)
            {
                // Note that if file doesn't exist yet we ignore option to preserve ID values
                if (File.Exists(filePath))
                {
                    try {
                        returnValue = csvWriter.ReadElementIds();
                        if (returnValue != "")
                        {
                            MessageBox.Show(returnValue);
                            return(false);
                        }
                    }
                    catch (Exception exception) {
                        MessageBox.Show("Exception at csvWriter.ReadElementIds(): " + exception.Message);
                        return(false);
                    }
                }
            }

            double spaceX, spaceY, height;

            List <List <HbXYZ> > curves = new List <List <HbXYZ> >();

            for (int indexX = 0; indexX <= GridSizeX; indexX++)
            {
                List <HbXYZ> curve = new List <HbXYZ>();
                spaceX = indexX * FactorGrowX + CellSizeX;
                double lineX = indexX * spaceX;
                for (int indexY = 0; indexY <= GridSizeY; indexY++)
                {
                    height = CalculateHeight(indexX, indexY);
                    spaceY = indexY * FactorGrowY + CellSizeY;
                    double lineY = indexY * spaceY;
                    HbXYZ  point = new HbXYZ(lineX, lineY, height);
                    curve.Add(point);
                }
                curves.Add(curve);
            }
            csvWriter.AddLoftForm(curves);

            csvWriter.WriteFile();

            return(true);
        }
Exemplo n.º 6
0
 // ********************************************* Translation ****************************************************
 private HbXYZ UnitsAndTranslation(HbXYZ hbXyz)
 {
     if (hbXyz == null)
     {
         return(null);               // This occurs when there is an optional parameter, such as with extrusion placement point.
     }
     return(new HbXYZ((hbXyz.X + this.translation.X) * this.unitsFactor,
                      (hbXyz.Y + this.translation.Y) * this.unitsFactor,
                      (hbXyz.Z + this.translation.Z) * this.unitsFactor));
 }
Exemplo n.º 7
0
        public bool CreateLines()
        {
            string    filePath  = this.csvFolderPath + FILE_NAME_LINE;
            CsvWriter csvWriter = new CsvWriter();

            csvWriter.Precision = 4;
            string returnValue = csvWriter.ConnectToFile(filePath);

            if (returnValue != "")
            {
                MessageBox.Show(returnValue);
                return(false);
            }
            if (this.preserveId)
            {
                // Note that if file doesn't exist yet we ignore option to preserve ID values
                if (File.Exists(filePath))
                {
                    try {
                        returnValue = csvWriter.ReadElementIds();
                        if (returnValue != "")
                        {
                            MessageBox.Show(returnValue);
                            return(false);
                        }
                    }
                    catch (Exception exception) {
                        MessageBox.Show("Exception at csvWriter.ReadElementIds(): " + exception.Message);
                        return(false);
                    }
                }
            }

            Spiral spiral = new Spiral(centerPoint);

            spiral.FactorA = FactorA;
            spiral.FactorB = FactorB;
            HbXYZ currentPoint, lastPoint = null;

            for (int i = 0; i < NumberOfPoints; i++)
            {
                XY xy = spiral.CalculatePoint(i);
                currentPoint = new HbXYZ(xy.X, xy.Y, 0.0);
                if (i > 0)
                {
                    csvWriter.AddModelLine(lastPoint, currentPoint);
                }
                lastPoint = currentPoint;
            }
            csvWriter.WriteFile();
            return(true);
        }
Exemplo n.º 8
0
        public bool CreateWalls()
        {
            string    filePath    = this.csvFolderPath + FILE_NAME_WALLS;
            CsvWriter csvWriter   = new CsvWriter();
            string    returnValue = csvWriter.ConnectToFile(filePath);

            if (returnValue != "")
            {
                MessageBox.Show(returnValue);
                return(false);
            }
            if (this.preserveId)
            {
                // Note that if file doesn't exist yet we ignore option to preserve ID values
                if (File.Exists(filePath))
                {
                    try {
                        returnValue = csvWriter.ReadElementIds();
                        if (returnValue != "")
                        {
                            MessageBox.Show(returnValue);
                            return(false);
                        }
                    }
                    catch (Exception exception) {
                        MessageBox.Show("Exception at csvWriter.ReadElementIds(): " + exception.Message);
                        return(false);
                    }
                }
            }

            HbXYZ point1, point2, point3, point4;

            csvWriter.SetWallHeight(FloorHeight - constantFloorThickness);
            XY p1, p2, p3, p4;

            for (int i = 1; i < NumberFloors; i++)
            {
                double elevationWall = (i - 1) * FloorHeight;
                Calculate(i, -2 * constantWallThickness, out p1, out p2, out p3, out p4);
                point1 = new HbXYZ(p1.X, p1.Y, elevationWall);
                point2 = new HbXYZ(p2.X, p2.Y, elevationWall);
                point3 = new HbXYZ(p3.X, p3.Y, elevationWall);
                point4 = new HbXYZ(p4.X, p4.Y, elevationWall);
                csvWriter.AddWall(point1, point2);
                csvWriter.AddWall(point2, point3);
                csvWriter.AddWall(point3, point4);
                csvWriter.AddWall(point4, point1);
            }
            csvWriter.WriteFile();
            return(true);
        }
Exemplo n.º 9
0
        public bool CreateWalls()
        {
            string    filePath  = this.csvFolderPath + FILE_NAME_WALL;
            CsvWriter csvWriter = new CsvWriter();

            csvWriter.Precision = 4;
            string returnValue = csvWriter.ConnectToFile(filePath);

            if (returnValue != "")
            {
                MessageBox.Show(returnValue);
                return(false);
            }
            if (this.preserveId)
            {
                // Note that if file doesn't exist yet we ignore option to preserve ID values
                if (File.Exists(filePath))
                {
                    try {
                        returnValue = csvWriter.ReadElementIds();
                        if (returnValue != "")
                        {
                            MessageBox.Show(returnValue);
                            return(false);
                        }
                    }
                    catch (Exception exception) {
                        MessageBox.Show("Exception at csvWriter.ReadElementIds(): " + exception.Message);
                        return(false);
                    }
                }
            }

            Spiral spiral = new Spiral(centerPoint);

            spiral.FactorA = FactorA;
            spiral.FactorB = FactorB;
            for (int i = 0; i < NumberOfPoints; i++)
            {
                XY    xyStart  = spiral.CalculatePoint(i);
                XY    xyEnd    = spiral.CalculatePoint(i + 1);
                XY    xyMid    = spiral.CalculatePoint(i + 0.5);
                HbXYZ xyzStart = new HbXYZ(xyStart.X, xyStart.Y, 0.0);
                HbXYZ xyzEnd   = new HbXYZ(xyEnd.X, xyEnd.Y, 0.0);
                HbXYZ xyzMid   = new HbXYZ(xyMid.X, xyMid.Y, 0.0);
                csvWriter.AddWall(xyzStart, xyzEnd, xyzMid);
            }
            csvWriter.WriteFile();
            return(true);
        }
Exemplo n.º 10
0
        // ************************************************** Public Functions ***********************************************
        public bool CreateGrids()
        {
            string    filePath  = this.csvFolderPath + FILE_NAME_GRID;
            CsvWriter csvWriter = new CsvWriter();

            csvWriter.Precision = 4;
            string returnValue = csvWriter.ConnectToFile(filePath);

            if (returnValue != "")
            {
                MessageBox.Show(returnValue);
                return(false);
            }
            if (this.preserveId)
            {
                // Note that if file doesn't exist yet we ignore option to preserve ID values
                if (File.Exists(filePath))
                {
                    try {
                        returnValue = csvWriter.ReadElementIds();
                        if (returnValue != "")
                        {
                            MessageBox.Show(returnValue);
                            return(false);
                        }
                    }
                    catch (Exception exception) {
                        MessageBox.Show("Exception at csvWriter.ReadElementIds(): " + exception.Message);
                        return(false);
                    }
                }
            }

            Spiral spiral = new Spiral(this.centerPoint);

            spiral.FactorA = FactorA;
            spiral.FactorB = FactorB;
            HbXYZ currentPoint;
            HbXYZ centerPoint = new HbXYZ(0.0, 0.0, 0.0);

            for (int i = 0; i <= NumberOfPoints; i++)
            {
                XY xy = spiral.CalculatePoint(i);
                currentPoint = new HbXYZ(2 * xy.X, 2 * xy.Y, 0.0);
                csvWriter.AddGrid(centerPoint, currentPoint);
                csvWriter.ModifyParameterSet("Name", (i + 1).ToString());
            }
            csvWriter.WriteFile();
            return(true);
        }
Exemplo n.º 11
0
        // No need for these to be public at this time but could be useful in the future

        private bool ConvertHbXyz(HbXYZ hbXyz, out XYZ xyz)
        {
            if (hbXyz == null)   // For optional value cases like parameters with Add FamilyExtrusion
            {
                xyz = null;
                return(true);
            }
            try {
                xyz = new XYZ(hbXyz.X, hbXyz.Y, hbXyz.Z);
                return(true);
            }
            catch {
                xyz = null;
                return(false);
            }
        }
Exemplo n.º 12
0
        // ************************************************ RevitModelBuilder Data Functions *****************************************************
        public HbCurve Hb(NurbsCurve nurbsCurveRhino)
        {
            HbNurbSpline nurbSplineRevit = new HbNurbSpline();

            Rhino.Geometry.Collections.NurbsCurvePointList points = nurbsCurveRhino.Points;
            for (int k = 0; k < points.Count; k++)
            {
                Rhino.Geometry.ControlPoint controlPoint = points[k];
                Point3d xyzRhino = controlPoint.Location;
                HbXYZ   xyzRevit = new HbXYZ(xyzRhino.X, xyzRhino.Y, xyzRhino.Z);
                nurbSplineRevit.Points.Add(xyzRevit);
            }
            HbCurve hbCurve = nurbSplineRevit;

            return(hbCurve);
        }
Exemplo n.º 13
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            // Set up Utility object and start process
            Utility utility = new Utility(DA);

            utility.Print("Starting Adaptive Components.");
            List <string> instructionData = new List <string>();

            // Get Inputs
            string folderPath = null, fileName = null;
            bool   write = false;

            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;
            }

            string familyName = null, typeName = null;             // Family and type are optional but both must be provided if used.

            utility.GetInput(3, ref familyName);
            utility.GetInput(4, ref typeName);

            GH_Structure <GH_Point> points = null;                  // Points in Data Tree required

            if (!utility.GetInput(5, out points))
            {
                return;
            }

            List <string>            parameterNames = null;        // Parameter names list and values tree are optional but both must be provided if used.
            GH_Structure <GH_String> parameterValues = null;

            string[,] parameterArray = null;
            utility.GetParameterValueArray(6, 7, ref parameterNames, out parameterValues, out parameterArray);
            int iMaxCountParam = 0, jMaxCountParam = 0;

            if (parameterArray != null)
            {
                iMaxCountParam = parameterArray.GetLength(0);
                jMaxCountParam = parameterArray.GetLength(1);
                if (parameterNames.Count < jMaxCountParam)
                {
                    jMaxCountParam = parameterNames.Count;
                }
            }

            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;
                    }

                    // Set Family and Type
                    if (familyName != null && typeName != null)
                    {
                        csvWriter.SetAdaptiveComponentType(familyName, typeName);
                    }

                    // Loop for each adaptive component, get points, and place component; then set parameter values
                    for (int i = 0; i < points.Branches.Count; i++)
                    {
                        // Add Adaptive Component
                        List <GH_Point> branch = points.Branches[i];
                        HbXYZ           hbXYZ1, hbXYZ2, hbXYZ3, hbXYZ4;
                        if (branch.Count <= 4)
                        {
                            hbXYZ1 = new HbXYZ(branch[0].Value.X, branch[0].Value.Y, branch[0].Value.Z);
                            if (branch.Count > 1)
                            {
                                hbXYZ2 = new HbXYZ(branch[1].Value.X, branch[1].Value.Y, branch[1].Value.Z);
                            }
                            else
                            {
                                hbXYZ2 = null;
                            }
                            if (branch.Count > 2)
                            {
                                hbXYZ3 = new HbXYZ(branch[2].Value.X, branch[2].Value.Y, branch[2].Value.Z);
                            }
                            else
                            {
                                hbXYZ3 = null;
                            }
                            if (branch.Count > 3)
                            {
                                hbXYZ4 = new HbXYZ(branch[3].Value.X, branch[3].Value.Y, branch[3].Value.Z);
                            }
                            else
                            {
                                hbXYZ4 = null;
                            }
                            csvWriter.AddAdaptiveComponent(hbXYZ1, hbXYZ2, hbXYZ3, hbXYZ4);
                            instructionData.Add("Add Adaptive Component:");
                        }
                        else
                        {
                            List <HbXYZ> pointsListRevit = new List <HbXYZ>();
                            for (int j = 0; j < branch.Count; j++)
                            {
                                HbXYZ hbXYZ = new HbXYZ(branch[j].Value.X, branch[j].Value.Y, branch[j].Value.Z);
                                pointsListRevit.Add(hbXYZ);
                            }
                            csvWriter.AddAdaptiveComponent(pointsListRevit);
                            instructionData.Add("Add Adaptive ComponentX:");
                        }

                        // Set parameters if needed. Assume user has matched the list lengths.  Error handling silently truncates if they don't match.
                        if (parameterArray != null)
                        {
                            for (int j = 0; j < parameterNames.Count; j++)
                            {
                                if (i < iMaxCountParam && j < jMaxCountParam)
                                {
                                    csvWriter.ModifyParameterSet(parameterNames[j], parameterArray[i, j]);
                                    instructionData.Add("Set Param: " + parameterNames[j] + ", " + parameterArray[i, j]);
                                }
                            }
                        }
                    }
                    csvWriter.WriteFile();
                    utility.Print("Adaptive Components completed successfully.");
                }
                catch (Exception exception) {
                    utility.Print(exception.Message);
                }
            }
            utility.WriteOut();
            DA.SetDataList(1, instructionData);
        }
Exemplo n.º 14
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);
            }
        }
Exemplo n.º 15
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            // Set up Utility object and start process
            Utility utility = new Utility(DA);

            utility.Print("Starting Beams.");
            List <string> instructionData = new List <string>();

            // Get Inputs
            string folderPath = null, fileName = null;
            bool   write = false;

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

            string familyName = null, typeName = null;               // 3, 4 - Family and type are optional but both must be provided if used.

            utility.GetInput(3, ref familyName);
            utility.GetInput(4, ref typeName);

            GH_Structure <GH_Point> points = null;                    // 5 - Points in Data Tree required

            if (!utility.GetInput(5, out points))
            {
                return;
            }

            List <double> rotations        = null;                   // 6 - Rotations list optional

            utility.GetInput(6, ref rotations);
            int iMaxCountRotate = 0;

            if (rotations != null)
            {
                iMaxCountRotate = rotations.Count;
            }

            List <string>            parameterNames  = null;         // 7, 8 - Parameter names list and values tree are optional but both must be provided if used.
            GH_Structure <GH_String> parameterValues = null;

            string[,] parameterArray = null;
            utility.GetParameterValueArray(7, 8, ref parameterNames, out parameterValues, out parameterArray);
            int iMaxCountParam = 0, jMaxCountParam = 0;

            if (parameterArray != null)
            {
                iMaxCountParam = parameterArray.GetLength(0);
                jMaxCountParam = parameterArray.GetLength(1);
                if (parameterNames.Count < jMaxCountParam)
                {
                    jMaxCountParam = parameterNames.Count;
                }
            }

            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;
                    }

                    // Set Family and Type
                    if (familyName != null && typeName != null)
                    {
                        csvWriter.SetBeamType(familyName, typeName);
                    }

                    // Loop for each beam, get points, and place component; then set parameter values
                    double lastRotationValue = 0;
                    for (int i = 0; i < points.Branches.Count; i++)
                    {
                        // Set rotation if necessary
                        if (rotations != null)
                        {
                            if (i < iMaxCountRotate)
                            {
                                if (Math.Abs(lastRotationValue - rotations[i]) > 0.00000001)
                                {
                                    csvWriter.SetBeamRotation(rotations[i]);
                                    lastRotationValue = rotations[i];
                                }
                            }
                        }

                        // Add the beam
                        List <List <HbCurve> > curvesListListRevit      = new List <List <HbCurve> >();
                        List <Grasshopper.Kernel.Types.GH_Point> branch = points.Branches[i];
                        HbXYZ hbXYZ1 = new HbXYZ(branch[0].Value.X, branch[0].Value.Y, branch[0].Value.Z);
                        HbXYZ hbXYZ2 = new HbXYZ(branch[1].Value.X, branch[1].Value.Y, branch[1].Value.Z);
                        csvWriter.AddBeam(hbXYZ1, hbXYZ2);

                        // Set parameters if needed. Assume user has matched the list lengths.  Error handling silently truncates if they don't match.
                        if (parameterArray != null)
                        {
                            for (int j = 0; j < parameterNames.Count; j++)
                            {
                                if (i < iMaxCountParam && j < jMaxCountParam)
                                {
                                    csvWriter.ModifyParameterSet(parameterNames[j], parameterArray[i, j]);
                                    instructionData.Add("Add Beam:");
                                }
                            }
                        }
                    }

                    csvWriter.WriteFile();
                    utility.Print("Beams completed successfully.");
                }
                catch (Exception exception) {
                    utility.Print(exception.Message);
                }
            }
            utility.WriteOut();
            DA.SetDataList(1, instructionData);
        }
Exemplo n.º 16
0
 public HbArc(HbXYZ pointStart, HbXYZ pointEnd, HbXYZ pointMid)
 {
     PointStart = pointStart;
     PointEnd   = pointEnd;
     PointMid   = pointMid;
 }
Exemplo n.º 17
0
 // For use with DesignScript
 public static HbEllipse New(HbXYZ pointFirst, HbXYZ pointSecond, double radiusY, string mode)
 {
     return(new HbEllipse(pointFirst, pointSecond, radiusY, mode));
 }
Exemplo n.º 18
0
        private bool ProcessPointsToBrep(HbXYZ hbXYZ1, HbXYZ hbXYZ2, HbXYZ hbXYZ3, HbXYZ hbXYZ4)     // planar floor
        {
            try {
                double brepTolerence = GH_Component.DocumentTolerance();  // Not sure what this is but suggested by McNeel
                if (brepTolerence <= 0.0)
                {
                    brepTolerence = 0.001;                                // Since we are not sure what the effect would be
                }
                if (hbXYZ1 == null || hbXYZ2 == null || hbXYZ3 == null || hbXYZ4 == null)
                {
                    return(true);                                                                      // Don't process bad data
                }
                List <Point3d> points = new List <Point3d> {
                    new Point3d(hbXYZ1.X, hbXYZ1.Y, hbXYZ1.Z),
                    new Point3d(hbXYZ2.X, hbXYZ2.Y, hbXYZ2.Z),
                    new Point3d(hbXYZ3.X, hbXYZ3.Y, hbXYZ3.Z),
                    new Point3d(hbXYZ4.X, hbXYZ4.Y, hbXYZ4.Z)
                };
                List <Curve> curves = new List <Curve>()
                {
                    new LineCurve(points[0], points[1]),
                    new LineCurve(points[1], points[2]),
                    new LineCurve(points[2], points[3]),
                    new LineCurve(points[3], points[0])
                };

                PolyCurve polyCurve = new PolyCurve();
                foreach (LineCurve curve in curves)
                {
                    polyCurve.Append(curve);
                }

                // Obsolete w Revit 6
                // Brep brep = Brep.CreatePlanarBreps(curves)[0];
                Brep brep = Brep.CreatePlanarBreps(curves, brepTolerence)[0];

                // Add to outputs
                this.dataTreePoints.AddRange(points, new GH_Path(indexPoints));
                indexPoints++;
                this.dataTreeCurves.AddRange(curves, new GH_Path(indexCurves));
                indexCurves++;
                this.dataTreeBreps.AddRange(new List <Brep> {
                    brep
                }, new GH_Path(indexBreps));
                indexBreps++;

                // Create Geometry
                if (createGeometryPoints)
                {
                    foreach (Point3d point3d in points)
                    {
                        Rhino.RhinoDoc.ActiveDoc.Objects.AddPoint(point3d);
                    }
                }
                if (createGeometryCurves)
                {
                    foreach (Curve curveItem in curves)
                    {
                        Rhino.RhinoDoc.ActiveDoc.Objects.AddCurve(curveItem);
                    }
                }
                if (createGeometrySurfaces)
                {
                    Rhino.RhinoDoc.ActiveDoc.Objects.AddBrep(brep);
                }
                return(true);
            }
            catch {
                return(false);
            }
        }
Exemplo n.º 19
0
 // For use with DesignScript
 public static HbLine New(HbXYZ pointStart, HbXYZ pointEnd)
 {
     return(new HbLine(pointStart, pointEnd));
 }
Exemplo n.º 20
0
        public bool CreateAdaptiveComponents()
        {
            string    filePath    = this.csvFolderPath + FILE_NAME_ADAPTIVE_COMPONENT;
            CsvWriter csvWriter   = new CsvWriter();
            string    returnValue = csvWriter.ConnectToFile(filePath);

            if (returnValue != "")
            {
                MessageBox.Show(returnValue);
                return(false);
            }
            if (this.preserveId)
            {
                // Note that if file doesn't exist yet we ignore option to preserve ID values
                if (File.Exists(filePath))
                {
                    try {
                        returnValue = csvWriter.ReadElementIds();
                        if (returnValue != "")
                        {
                            MessageBox.Show(returnValue);
                            return(false);
                        }
                    }
                    catch (Exception exception) {
                        MessageBox.Show("Exception at csvWriter.ReadElementIds(): " + exception.Message);
                        return(false);
                    }
                }
            }

            HbXYZ point1A, point2A, point3A, point4A;
            HbXYZ point1B = new HbXYZ(0, 0, 0); HbXYZ point2B = new HbXYZ(0, 0, 0);
            HbXYZ point3B = new HbXYZ(0, 0, 0); HbXYZ point4B = new HbXYZ(0, 0, 0);

            csvWriter.SetAdaptiveComponentType(ADAPTIVE_COMPONENT_TYPE, ADAPTIVE_COMPONENT_TYPE);
            XY p1, p2, p3, p4;

            for (int i = 0; i < NumberFloors; i++)
            {
                double elevationWall = i * FloorHeight;
                Calculate(i, 0, out p1, out p2, out p3, out p4);
                point1A = new HbXYZ(p1.X, p1.Y, elevationWall);
                point2A = new HbXYZ(p2.X, p2.Y, elevationWall);
                point3A = new HbXYZ(p3.X, p3.Y, elevationWall);
                point4A = new HbXYZ(p4.X, p4.Y, elevationWall);
                if (i != 0)
                {
                    csvWriter.AddAdaptiveComponent(point1A, point2A, point2B, point1B);
                    csvWriter.AddAdaptiveComponent(point2A, point3A, point3B, point2B);
                    csvWriter.AddAdaptiveComponent(point3A, point4A, point4B, point3B);
                    csvWriter.AddAdaptiveComponent(point4A, point1A, point1B, point4B);
                }
                point1B = new HbXYZ(point1A.X, point1A.Y, point1A.Z);
                point2B = new HbXYZ(point2A.X, point2A.Y, point2A.Z);
                point3B = new HbXYZ(point3A.X, point3A.Y, point3A.Z);
                point4B = new HbXYZ(point4A.X, point4A.Y, point4A.Z);
            }
            csvWriter.WriteFile();
            return(true);
        }
Exemplo n.º 21
0
        // ************************************************** Public Functions ***********************************************
        public bool CreateStructure()
        {
            string    filePath    = this.csvFolderPath + FILE_NAME_STRUCTURE;
            CsvWriter csvWriter   = new CsvWriter();
            string    returnValue = csvWriter.ConnectToFile(filePath);

            if (returnValue != "")
            {
                MessageBox.Show(returnValue);
                return(false);
            }
            if (this.preserveId)
            {
                // Note that if file doesn't exist yet we ignore option to preserve ID values
                if (File.Exists(filePath))
                {
                    try {
                        returnValue = csvWriter.ReadElementIds();
                        if (returnValue != "")
                        {
                            MessageBox.Show(returnValue);
                            return(false);
                        }
                    }
                    catch (Exception exception) {
                        MessageBox.Show("Exception at csvWriter.ReadElementIds(): " + exception.Message);
                        return(false);
                    }
                }
            }

            csvWriter.SetBeamJustification("Top");

            HbXYZ point1A, point2A, point3A, point4A;
            HbXYZ point1B = new HbXYZ(0, 0, 0); HbXYZ point2B = new HbXYZ(0, 0, 0);
            HbXYZ point3B = new HbXYZ(0, 0, 0); HbXYZ point4B = new HbXYZ(0, 0, 0);
            //mModelBuilder.  beam tops?
            //double elevationFloor, elevationWall; //, x1, x2, x3, x4, y1, y2, y3, y4;
            XY p1, p2, p3, p4;

            for (int i = 0; i < NumberFloors; i++)
            {
                //Calculate(i, out elevationFloor, out elevationWall, out p1, out p2, out p3, out p4);
                double elevationBeam = i * FloorHeight - constantFloorThickness;
                Calculate(i, -4 * constantWallThickness, out p1, out p2, out p3, out p4);
                point1A = new HbXYZ(p1.X, p1.Y, elevationBeam);
                point2A = new HbXYZ(p2.X, p2.Y, elevationBeam);
                point3A = new HbXYZ(p3.X, p3.Y, elevationBeam);
                point4A = new HbXYZ(p4.X, p4.Y, elevationBeam);
                if (i != 0)
                {
                    csvWriter.AddColumn(point1B, point1A);
                    csvWriter.AddColumn(point2B, point2A);
                    csvWriter.AddColumn(point3B, point3A);
                    csvWriter.AddColumn(point4B, point4A);
                }
                csvWriter.AddBeam(point1A, point2A);
                csvWriter.AddBeam(point2A, point3A);
                csvWriter.AddBeam(point3A, point4A);
                csvWriter.AddBeam(point4A, point1A);
                point1B = new HbXYZ(point1A.X, point1A.Y, point1A.Z);
                point2B = new HbXYZ(point2A.X, point2A.Y, point2A.Z);
                point3B = new HbXYZ(point3A.X, point3A.Y, point3A.Z);
                point4B = new HbXYZ(point4A.X, point4A.Y, point4A.Z);
            }
            csvWriter.WriteFile();
            return(true);
        }
Exemplo n.º 22
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            bool   write      = false;
            string folderPath = null;
            string fileName   = null;
            GH_Structure <GH_Point> points          = null;
            List <string>           instructionData = new List <string>();

            if (DA.Iteration == 0)
            {
                switch (this.loftMode)
                {
                case LoftMode.None:
                    this.Message = "Default";
                    break;

                case LoftMode.Points:
                    this.Message = "Ref Points";
                    break;

                case LoftMode.Lines:
                    this.Message = "Lines";
                    break;

                case LoftMode.Loft:
                    this.Message = "Surface";
                    break;
                }
            }

            // Set up Utility object and start process
            Utility utility = new Utility(DA);

            utility.Print("Starting Loft Form.");

            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 points))
            {
                return;
            }

            if (write)
            {
                // 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;
                }
                switch (this.loftMode)
                {
                case LoftMode.Loft:
                    // Loop for each branch, get points, and create form
                    List <List <HbXYZ> > pointsListListRevit = new List <List <HbXYZ> >();
                    if (!utility.ReadDataTree(points, ref pointsListListRevit))
                    {
                        return;
                    }
                    csvWriter.AddLoftForm(pointsListListRevit);
                    instructionData.Add("Add Loft Form:");
                    csvWriter.WriteFile();
                    utility.Print("Loft Form completed successfully.");
                    break;

                case LoftMode.Lines:
                    // Loop for each branch, get points, and place curve
                    for (int i = 0; i < points.Branches.Count; i++)
                    {
                        List <GH_Point> branch          = points.Branches[i];
                        List <HbXYZ>    pointsListRevit = new List <HbXYZ>();
                        for (int j = 0; j < branch.Count; j++)
                        {
                            HbXYZ hbXYZ = new HbXYZ(branch[j].Value.X, branch[j].Value.Y, branch[j].Value.Z);
                            pointsListRevit.Add(hbXYZ);
                        }
                        csvWriter.AddCurveByPoints(pointsListRevit);
                        instructionData.Add("Add Curve by Points:");
                    }
                    csvWriter.WriteFile();
                    utility.Print("Curves By Points completed successfully.");
                    break;

                case LoftMode.Points:
                    List <GH_Point> points_list = null;
                    points_list = points.FlattenData();
                    // Loop for each point and place reference point.
                    for (int i = 0; i < points_list.Count; i++)
                    {
                        HbXYZ hbXYZ = new HbXYZ(points_list[i].Value.X, points_list[i].Value.Y, points_list[i].Value.Z);
                        csvWriter.AddReferencePoint(hbXYZ);
                        instructionData.Add("Add Reference Point:");
                    }
                    csvWriter.WriteFile();
                    utility.Print("Reference Points completed successfully.");
                    break;
                }
            }
            utility.WriteOut();
            DA.SetDataList(1, instructionData);
        }
Exemplo n.º 23
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            if (DA.Iteration == 0)
            {
                switch (this.areaMode)
                {
                case AreaMode.None:
                    this.Message = "Select Mode";
                    break;

                case AreaMode.Rooms:
                    this.Message = "Rooms";
                    break;

                case AreaMode.Areas:
                    this.Message = "Areas";
                    break;
                }
            }

            // Set up Utility object and start process
            Utility utility = new Utility(DA);

            utility.Print("Starting " + this.Message + ".");
            List <string> instructionData = new List <string>();

            // Get Inputs
            string folderPath = null, fileName = null;
            bool   write = false;

            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;
            }


            GH_Structure <GH_Point> points = null;               // Points in Data Tree required

            if (!utility.GetInput(3, out points))
            {
                return;
            }

            List <string>            parameterNames  = null;    // Parameter names list and values tree are optional but both must be provided if used.
            GH_Structure <GH_String> parameterValues = null;

            string[,] parameterArray = null;
            utility.GetParameterValueArray(4, 5, ref parameterNames, out parameterValues, out parameterArray);
            int iMaxCountParam = 0, jMaxCountParam = 0;

            if (parameterArray != null)
            {
                iMaxCountParam = parameterArray.GetLength(0);
                jMaxCountParam = parameterArray.GetLength(1);
                if (parameterNames.Count < jMaxCountParam)
                {
                    jMaxCountParam = parameterNames.Count;
                }
            }

            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;
                    }

                    // Loop for each room, get points, and place component; then set parameter values
                    for (int i = 0; i < points.Branches.Count; i++)
                    {
                        // Add the room
                        List <List <HbCurve> > curvesListListRevit      = new List <List <HbCurve> >();
                        List <Grasshopper.Kernel.Types.GH_Point> branch = points.Branches[i];
                        HbXYZ hbXYZ = new HbXYZ(branch[0].Value.X, branch[0].Value.Y, branch[0].Value.Z);

                        //switch on room or area
                        switch (this.areaMode)
                        {
                        case AreaMode.Rooms: {
                            csvWriter.AddRoom(hbXYZ);
                            instructionData.Add("Add Room: " + utility.formatPoint(hbXYZ));
                            break;
                        }

                        case AreaMode.Areas: {
                            csvWriter.AddArea(hbXYZ);
                            instructionData.Add("Add Room: " + utility.formatPoint(hbXYZ));
                            break;
                        }

                        default: {
                            break;
                        }
                        }

                        // Set parameters if needed. Assume user has matched the list lengths.  Error handling silently truncates if they don't match.
                        if (parameterArray != null)
                        {
                            for (int j = 0; j < parameterNames.Count; j++)
                            {
                                if (i < iMaxCountParam && j < jMaxCountParam)
                                {
                                    csvWriter.ModifyParameterSet(parameterNames[j], parameterArray[i, j]);
                                    instructionData.Add("Set Param: " + parameterNames[j] + ", " + parameterArray[i, j]);
                                }
                            }
                        }
                    }
                    csvWriter.WriteFile();
                    utility.Print("Rooms_Areas completed successfully.");
                }
                catch (Exception exception) {
                    utility.Print(exception.Message);

                    return;
                }
            }
            utility.WriteOut();
            DA.SetDataList(1, instructionData);
        }
Exemplo n.º 24
0
 // For use with DesignScript
 public static HbArc New(HbXYZ pointStart, HbXYZ pointEnd, HbXYZ pointMid)
 {
     return(new HbArc(pointStart, pointEnd, pointMid));
 }
Exemplo n.º 25
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            // Set up Utility object and start process
            Utility utility = new Utility(DA);

            utility.Print("Starting Families.");
            List <string> instructionData = new List <string>();

            // Get Inputs
            string folderPath = null, fileName = null;
            bool   write = false;

            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;
            }

            string familyName = null, typeName = null;               // Family and type are optional

            utility.GetInput(3, ref familyName);
            utility.GetInput(4, ref typeName);

            GH_Structure <GH_Point> points = null;                    // Points in Data Tree required

            if (!utility.GetInput(5, out points))
            {
                return;
            }

            List <double> rotation         = null;                   // Rotation list optional

            utility.GetInput(6, ref rotation);
            int iMaxCountRotate = 0;

            if (rotation != null)
            {
                iMaxCountRotate = rotation.Count;
            }

            //7-10 flipx,flipy, mirrx,mirry - Booleans to flip and/or mirror family
            List <bool> flipHand = null, flipFace = null;
            List <bool> mirrorX = null, mirrorY = null;

            utility.GetInput(7, ref flipHand);
            utility.GetInput(8, ref flipFace);
            utility.GetInput(9, ref mirrorX);
            utility.GetInput(10, ref mirrorY);

            List <string>            parameterNames = null;          // Parameter names list and values tree are optional but both must be provided if used.
            GH_Structure <GH_String> parameterValues = null;

            string[,] parameterArray = null;
            utility.GetParameterValueArray(11, 12, ref parameterNames, out parameterValues, out parameterArray);
            int iMaxCountParam = 0, jMaxCountParam = 0;

            if (parameterArray != null)
            {
                iMaxCountParam = parameterArray.GetLength(0);
                jMaxCountParam = parameterArray.GetLength(1);
                if (parameterNames.Count < jMaxCountParam)
                {
                    jMaxCountParam = parameterNames.Count;
                }
            }

            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;
                    }

                    // Set Family and Type
                    if (familyName != null && typeName != null)
                    {
                        csvWriter.SetFamilyType(familyName, typeName);
                    }

                    // Loop for each Family, get points, and place component; then set parameter values
                    double lastRotationValue = 0;
                    bool   lastFlipHandValue = false, lastFlipFaceValue = false;
                    bool   lastMirrorXValue = false, lastMirrorYValue = false;

                    for (int i = 0; i < points.Branches.Count; i++)
                    {
                        // Set rotation if necessary
                        if (i < iMaxCountRotate)
                        {
                            if (Math.Abs(lastRotationValue - rotation[i]) > 0.00000001)
                            {
                                csvWriter.SetFamilyRotation(rotation[i]);
                                instructionData.Add("Set Rotate: " + rotation[i].ToString());
                                lastRotationValue = rotation[i];
                            }
                        }

                        // Set Flip if necessary
                        if (flipHand.Count != 0 || flipFace.Count != 0)
                        {
                            bool flipHandThis = false;
                            bool flipFaceThis = false;
                            if (i < flipHand.Count)
                            {
                                flipHandThis = flipHand[i];
                            }
                            if (i < flipFace.Count)
                            {
                                flipFaceThis = flipFace[i];
                            }
                            if (flipHandThis != lastFlipHandValue || flipFaceThis != lastFlipFaceValue)
                            {
                                csvWriter.SetFamilyFlipped(flipHandThis, flipFaceThis);
                                instructionData.Add("Set Flipped: " + flipHandThis.ToString() + ", " + flipFaceThis.ToString());
                                lastFlipHandValue = flipHandThis;
                                lastFlipFaceValue = flipFaceThis;
                            }
                        }

                        // Set Mirror if necessary
                        if (mirrorX.Count != 0 || mirrorY.Count != 0)
                        {
                            bool mirrorXThis = false;
                            bool mirrorYThis = false;
                            if (i < mirrorX.Count)
                            {
                                mirrorXThis = mirrorX[i];
                            }
                            if (i < mirrorY.Count)
                            {
                                mirrorYThis = mirrorY[i];
                            }
                            if (mirrorXThis != lastMirrorXValue || mirrorYThis != lastMirrorYValue)
                            {
                                csvWriter.SetFamilyMirrored(mirrorXThis, mirrorYThis);
                                instructionData.Add("Set Mirrored: " + mirrorXThis.ToString() + ", " + mirrorYThis.ToString());
                                lastMirrorXValue = mirrorXThis;
                                lastMirrorYValue = mirrorYThis;
                            }
                        }

                        // Add the Family
                        List <List <HbCurve> > curvesListListRevit      = new List <List <HbCurve> >();
                        List <Grasshopper.Kernel.Types.GH_Point> branch = points.Branches[i];
                        HbXYZ hbXYZ = new HbXYZ(branch[0].Value.X, branch[0].Value.Y, branch[0].Value.Z);
                        csvWriter.AddFamilyInstance(hbXYZ);
                        instructionData.Add("Add Family:");

                        // Set parameters if needed. Assume user has matched the list lengths.  Error handling silently truncates if they don't match.
                        if (parameterArray != null)
                        {
                            for (int j = 0; j < parameterNames.Count; j++)
                            {
                                if (i < iMaxCountParam && j < jMaxCountParam)
                                {
                                    csvWriter.ModifyParameterSet(parameterNames[j], parameterArray[i, j]);
                                    instructionData.Add("Set Param: " + parameterNames[j] + ", " + parameterArray[i, j]);
                                }
                            }
                        }
                    }

                    csvWriter.WriteFile();
                    utility.Print("Family Instances completed successfully.");
                }
                catch (Exception exception) {
                    utility.Print(exception.Message);
                }
            }
            utility.WriteOut();
            DA.SetDataList(1, instructionData);
        }
Exemplo n.º 26
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);
        }
Exemplo n.º 27
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            // Set up Utility object and start process
            Utility utility = new Utility(DA);

            utility.Print("Starting TopoSurface.");
            List <string> instructionData = new List <string>();

            // Get Inputs
            string folderPath = null, fileName = null;
            bool   write = false;

            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;
            }

            List <GH_Point> points = null;                            // Points in Data Tree required

            if (!utility.GetInput(3, ref points))
            {
                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 <HbXYZ> pointsListRevit = new List <HbXYZ>();

                    // Loop for each topo point tree or list
                    for (int i = 0; i < points.Count; i++)
                    {
                        // Add the point
                        HbXYZ hbXYZ = new HbXYZ(points[i].Value.X, points[i].Value.Y, points[i].Value.Z);
                        pointsListRevit.Add(hbXYZ);
                    }

                    csvWriter.AddTopographySurface(pointsListRevit);
                    instructionData.Add("Add Topo Surface:");
                    csvWriter.WriteFile();
                    utility.Print("TopoSurface completed successfully.");
                }
                catch (Exception exception) {
                    utility.Print(exception.Message);
                }
                utility.WriteOut();
                DA.SetDataList(1, instructionData);
            }
        }
Exemplo n.º 28
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            // Set up Utility object and start process
            Utility utility = new Utility(DA);

            utility.Print("Starting Family Extrusions.");
            List <string> instructionData = new List <string>();

            // Get Inputs
            string folderPath = null, fileName = null;
            bool   write = false;

            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;
            }

            string famName = null;

            utility.GetInput(3, ref famName);                   // Family Name is optional

            GH_Structure <GH_Curve> dataTree = null;            // Profiles in Data Tree required

            if (!utility.GetInput(4, out dataTree))
            {
                return;
            }

            List <GH_Point> placementPnt = null;

            utility.GetInput(5, ref placementPnt);   // placement point for profiles. optional

            List <double> heights = null;            // heights of extrusions

            if (!utility.GetInput(6, ref heights))
            {
                return;
            }

            List <string>            parameterNames  = null;    // Parameter names list and values tree are optional but both must be provided if used.
            GH_Structure <GH_String> parameterValues = null;

            string[,] parameterArray = null;

            utility.GetParameterValueArray(7, 8, ref parameterNames, out parameterValues, out parameterArray);
            int iMaxCountParam = 0, jMaxCountParam = 0;

            if (parameterArray != null)
            {
                iMaxCountParam = parameterArray.GetLength(0);
                jMaxCountParam = parameterArray.GetLength(1);
                if (parameterNames.Count < jMaxCountParam)
                {
                    jMaxCountParam = parameterNames.Count;
                }
            }

            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;
                    }

                    // Loop through the data tree of curves and process each one.
                    for (int i = 0; i < dataTree.Branches.Count; i++)
                    {
                        // Parse the profile curves
                        List <List <HbCurve> > curvesListListRevit = new List <List <HbCurve> >();
                        if (!utility.ReadDataTreeBranch(dataTree.Branches[i], ref curvesListListRevit))
                        {
                            utility.Print("ReadDataTreeBranch() failed");
                            utility.WriteOut();
                            return;
                        }

                        // set height assume user has matched the list lengths
                        if (heights != null)
                        {
                            csvWriter.SetFamilyExtrusionHeight(heights[i]);
                            instructionData.Add("Set Height:");
                        }

                        if (placementPnt.Count == 0 & famName == "")
                        {
                            csvWriter.AddFamilyExtrusion(curvesListListRevit);
                            instructionData.Add("Add Family Extrusion:");
                        }
                        else if (placementPnt.Count == 0 & famName != "")
                        {
                            csvWriter.AddFamilyExtrusion(curvesListListRevit, famName);
                            instructionData.Add("Add Family Extrusion:");
                        }
                        else if (placementPnt.Count != 0 & famName == "")
                        {
                            HbXYZ hbXYZ = new HbXYZ(placementPnt[i].Value.X, placementPnt[i].Value.Y, placementPnt[i].Value.Z);
                            csvWriter.AddFamilyExtrusion(curvesListListRevit, hbXYZ);
                            instructionData.Add("Add Family Extrusion:");
                        }
                        else
                        {
                            HbXYZ hbXYZ = new HbXYZ(placementPnt[i].Value.X, placementPnt[i].Value.Y, placementPnt[i].Value.Z);
                            csvWriter.AddFamilyExtrusion(curvesListListRevit, famName, hbXYZ);
                            instructionData.Add("Add Family Extrusion:");
                        }


                        // Set parameters. Assume user has matched the list lengths.  Error handling silently truncates if they don't match.
                        if (parameterArray != null)
                        {
                            for (int j = 0; j < parameterNames.Count; j++)
                            {
                                if (i < iMaxCountParam && j < jMaxCountParam)
                                {
                                    csvWriter.ModifyParameterSet(parameterNames[j], parameterArray[i, j]);
                                    instructionData.Add("Set Param: " + parameterNames[j] + ", " + parameterArray[i, j]);
                                }
                            }
                        }
                    }
                    csvWriter.WriteFile();
                    utility.Print("Mass Family Extrusions completed successfully.");
                }
                catch (Exception exception) {
                    utility.Print(exception.Message);
                }
            }
            utility.WriteOut();
            DA.SetDataList(1, instructionData);
        }
Exemplo n.º 29
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            // Set up Utility object and start process
            Utility utility = new Utility(DA);

            utility.Print("Starting Columns.");
            List <string> instructionData = new List <string>();

            bool write = false;

            if (DA.Iteration == 0)
            {
                switch (this.colMode)
                {
                case ColMode.None:
                    this.Message = "Select Mode";
                    break;

                case ColMode.Arch:
                    this.Message = "Architectural";
                    break;

                case ColMode.StrucVert:
                    this.Message = "Structural Vertical";
                    break;

                case ColMode.StrucPoint:
                    this.Message = "Structural Point";
                    break;

                case ColMode.StrucAngle:
                    this.Message = "Structural Angle";
                    break;
                }
            }

            // Get Inputs
            string folderPath = null, fileName = null;

            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;
            }

            string familyName = null, typeName = null;         // Family and type are optional but both must be provided if used.

            utility.GetInput(3, ref familyName);
            utility.GetInput(4, ref typeName);

            GH_Structure <GH_Point> points = null;               // Points in Data Tree required

            if (!utility.GetInput(5, out points))
            {
                return;
            }

            List <double> heights          = null;              // Heights list optional

            utility.GetInput(6, ref heights);
            int iMaxCountHeight = 0;

            if (heights != null)
            {
                iMaxCountHeight = heights.Count;
            }

            List <double> rotations = null;                      // Rotations list optional

            utility.GetInput(7, ref rotations);
            int iMaxCountRotate = 0;

            if (rotations != null)
            {
                iMaxCountRotate = rotations.Count;
            }

            List <string>            parameterNames  = null;    // Parameter names list and values tree are optional but both must be provided if used.
            GH_Structure <GH_String> parameterValues = null;

            string[,] parameterArray = null;
            utility.GetParameterValueArray(8, 9, ref parameterNames, out parameterValues, out parameterArray);
            int iMaxCountParam = 0, jMaxCountParam = 0;

            if (parameterArray != null)
            {
                iMaxCountParam = parameterArray.GetLength(0);
                jMaxCountParam = parameterArray.GetLength(1);
                if (parameterNames.Count < jMaxCountParam)
                {
                    jMaxCountParam = parameterNames.Count;
                }
            }

            if (write)
            {
                // 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;
                }

                try {
                    // Switch on Column Mode
                    if (familyName != null && typeName != null)
                    {
                        switch (this.colMode)
                        {
                        case ColMode.Arch:
                            csvWriter.SetColumnMode("Architectural", familyName, typeName);
                            break;

                        case ColMode.StrucPoint:
                            csvWriter.SetColumnMode("StructuralPointDriven", familyName, typeName);
                            break;

                        case ColMode.StrucVert:
                            csvWriter.SetColumnMode("StructuralVertical", familyName, typeName);
                            break;

                        case ColMode.StrucAngle:
                            csvWriter.SetColumnMode("StructuralAngleDriven", familyName, typeName);
                            break;

                        default:
                            break;
                        }
                    }
                }
                catch (Exception exception) {
                    utility.Print(exception.Message);
                    utility.WriteOut();
                    return;
                }

                // Loop for each column, get points, and place component; then set parameter values
                try {
                    double lastRotationValue = 0;
                    double lastHeightValue   = 0;

                    for (int i = 0; i < points.Branches.Count; i++)
                    {
                        // Set rotation if necessary
                        if (rotations != null)
                        {
                            if (i < iMaxCountRotate)
                            {
                                if (Math.Abs(lastRotationValue - rotations[i]) > 0.00000001)
                                {
                                    csvWriter.SetColumnRotation(rotations[i]);
                                    lastRotationValue = rotations[i];
                                }
                            }
                        }

                        // Set Height if not in points placement mode.
                        if (colMode != ColMode.StrucPoint)
                        {
                            if (i < iMaxCountHeight)
                            {
                                if (Math.Abs(lastHeightValue - heights[i]) > 0.00000001)
                                {
                                    csvWriter.SetColumnHeight(heights[i]);
                                    lastHeightValue = heights[i];
                                }
                            }
                        }

                        // Add the Column
                        List <List <HbCurve> > curvesListListRevit      = new List <List <HbCurve> >();
                        List <Grasshopper.Kernel.Types.GH_Point> branch = points.Branches[i];
                        HbXYZ hbXYZ1 = new HbXYZ(branch[0].Value.X, branch[0].Value.Y, branch[0].Value.Z);

                        if (colMode == ColMode.StrucPoint)
                        {
                            HbXYZ hbXYZ2 = new HbXYZ(branch[1].Value.X, branch[1].Value.Y, branch[1].Value.Z);
                            csvWriter.AddColumn(hbXYZ1, hbXYZ2);
                            instructionData.Add("Add Column:");
                        }
                        else
                        {
                            csvWriter.AddColumn(hbXYZ1);
                            instructionData.Add("Add Column:");
                        }

                        // Set parameters if needed. Assume user has matched the list lengths.  Error handling silently truncates if they don't match.
                        if (parameterArray != null)
                        {
                            for (int j = 0; j < parameterNames.Count; j++)
                            {
                                if (i < iMaxCountParam && j < jMaxCountParam)
                                {
                                    csvWriter.ModifyParameterSet(parameterNames[j], parameterArray[i, j]);
                                    instructionData.Add("Set Param: " + parameterNames[j] + ", " + parameterArray[i, j]);
                                }
                            }
                        }
                    }
                    csvWriter.WriteFile();
                    utility.Print("Columns completed successfully.");
                }
                catch (Exception exception) {
                    utility.Print(exception.Message);
                }
            }
            utility.WriteOut();
            DA.SetDataList(1, instructionData);
        }
Exemplo n.º 30
0
 public HbReferencePoint(HbXYZ hbXyz)
 {
     X = hbXyz.X;
     Y = hbXyz.Y;
     Z = hbXyz.Z;
 }