Indeed Jeremy, I did miss that one, and it is precisely what is required. When it is run on a vertical grid, it works as expected. I modified your code so that the start and end points are given the same X value (i.e. truly vertical) to remove the microscopic "off-axis". It fails here:
// "The curve is unbound or not coincident with the original one of the datum plane"
grid.SetCurveInView(DatumExtentType.Model, view, newLine);
To be clear, if my code is run on a vertical grid (i.e. not really effecting a change, but still functionally the same), it completes without error.
The main change I made to your code is:
XYZ newStart = newXYZ(start.X, start.Y, start.Z);
XYZ newEnd = newXYZ(start.X, end.Y, end.Z);
A test file with faulty vertical grids can be found here:
For completeness, here is my code:
// only fixes vertical or horizontal - IsVertical public static Result FixGridAxisByPick(UIDocument uidoc, bool IsVertical, out string pstrMsg) { Document doc = uidoc.Document; Selection sel = uidoc.Selection; Autodesk.Revit.DB.View view = doc.ActiveView; string lstrMsg = "Off-Axis Error Results:"; ISelectionFilter f = new JtElementsOfClassSelectionFilter<Grid>(); Reference elemRef = sel.PickObject(ObjectType.Element, f, "Pick a grid"); Grid grid = doc.GetElement(elemRef) as Grid; IList<Curve> gridCurves = grid.GetCurvesInView(DatumExtentType.Model, view); using (Transaction tx = new Transaction(doc)) { tx.Start("Modify Grid Endpoints"); foreach (Curve c in gridCurves) { XYZ start = c.GetEndPoint(0); XYZ end = c.GetEndPoint(1); MessageBox.Show("start: " + start.ToString() + Environment.NewLine + " end: " + end.ToString()); //XYZ newStart = start + 10 * XYZ.BasisY; //XYZ newEnd = end - 10 * XYZ.BasisY; XYZ newStart = new XYZ(start.X, start.Y, start.Z); XYZ newEnd = new XYZ(start.X, end.Y, end.Z); MessageBox.Show("newStart: " + newStart.ToString() + Environment.NewLine + " newEnd: " + newEnd.ToString()); Line newLine = Line.CreateBound(newStart, newEnd); // *** fails on this line *** // "The curve is unbound or not coincident with the original one of the datum plane" grid.SetCurveInView(DatumExtentType.Model, view, newLine); } tx.Commit(); } pstrMsg = lstrMsg; return Result.Succeeded; }
I am not asking you to debug for me, but I am not able to interpret the exception message. Thanks for any advice. Dale