中文链接
By Aaron Lu
Image export feature is available in RevitAPI, that is: Document.ExportImage method, a real example is:
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());
}
}
This program can export all the exportable views into .png file.
In general, there is no problem, but for some special revit files, it will export some .jpg files as well, why that happens even if we set the exporting format to .png using HLRandWFViewsFileType = ImageFileType.PNG?
The reason is: ImageExportOptions has different settings for two types of views: (1) hidden line and wireframe (HLRandWFViewsFileType property) and (2) shadow views (ShadowViewsFileType property), so we have to set ShadowViewsFileType to .png as well, then the problem got solved
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,
};