public void createGrossSchedule(String name, String fileName, Document doc) { ViewSchedule schedule = new FilteredElementCollector(doc).OfClass(typeof(ViewSchedule)).Where(x => x.Name == name + " Schedule").FirstOrDefault() as ViewSchedule; ViewScheduleExportOptions opt = new ViewScheduleExportOptions(); opt.FieldDelimiter = ","; opt.Title = false; string path = _export_folder_name; if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } string file = System.IO.Path.GetFileNameWithoutExtension(fileName) + ".csv"; schedule.Export(path, file, opt); }
public void createCountSchedule(String name, ElementId elementId) { ViewSchedule schedule = new FilteredElementCollector(CachedDoc).OfClass(typeof(ViewSchedule)).Where(x => x.Name == name + " Schedule").FirstOrDefault() as ViewSchedule; if (schedule == null) { Transaction tSchedule = new Transaction(CachedDoc, "Create Schedule"); tSchedule.Start(); //Create an empty view schedule for doors. //schedule = ViewSchedule.CreateSchedule(CachedDoc, new ElementId(BuiltInCategory.INVALID), ElementId.InvalidElementId); schedule = ViewSchedule.CreateSchedule(CachedDoc, elementId, ElementId.InvalidElementId); schedule.Name = name + " Schedule"; ElementId keynoteId = new ElementId(BuiltInParameter.KEYNOTE_PARAM); //Iterate all the schedulable fields gotten from the doors view schedule. foreach (SchedulableField schedulableField in schedule.Definition.GetSchedulableFields()) { //See if the FieldType is ScheduleFieldType.Instance. if (schedulableField.FieldType == ScheduleFieldType.Count || schedulableField.ParameterId == keynoteId) { //Get ParameterId of SchedulableField. ElementId parameterId = schedulableField.ParameterId; //Add a new schedule field to the view schedule by using the SchedulableField as argument of AddField method of Autodesk.Revit.DB.ScheduleDefinition class. ScheduleField field = schedule.Definition.AddField(schedulableField); //See if the parameterId is a BuiltInParameter. if (Enum.IsDefined(typeof(BuiltInParameter), parameterId.IntegerValue)) { BuiltInParameter bip = (BuiltInParameter)parameterId.IntegerValue; //Get the StorageType of BuiltInParameter. Autodesk.Revit.DB.StorageType st = CachedDoc.get_TypeOfStorage(bip); //if StorageType is String or ElementId, set GridColumnWidth of schedule field to three times of current GridColumnWidth. //And set HorizontalAlignment property to left. if (st == Autodesk.Revit.DB.StorageType.String || st == Autodesk.Revit.DB.StorageType.ElementId) { field.GridColumnWidth = 3 * field.GridColumnWidth; field.HorizontalAlignment = ScheduleHorizontalAlignment.Left; } //For other StorageTypes, set HorizontalAlignment property to center. else { field.HorizontalAlignment = ScheduleHorizontalAlignment.Center; } } if (field.ParameterId == keynoteId) { ScheduleSortGroupField sortGroupField = new ScheduleSortGroupField(field.FieldId); schedule.Definition.AddSortGroupField(sortGroupField); schedule.Definition.IsItemized = false; } if (schedulableField.FieldType == ScheduleFieldType.Count) { } } } tSchedule.Commit(); tSchedule.Dispose(); } else { schedule.RefreshData(); } ViewScheduleExportOptions opt = new ViewScheduleExportOptions(); opt.FieldDelimiter = ","; opt.Title = false; string path = _export_folder_name; if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } string file = System.IO.Path.GetFileNameWithoutExtension(name) + ".csv"; schedule.Export(path, file, opt); }
public void createMaterialTakeOffSchedule(String name, ElementId elementId) { //Get UIDocument UIDocument uidoc = _cachedCmdData.Application.ActiveUIDocument; //Get Document Document doc = uidoc.Document; ViewSchedule schedule = new FilteredElementCollector(CachedDoc).OfClass(typeof(ViewSchedule)).Where(x => x.Name == name + " Schedule").FirstOrDefault() as ViewSchedule; if (schedule == null) { Transaction tSchedule = new Transaction(CachedDoc, "Create Schedule"); tSchedule.Start(); //Create an empty view schedule for doors. schedule = ViewSchedule.CreateMaterialTakeoff(CachedDoc, elementId); schedule.Name = name + " Schedule"; ElementId volumeId = new ElementId(BuiltInParameter.MATERIAL_VOLUME); ElementId areaId = new ElementId(BuiltInParameter.MATERIAL_AREA); //Iterate all the schedulable fields gotten from the doors view schedule. foreach (SchedulableField schedulableField in schedule.Definition.GetSchedulableFields()) { //See if the FieldType is ScheduleFieldType.Instance. if (schedulableField.ParameterId == volumeId || schedulableField.ParameterId == areaId || schedulableField.GetName(doc).Equals("Material: Keynote")) { //Get ParameterId of SchedulableField. ElementId parameterId = schedulableField.ParameterId; //Add a new schedule field to the view schedule by using the SchedulableField as argument of AddField method of Autodesk.Revit.DB.ScheduleDefinition class. ScheduleField field = schedule.Definition.AddField(schedulableField); //See if the parameterId is a BuiltInParameter. if (Enum.IsDefined(typeof(BuiltInParameter), parameterId.IntegerValue)) { BuiltInParameter bip = (BuiltInParameter)parameterId.IntegerValue; //Get the StorageType of BuiltInParameter. Autodesk.Revit.DB.StorageType st = CachedDoc.get_TypeOfStorage(bip); //if StorageType is String or ElementId, set GridColumnWidth of schedule field to three times of current GridColumnWidth. //And set HorizontalAlignment property to left. if (st == Autodesk.Revit.DB.StorageType.String || st == Autodesk.Revit.DB.StorageType.ElementId) { field.GridColumnWidth = 3 * field.GridColumnWidth; field.HorizontalAlignment = ScheduleHorizontalAlignment.Left; } //For other StorageTypes, set HorizontalAlignment property to center. else { field.HorizontalAlignment = ScheduleHorizontalAlignment.Center; } } if (schedulableField.GetName(doc).Equals("Material: Keynote")) { ScheduleSortGroupField sortGroupField = new ScheduleSortGroupField(field.FieldId); schedule.Definition.AddSortGroupField(sortGroupField); schedule.Definition.IsItemized = false; } if (field.ParameterId == volumeId) { FormatOptions formatOpt = new FormatOptions(DisplayUnitType.DUT_CUBIC_FEET, UnitSymbolType.UST_CF, 0.01); formatOpt.UseDefault = false; field.SetFormatOptions(formatOpt); field.DisplayType = ScheduleFieldDisplayType.Totals; } if (field.ParameterId == areaId) { FormatOptions formatOpt = new FormatOptions(DisplayUnitType.DUT_SQUARE_FEET, UnitSymbolType.UST_SF, 0.01); formatOpt.UseDefault = false; field.SetFormatOptions(formatOpt); field.DisplayType = ScheduleFieldDisplayType.Totals; } } } tSchedule.Commit(); tSchedule.Dispose(); } else { schedule.RefreshData(); } ViewScheduleExportOptions opt = new ViewScheduleExportOptions(); opt.FieldDelimiter = ","; opt.Title = false; string path = _export_folder_name; if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } string file = System.IO.Path.GetFileNameWithoutExtension(name) + ".csv"; schedule.Export(path, file, opt); }