// 遍历标高 [Transaction(TransactionMode.Manual)][Regeneration(RegenerationOption.Manual)] // [Journaling(JournalingMode.NoCommandData)] public class cmdGetLevel : IExternalCommand{ public Result Execute(ExternalCommandData cmdData, ref string message, ElementSet elements) { UIDocument uiDoc = cmdData.Application.ActiveUIDocument; Selection selection = uiDoc.Selection; Transaction ts = new Transaction(uiDoc.Document, " level " ); ts.Start(); FilteredElementCollector collector = new FilteredElementCollector(uiDoc.Document); ICollection < Element > collection = collector.OfClass( typeof (Level)).ToElements(); foreach (Element e in collection) { TaskDialog.Show( " 标高 " , e.Name); } ts.Commit(); return Result.Succeeded; }}