public static View CreateFloorCallout(Document doc, List <View> views, string level, BoundingBoxXYZ bb, string viewName, double offset) { ViewFamilyType vft = new FilteredElementCollector(doc).OfClass(typeof(ViewFamilyType)) .Cast <ViewFamilyType>().FirstOrDefault <ViewFamilyType>(x => ViewFamily.FloorPlan == x.ViewFamily); XYZ max = GeomUtil.OffsetPoint(GeomUtil.OffsetPoint(GeomUtil.OffsetPoint(bb.Max, XYZ.BasisX, offset), XYZ.BasisY, offset), XYZ.BasisZ, offset); XYZ min = GeomUtil.OffsetPoint(GeomUtil.OffsetPoint(GeomUtil.OffsetPoint(bb.Min, -XYZ.BasisX, offset), -XYZ.BasisY, offset), -XYZ.BasisZ, offset); bb = new BoundingBoxXYZ { Max = max, Min = min }; View pv = null; string s = string.Empty; bool check = false; foreach (View v in views) { try { s = v.LookupParameter("Associated Level").AsString(); if (s == level) { pv = v; check = true; break; } } catch { continue; } } if (!check) { throw new Exception("Invalid level name!"); } View vs = ViewSection.CreateCallout(doc, pv.Id, vft.Id, min, max); vs.CropBox = bb; vs.Name = viewName; return(vs); }
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { UIApplication uiApp = commandData.Application; Application app = uiApp.Application; Document document = uiApp.ActiveUIDocument.Document; Selection sel = uiApp.ActiveUIDocument.Selection; UIDocument uiDoc = commandData.Application.ActiveUIDocument; Transaction trans = new Transaction(document, "创建索引详图"); trans.Start(); #region 方案一 XYZ p1 = sel.PickPoint(); XYZ p2 = sel.PickPoint(); //创建新视图所需要的ViewFamilyType的Id ElementId viewTypeId = document.ActiveView.GetTypeId(); //获得当前视图即为父视图ElementId View view = ViewSection.CreateCallout(document, document.ActiveView.Id, viewTypeId, p1, p2); //ViewPlan detViewPlan = ViewSection.CreateCallout(document, document.ActiveView.Id, viewTypeId, p1, p2) as ViewPlan; #endregion trans.Commit(); //document.ActiveView = view; uiDoc.ActiveView = view; //增加删除刚才创建的索引详图功能??? //导出索引详图视图截图 ImageExportOptions options = new ImageExportOptions(); options.ZoomType = ZoomFitType.FitToPage; options.ExportRange = ExportRange.CurrentView; options.FilePath = @"C:\Users\Administrator.WIN7U-20141230O\Desktop\map\CurrentViewImage";//命名需要修改,不然每次重复替换 options.FitDirection = FitDirectionType.Horizontal; options.HLRandWFViewsFileType = ImageFileType.JPEGMedium; options.ShadowViewsFileType = ImageFileType.JPEGMedium; options.PixelSize = 1920; commandData.Application.ActiveUIDocument.Document.ExportImage(options); #region 切换三维视图(未成功,可能版本问题) // Transaction tr = new Transaction(document, "切换三维视图"); // tr.Start(); // // 找到一个三维视图类型 // IEnumerable<ViewFamilyType> viewFamilyTypes = // from elem in new FilteredElementCollector(document).OfClass(typeof (ViewFamilyType)) // let type = elem as ViewFamilyType // where type.ViewFamily = ViewFamily.ThreeDimensional // select type; // //创建三维视图 // View3D view3D = View3D.CreatePerspective(document, viewFamilyTypes.First().Id); // tr.Commit(); // uiDoc.ActiveView = view3D; #endregion return(Result.Succeeded); }