RevitAPI: Document.ExportImage匯出檔案格式並不都是.png,即便設定了HLRandWFViewsFileType為ImageFileType.PNG
阿新 • • 發佈:2019-01-22
RevitAPI有匯出圖片的功能,那就是使用Document.ExportImage方法,一個實際的例子如下
執行該程式會把所有支援匯出的檢視都匯出為.PNG檔案。FilteredElementCollector FEC_Views = new FilteredElementCollector(OpenDoc).OfClass(typeof(View)); FEC_Views.OfCategory(BuiltInCategory.OST_Views); StringBuilder sb = new StringBuilder(); foreach (View View in FEC_Views) { if (View.IsTemplate) continue; IList<ElementId> ImageExportList = new List<ElementId>(); ImageExportList.Clear(); ImageExportList.Add(View.Id); var NewViewName = View.Name.ToString().Replace(".", "-"); var BilledeExportOptions_3D_PNG = new ImageExportOptions { ZoomType = ZoomFitType.FitToPage, PixelSize = 2024, FilePath = ParentFolder + @"\" + NewViewName, FitDirection = FitDirectionType.Horizontal, HLRandWFViewsFileType = ImageFileType.PNG, ImageResolution = ImageResolution.DPI_600, ExportRange = ExportRange.SetOfViews, }; BilledeExportOptions_3D_PNG.SetViewsAndSheets(ImageExportList); try { OpenDoc.ExportImage(BilledeExportOptions_3D_PNG); } catch (Exception ex) { sb.AppendLine(View.Id.ToString()); sb.AppendLine(ex.ToString()); } }
一般情況下,都能正確按照期望匯出。但是,有些檔案卻匯出了一些.JPG檔案,不是已經通過HLRandWFViewsFileType = ImageFileType.PNG設定好了匯出格式是PNG嗎?
原來格式設定包含兩方面:1.隱藏線和線框設定,通過HLRandWFViewsFileType 2.陰影設定,通過ShadowViewsFileType。
那麼改進的方法就是把ShadowViewsFileType也設定成.PNG:
var BilledeExportOptions_3D_PNG = new ImageExportOptions { ZoomType = ZoomFitType.FitToPage, PixelSize = 2024, FilePath = ParentFolder + @"\" + NewViewName, FitDirection = FitDirectionType.Horizontal, HLRandWFViewsFileType = ImageFileType.PNG, ShadowViewsFileType = ImageFileType.PNG, ImageResolution = ImageResolution.DPI_600, ExportRange = ExportRange.SetOfViews, };