I'm trying to retrieve the curve property of a grid object in my Revit 2016 document, but somehow it's not working. When I debug my code VS tells me grid.Curve is null. But I can't figure out why.
I've based my code on this example: https://knowledge.autodesk.com/search-result/caas/CloudHelp/cloudhelp/2016/ENU/Revit-API/files/GUID-...
foreach (Grid gridinstance in xxGrids) { if (gridinstance.IsCurved) { Arc arc = gridinstance.Curve as Arc; } else { Line line = gridinstance.Curve as Line; } }
xxGrids in this case is a list of Grid objects and is populated with some orthogonal grid objects. The IsCurved property of all of them is false, so I should be able to retrieve a line object based on the grid.Curve property but this is always null.
When I use the snoop current selection tool I can see that the curve property is an actual line with endpoint coordinates and more. Why can't I retrieve this via code?
Anybody any thought on this?
Thanks in advance..
After some additional testing I've narrowed the problem down to the actual creation of the grid elements, in my case the grid elements are created in my code with a method which basically accepts 2 lists of XYZ's which represent the start and endpoints of the grid element:
public static void CreateGridElements(Document document, List<XYZ> startPoints, List<XYZ> endPoints) { if (startPoints.Count == endPoints.Count)
{
for (int i = 0; i < startPoints.Count; i++)
{
Line line = Line.CreateBound(startPoints[i], endPoints[i]);
Grid grid = Grid.Create(document, line);
}
}
}
Whenever I've created a gridelement with this method, I'm unable to retrieve the Curve property of the grid element. When I created a grid element via the normal Revit UI it does work. Is there somehow a difference between grid elements which are created through API or UI?