转载请复制以下信息:
原文链接: http://blog.csdn.net/joexiongjin/article/details/7564984
作者: 叶雄进 , Autodesk ADN
2012.5.14
创建明细表是Revit2013的一个比较重要的API功能增强点。可以用来创建明细表,
1。指定显示那个类别的对象;
2. 可以定制一个表中有那些列,列的宽度。
3. 也可以向明细表设置过滤器,选择那些对象可以在明细表中显示出来。
4. 明细表排序和分组。
下面代码段显示了如何创建一个房间明细表。代码摘自Revit 2013 SDK 中的ScheduleCreation 例子。
顺便说句: 你可以在这个页面下载到最新的Revit 2013 SDK,包含这个例子。 随产品发布的SDK不包含这个例子。
http://usa.autodesk.com/adsk/servlet/index?siteID=123112&id=2484975
private ICollection<ViewSchedule> CreateSchedules(UIDocument uiDocument) { Document document = uiDocument.Document; Transaction t = new Transaction(document, "Create Schedules"); t.Start(); List<ViewSchedule> schedules = new List<ViewSchedule>(); //Create an empty view schedule of wall category. ViewSchedule schedule = ViewSchedule.CreateSchedule(document, new ElementId(BuiltInCategory.OST_Walls), ElementId.InvalidElementId); schedule.Name = "Wall Schedule 1"; schedules.Add(schedule); //Iterate all the schedulable field gotten from the walls view schedule. foreach (SchedulableField schedulableField in schedule.Definition.GetSchedulableFields()) { //Judge if the FieldType is ScheduleFieldType.Instance. if (schedulableField.FieldType == ScheduleFieldType.Instance) { //Get ParameterId of SchedulableField. ElementId parameterId = schedulableField.ParameterId; //If the ParameterId is id of BuiltInParameter.ALL_MODEL_MARK then ignore next operation. if (ShouldSkip(parameterId)) continue; //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); //Judge if the parameterId is a BuiltInParameter. if (Enum.IsDefined(typeof(BuiltInParameter), parameterId.IntegerValue)) { BuiltInParameter bip = (BuiltInParameter)parameterId.IntegerValue; //Get the StorageType of BuiltInParameter. StorageType st = document.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 == StorageType.String || st == StorageType.ElementId) { field.GridColumnWidth = 3 * field.GridColumnWidth; field.HorizontalAlignment = ScheduleHorizontalAlignment.Left; } //For other StorageTypes, set HorizontalAlignment property to center. else { field.HorizontalAlignment = ScheduleHorizontalAlignment.Center; } } //Filter the view schedule by volume if (field.ParameterId == new ElementId(BuiltInParameter.HOST_VOLUME_COMPUTED)) { double volumeFilterInCubicFt = 0.8 * Math.Pow(3.2808399, 3.0); ScheduleFilter filter = new ScheduleFilter(field.FieldId, ScheduleFilterType.GreaterThan, volumeFilterInCubicFt); schedule.Definition.AddFilter(filter); } //Group and sort the view schedule by type if (field.ParameterId == new ElementId(BuiltInParameter.ELEM_TYPE_PARAM)) { ScheduleSortGroupField sortGroupField = new ScheduleSortGroupField(field.FieldId); sortGroupField.ShowHeader = true; schedule.Definition.AddSortGroupField(sortGroupField); } } } t.Commit(); uiDocument.ActiveView = schedule; return schedules; }