BIM Software Tips: How to Extract Axis Information in Revit
Are you looking to extract information about grids in the current Revit view, such as their names, elevations, and coordinates?
This is a common scenario in Revit programming—locating target objects and retrieving their relevant data.
To find the target objects, you need to utilize Revit’s filtering system. The core class for this purpose is the FilteredElementCollector, which allows you to specify filtering criteria and collect elements that match those conditions.
Once you have these elements, you can access their properties, parameter values, and position information via the Element.Location property.
Below is an example demonstrating how to retrieve such information in Revit:
[Transaction(TransactionMode.Manual)]
public class GetAllGrids : IExternalCommand
{
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
UIApplication uiApp = commandData.Application;
Application app = uiApp.Application;
UIDocument uiDoc = uiApp.ActiveUIDocument;
Document doc = uiDoc.Document;
// Collect all grid elements in the active view
FilteredElementCollector collector = new FilteredElementCollector(doc, doc.ActiveView.Id);
collector.OfClass(typeof(Grid));
string sInfo = string.Empty;
foreach (Element elem in collector)
{
sInfo += “Name = ” + elem.Name + “; “;
Grid grid = elem as Grid;
LocationCurve locCurve = grid.Location as LocationCurve;
Curve cur = locCurve.Curve;
XYZ ptStart = cur.GetEndPoint(0);
XYZ ptEnd = cur.GetEndPoint(1);
// Additional information like coordinates can be processed here
}
TaskDialog.Show(“Grid Information”, sInfo);
return Result.Succeeded;
}
}














Must log in before commenting!
Sign Up