- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I'm using this code in my addin to automatically create and export a Door Schedule:
I need more information in my Schedule, so I am adding a few custom parameters to store the values that I need.
The 'custom' parameters that I populate are the following:
FromRoom and ToRoom Name, Number and Location
ElementId
UniqueId
TypeMark
Question:
How can I include the Room parameter values when I create the schedule?
Code:
ViewSchedule schedule = new FilteredElementCollector(doc).OfClass(typeof(ViewSchedule)).Where(x => x.Name == "Sample Door Schedule").FirstOrDefault() as ViewSchedule;
if (schedule == null)
{
Transaction tSchedule = new Transaction(doc, "Create Schedule");
tSchedule.Start();
//Create an empty view schedule for doors.
schedule = ViewSchedule.CreateSchedule(doc, new ElementId(BuiltInCategory.OST_Doors), ElementId.InvalidElementId);
schedule.Name = "Sample Door Schedule";
//Iterate all the schedulable fields gotten from the doors view schedule.
foreach (SchedulableField schedulableField in schedule.Definition.GetSchedulableFields())
{
//Seeif the FieldType is ScheduleFieldType.Instance.
if (schedulableField.FieldType == ScheduleFieldType.Instance)
{
//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 = doc.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;
}
}
}
}
tSchedule.Commit();
tSchedule.Dispose();
}
else
{
schedule.RefreshData();
}
opt.FieldDelimiter = "\t";
opt.Title = false;
string path = GlobalVar.folder_application + "\\Schedules";
if (!Directory.Exists(path))
Directory.CreateDirectory(path);
string file = System.IO.Path.GetFileNameWithoutExtension(doc.PathName) + ".csv";
schedule.Export(path, file, opt);
//UIApplication uiapp = GlobalVar.ThisApplication;
//UIDocument uidoc = uiapp.ActiveUIDocument;
//uidoc.ActiveView = schedule;
//Show the schedule in Excel
GlobalVar.StartDoc(path + "\\" + file);
}
Solved! Go to Solution.