RevitAPI: Document.ExportImage exports some .jpg files when setting ImageFileType set to PNG

中文链接

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?

Exported_result

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,
};

 


Comments

2 responses to “RevitAPI: Document.ExportImage exports some .jpg files when setting ImageFileType set to PNG”

  1. Really, good read
    thanks

  2. Hi,
    Thanks for the post!
    I can see that this will help in my workflow.
    but i am new to C# and programming.
    I had managed to complete the building “my 1st revit plugin” by autodesk.
    but i don’t understand. most of these code.
    and don’t you need to import the API into the code?
    can anyone explain or able to point me to the right direction?
    thanks

Leave a Reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading