private List <Dimension> CreateDimensions( Document doc, GridParameters p, List <Grid> grid) { /* * This method create dimensions between grid axes, * for all orientations, one dimension line by one orientation */ List <Dimension> dimensions = new List <Dimension>(); // The view in which the dimensions will be drawn View view = GetView(doc); Orientation[] orientations = p.GetOrientations().ToArray(); Dictionary <Orientation, List <Grid> > gridsByOrientations = DivideGridByOrientation(p, grid, orientations.ToList()); foreach (Orientation orientation in orientations) { if (p.GetNumber(orientation) > 1) { CreateDimensionForOrientation( doc, gridsByOrientations, view, p, orientation); } } return(dimensions); }
private Dictionary <Orientation, List <Grid> > DivideGridByOrientation( GridParameters p, List <Grid> grid, List <Orientation> orientations) { Dictionary <Orientation, List <Grid> > gridsByOrientation = new Dictionary <Orientation, List <Grid> >(); int count = default; foreach (Orientation orientation in orientations) { int linesByOrientation = p.GetNumber(orientation); List <Grid> oneOrientationGrid = new List <Grid>(); for (int i = 0, n = linesByOrientation; i < n; i++) { oneOrientationGrid.Add(grid[count + i]); } count += linesByOrientation; gridsByOrientation.Add(orientation, oneOrientationGrid); } return(gridsByOrientation); }
private List <Grid> CreateAxes(Document doc, GridParameters p, Orientation orientation) { List <Grid> list = new List <Grid>(); Line line = default; Grid gridLine = default; double perpendicularSize = p.GetSize(p.GetPerpendicularOrientation(orientation)); double startPoint = p.GetStartPoint(orientation); double endPoint = p.GetEndPoint(orientation); int number = p.GetNumber(orientation); double distance = p.GetDistance(orientation); using (Transaction transaction = new Transaction(doc)) { try { // Iteration start with one (1), not zero (0)! for (int i = 1, n = number; i <= n; i++) { string name = default; double offset = default; if (distance > 0) { offset = (distance * i) - (perpendicularSize / 2); } double x0 = default; double x1 = default; double y0 = default; double y1 = default; switch (orientation) { case Orientation.Vertical: x0 = x1 = offset; y0 = startPoint; y1 = endPoint; name = "1"; break; case Orientation.Horizontal: x0 = startPoint; x1 = endPoint; y0 = y1 = offset; name = "A"; break; } transaction.Start($"Create {orientation.ToString().ToLower()} axis"); line = Line.CreateBound( new XYZ(x0, y0, 0), new XYZ(x1, y1, 0)); gridLine = Grid.Create(doc, line); // Initialize grid axes elevation double indent = GetElevationIndent(); double elevation = GetHighestElevation(doc); gridLine.SetVerticalExtents(0 - indent, indent + elevation); // Set name for first axis in orientation if (i == 1) { ElementCategoryFilter gridsFilter = new ElementCategoryFilter(BuiltInCategory.OST_Grids); FilteredElementCollector existingGrids = new FilteredElementCollector(doc) .WherePasses(gridsFilter) .WhereElementIsNotElementType(); List <string> existingGridsName = new List <string>(); foreach (Grid grid in existingGrids) { existingGridsName.Add(grid.Name); } if (existingGridsName.Contains(name)) { string prefixName; do { SetPrefixForm setPrefixForm = new SetPrefixForm(orientation.ToString()); setPrefixForm.ShowDialog(); if (setPrefixForm.DialogResult == DialogResult.Cancel) { throw new OperationCanceledException(); } prefixName = $"{setPrefixForm.prefix} {name}"; }while (existingGridsName.Contains(prefixName)); gridLine.Name = prefixName; } else { gridLine.Name = name; } } transaction.Commit(); list.Add(gridLine); } } catch (ArgumentException) { System.Windows.Forms.MessageBox.Show("The axes can't have same name"); } } return(list); }