1)读取所有视图:
public static ViewSet GetAllViews(Document doc) { ViewSet views = new ViewSet(); FilteredElementCollector collector = new FilteredElementCollector(doc); FilteredElementIterator it = collector.OfClass(typeof(View)).GetElementIterator(); it.Reset(); while (it.MoveNext()) { View view = it.Current as View3D; if (null != view && !view.IsTemplate && view.CanBePrinted) { views.Insert(view); } else if (null == view) { View view2D = it.Current as View; if (view2D.ViewType == ViewType.FloorPlan | view2D.ViewType == ViewType.CeilingPlan | view2D.ViewType == ViewType.AreaPlan | view2D.ViewType == ViewType.Elevation | view2D.ViewType == ViewType.Section) { views.Insert(view2D); } } } return views; }
2)读取视图的名称:
public static string GetViewDisplayName(View view) { String name = view.ViewName; //special treament to sheet name if (view.ViewType == ViewType.DrawingSheet) { ViewSheet sheet = view as ViewSheet; name = String.Format("{0} - {1}", sheet.SheetNumber, name); } if(view.ViewType == ViewType.ThreeD) { if (name.Contains("{")&&name.Contains("}")) { int bracketStart = name.IndexOf("{"); int bracketEnd = name.IndexOf("}"); name = name.Substring(bracketStart + 1, bracketEnd - bracketStart - 1); } } else if(view.ViewType == ViewType.FloorPlan) { name = string.Format("楼层平面:{0}", name); } else if (view.ViewType == ViewType.CeilingPlan) { name = string.Format("天花板平面:{0}", name); } else if (view.ViewType == ViewType.AreaPlan) { name = string.Format("面积平面:{0}", name); } else if (view.ViewType == ViewType.Elevation) { name = string.Format("建筑立面:{0}", name); } else if (view.ViewType == ViewType.Section) { name = string.Format("建筑剖面:{0}", name); } return name; }