public class CreatFloorSurface : IExternalCommand { public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { UIDocument uidoc = commandData.Application.ActiveUIDocument;
Document doc = uidoc.Document;
List<Element> floorList = FloorList(doc); TaskDialog.Show("1", floorList.Count().ToString()); return Result.Succeeded; } public List<Element> FloorList(Document doc) {FilteredElementCollector collector = new FilteredElementCollector(doc);
//方法一
List<Element> floorList = collector.OfCategory(BuiltInCategory.OST_Floors).OfClass(typeof(FloorType)).ToList();
//floorType 可以换成ElementType,不能换成familySymbol.
//方法二
//List<Element> floorList = collector.OfCategory(BuiltInCategory.OST_Floors).WhereElementIsElementType().ToList();
此处不能用Ilist<Element> floorList =collector.OfCategory(BuiltInCategory.OST_Floors).WhereElementIsElementType().ToElements();
return floorList; }