protected override void SolveInstance(IGH_DataAccess DA) { // Set up Utility object and start process this.utility = new Utility(DA); utility.Print("Starting Input."); // Switch to avoid running calculations every time bool read = false; // Get Inputs string folderPath = null, fileName = null; if (!this.utility.GetInput(0, ref read)) // Write command is required { this.utility.WriteOut(); return; } if (!this.utility.GetInput(1, ref folderPath)) // Folder path is required { this.utility.WriteOut(); return; } if (!this.utility.GetInput(2, ref fileName)) // File name is required { this.utility.WriteOut(); return; } DA.GetData(3, ref this.createGeometryPoints); // Create geometry commands optional; default is true DA.GetData(4, ref this.createGeometryCurves); DA.GetData(5, ref this.createGeometrySurfaces); if (read) { string returnValue; try { // Initialize the output lists this.dataTreePoints = new DataTree <Point3d>(); this.dataTreeCurves = new DataTree <Curve>(); this.dataTreeBreps = new DataTree <Brep>(); // Used to create surfaces this.indexPoints = 0; this.indexCurves = 0; this.indexBreps = 0; // Setup the reader CsvReader csvReader = new CsvReader(); this.utility.Print("CsvWriter Version: " + csvReader.Version); if (!this.utility.EstablishCsvLink(csvReader, folderPath, fileName)) { this.utility.Print("EstablishCsvLink() failed"); this.utility.WriteOut(); return; } // Read the file returnValue = csvReader.ReadFile();; if (returnValue != "") { this.utility.Print("Error reading file: " + returnValue + "."); this.utility.WriteOut(); return; } // Check syntax returnValue = csvReader.CheckSyntax(); if (returnValue != "") { System.Windows.Forms.DialogResult dialogResult = System.Windows.Forms.MessageBox.Show( "Syntax error detected in file: " + returnValue + "\n\n" + "Select 'OK' to continue or 'Cancel' to stop processing.", "Hummingbird", System.Windows.Forms.MessageBoxButtons.OKCancel); if (dialogResult != System.Windows.Forms.DialogResult.OK) { this.utility.Print("Processing cancelled by user."); this.utility.WriteOut(); return; } } // Get the pre-parsed data returnValue = csvReader.GetInput(); List <Point3d> points; // Process all of the items foreach (HbInputItem hbInputItem in csvReader.HbInputItems) { // TODO Various places we may want to eliminate duplicate points? string hbAction = hbInputItem.CommandAction; string hbObject = hbInputItem.CommandObject; string hbModifier = hbInputItem.CommandModifier; switch (hbAction) { case "Add": switch (hbObject) { case "Level": points = new List <Point3d> { new Point3d(-10, -10, hbInputItem.DoubleValues[0]), new Point3d(10, -10, hbInputItem.DoubleValues[0]), new Point3d(10, 10, hbInputItem.DoubleValues[0]), new Point3d(-10, 10, hbInputItem.DoubleValues[0]) }; ProcessPlaneSurfaceByPoints(new Point3d(0, 0, hbInputItem.DoubleValues[0]), points, new Interval(-10, 10), new Interval(-10, 10)); break; case "Grid": //hbInputItem.HbCurve - HbLine or HbArc case "DetailLine": //hbInputItem.HbCurve - HbLine case "ModelLine": case "DetailArc": //hbInputItem.HbCurve - HbArc case "ModelArc": case "DetailEllipse": //hbInputItem.HbCurve - HbEllipse case "ModelEllipse": case "DetailNurbSpline": //hbInputItem.HbCurve - HbNurbSpline case "ModelNurbSpline": case "AreaBoundaryLine": case "RoomSeparationLine": switch (hbModifier) { case "": // Grid may be only one? case "Curve": //hbInputItem.HbCurve - HbLine, HbArc, HbEllipse, or HbNurbSpline ProcesssCurveItem(hbInputItem); break; case "CurveArrArray": //hbInputItem.HbCurveArrArray - (multiple HbLine, HbArc, HbNurbSpline) ProcessCurveArrArray(hbInputItem.HbCurveArrArray); // various kinds of lines, vertical wall, or planar floor break; } break; case "TopographySurface": //hbInputItem.HbXyzList - (multiple HbXYZ) points = new List <Point3d>(); foreach (HbXYZ hbXYZ in hbInputItem.ListHbXYZ) { points.Add(new Point3d(hbXYZ.X, hbXYZ.Y, hbXYZ.Z)); } ProcessTopographySurface(points); break; case "AdaptiveComponent": points = new List <Point3d>(); foreach (HbXYZ hbXYZ in hbInputItem.ListHbXYZ) { points.Add(new Point3d(hbXYZ.X, hbXYZ.Y, hbXYZ.Z)); } ProcessSinglePoints(points); break; case "Wall": switch (hbModifier) { case "Curve": // hbInputItem.hbCurve - HbLine or HbArc ProcesssCurveItem(hbInputItem, wallHeight); break; case "CurveArrArray": // hbInputItem.HbCurveArrArray - (multiple HbLine, HbArc, HbNurbSpline) ProcessCurveArrArray(hbInputItem.HbCurveArrArray); break; } break; case "Floor": case "FilledRegion": switch (hbModifier) { case "Points": // hbInputItem.HbXyzList - (multiple HbXYZ) ProcessPointsToBrep(hbInputItem.ListHbXYZ[0], hbInputItem.ListHbXYZ[1], hbInputItem.ListHbXYZ[2], hbInputItem.ListHbXYZ[3]); break; case "CurveArrArray": // hbInputItem.HbCurveArrayArray - (multiple HbLine, HbArc, HbNurbSpline) ProcessCurveArrArray(hbInputItem.HbCurveArrArray); break; } break; case "FamilyInstance": //hbInputItem.HbXyzList - (multiple HbXYZ) case "Column": // One for family instance, area, and room; case "Beam": // One or two with column and beam. case "Area": case "Room": points = new List <Point3d>(); points.Add(new Point3d(hbInputItem.ListHbXYZ[0].X, hbInputItem.ListHbXYZ[0].Y, hbInputItem.ListHbXYZ[0].Z)); if (hbInputItem.ListHbXYZ.Count == 2) { points.Add(new Point3d(hbInputItem.ListHbXYZ[1].X, hbInputItem.ListHbXYZ[1].Y, hbInputItem.ListHbXYZ[1].Z)); } ProcessSinglePoints(points); break; case "ReferencePoint": //hbInputItem.HbReferencePoint - HbReferencePoint points = new List <Point3d>(); // Apparently only a single point is allowed? points.Add(new Point3d(hbInputItem.HbReferencePoint.X, hbInputItem.HbReferencePoint.Y, hbInputItem.HbReferencePoint.Z)); ProcessSinglePoints(points); break; case "CurveByPoints": //hbInputItem.HbReferenceArray - (multiple HbReferencePoint) ProcessCurveByPoints(hbInputItem.HbReferenceArray); break; case "LoftForm": //hbInputItem.HbReferenceArrayArray - (multiple HbReferenceArray) //TODO More work ProcessLoftForm(hbInputItem.HbReferenceArrayArray); break; case "FamilyExtrusion": //TODO More work //hbInputItem.ListHbXyz[0] - HbXYZ (insertion point, optional) //hbInputItem.HbCurveArrayArray - (multiple HbLine, HbArc, HbNurbSpline) break; default: break; } break; case "Set": // Most cases are not handled switch (hbObject) { case "WallHeight": wallHeight = hbInputItem.DoubleValues[0]; break; default: break; } break; default: // Case "Modify" is not being handled break; } } // Write the output geometry // TODO: This would be a good place to eliminate duplicate geometry. Maybe add a bool switch as to whether or not to do that? DA.SetDataTree(1, this.dataTreePoints); DA.SetDataTree(2, this.dataTreeCurves); DA.SetDataTree(3, this.dataTreeBreps); // Write the output messages this.utility.Print("Input completed successfully."); this.utility.WriteOut(); } catch (Exception exception) { this.utility.Print(exception.Message); this.utility.WriteOut(); } } }