前言
这个例子介绍如何创建明细表。明细表相关介绍:Revit API:明细表ViewSchedule
内容
创建明细表 Command 的主要逻辑:
UIDocument uiDocument = commandData.Application.ActiveUIDocument;
ScheduleCreationUtility utility = new ScheduleCreationUtility();
utility.CreateAndAddSchedules(uiDocument);
ScheduleCreationUtility
CreateAndAddSchedules
调用了 CreateSchedules
和 AddScheduleToNewSheet
。
public void CreateAndAddSchedules(UIDocument uiDocument)
{
TransactionGroup tGroup = new TransactionGroup(uiDocument.Document, "Create schedules and sheets");
tGroup.Start();
ICollection<ViewSchedule> schedules = CreateSchedules(uiDocument);
foreach (ViewSchedule schedule in schedules)
{
AddScheduleToNewSheet(uiDocument.Document, schedule);
}
tGroup.Assimilate();
}
CreateSchedules
创建明细表。
明细表的创建:
ViewSchedule schedule = ViewSchedule.CreateSchedule(document, new ElementId(BuiltInCategory.OST_Walls), ElementId.InvalidElementId);
schedule.Name = "Wall Schedule 1";
从明细表中获取内容 field:
SchedulableField schedulableField in schedule.Definition.GetSchedulableFields()
增加 field及相关过滤器:
ScheduleField field = schedule.Definition.AddField(schedulableField);
double volumeFilterInCubicFt = 0.8 * Math.Pow(3.2808399, 3.0);
ScheduleFilter filter = new ScheduleFilter(field.FieldId, ScheduleFilterType.GreaterThan, volumeFilterInCubicFt);
schedule.Definition.AddFilter(filter);
ScheduleSortGroupField sortGroupField = new ScheduleSortGroupField(field.FieldId);
sortGroupField.ShowHeader = true;
schedule.Definition.AddSortGroupField(sortGroupField);
AddScheduleToNewSheet
把明细表放到图纸上。
//创建图纸
ViewSheet newSheet = ViewSheet.Create(document, titleBlockId);
newSheet.Name = "Sheet for " + schedule.Name;
document.Regenerate();
// 在图纸上放置一个明细表
XYZ upperLeft = new XYZ(); // 放置在图纸上的位置
ScheduleSheetInstance placedInstance = ScheduleSheetInstance.Create(document, newSheet.Id, schedule.Id, upperLeft);