前言
這個例子介紹 Revit 的配電盤明細表,PanelSchedule。Revit 的電器專業在國內用的并不是十分廣泛,但從功能上來說還是比較完整的。
內容
這個例子里有三個命令:
- PanelScheduleExport - 導出配電盤明細表
- InstanceViewCreation - 創建配電盤明細表
- SheetImport - 在圖紙中導入配電盤明細表
PanelScheduleExport
用于導出的配電盤明細表:
導出到 Excel:
主要用到的 Revit API:
通過 GetSectionData 可以獲取配電盤明細表里各個分區的內容
// public class PanelScheduleView : TableView
public TableSectionData GetSectionData(SectionType sectionType);
一個配電盤明細表可以有的分區類型:
頭Header、體Body、總結Symmary、尾Footer
namespace Autodesk.Revit.DB
{public enum SectionType{None = -1,Header = 0,Body = 1,Summary = 2,Footer = 3}
}
從 TableSectionData
可以獲取對應的行列:
TableSectionData sectionData = psView.GetSectionData(sectionType);
nRows = sectionData.NumberOfRows;
nCols = sectionData.NumberOfColumns;
通過 GetCellText 可以獲取對應的配電盤明細表的內容:
// public class TableView : View
public string GetCellText(SectionType sectionType, int row, int column);
InstanceViewCreation
選中一個配電盤 Panel,通過 CreateInstanceView
創建一個配電盤明細表:
// public class PanelScheduleView : TableView
public static PanelScheduleView CreateInstanceView(Document ADoc, ElementId panelId);
SheetImport
通過 PanelScheduleSheetInstance::Create
在圖紙上放置配電盤明細表:
// public class PanelScheduleSheetInstance : Element
public static PanelScheduleSheetInstance Create(Document ADoc, ElementId scheduleId, View DBView);
為了將多個明細表放在同一行,計算了各個表的起始位置:
XYZ nextOrigin = new XYZ(0.0, 0.0, 0.0);
foreach (Element element in psViews)
{PanelScheduleView psView = element as PanelScheduleView;if (psView.IsPanelScheduleTemplate()){// ignore the PanelScheduleView instance which is a template.continue;}PanelScheduleSheetInstance onSheet = PanelScheduleSheetInstance.Create(doc, psView.Id, sheet);onSheet.Origin = nextOrigin;BoundingBoxXYZ bbox = onSheet.get_BoundingBox(doc.ActiveView);double width = bbox.Max.X - bbox.Min.X;nextOrigin = new XYZ(onSheet.Origin.X + width, onSheet.Origin.Y, onSheet.Origin.Z);
}