private void OnAppInitalized(object sender, ApplicationInitializedEventArgs e) { Autodesk.Revit.ApplicationServices.Application app = sender as Autodesk.Revit.ApplicationServices.Application; uiApp = new UIApplication(app); }
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { UIApplication uiApp = commandData.Application; Autodesk.Revit.ApplicationServices.Application app = uiApp.Application; Document document = uiApp.ActiveUIDocument.Document; Selection sel = uiApp.ActiveUIDocument.Selection; Transaction trans = new Transaction(document, "过滤获取当前视图中的轴网信息"); trans.Start(); FilteredElementCollector collector = new FilteredElementCollector(document, document.ActiveView.Id);// collector.OfClass(typeof(Grid)); string sInfo = null; foreach (Element elem in collector) { sInfo += "Name = " + elem.Name + ";"; Grid grid = elem as Grid; LocationCurve locCurve = grid.Location as LocationCurve; if (locCurve != null) { Curve cur = locCurve.Curve; XYZ ptStart = cur.GetEndPoint(0); XYZ ptEnd = cur.GetEndPoint(1); } } TaskDialog.Show("Grid message", sInfo); trans.Commit(); return(Result.Succeeded); }