danrodi
danrodi

Reputation: 296

Exporting image in Revit API

I'm trying to export the image of a selected object in Revit. When a button is clicked, the following method is being run:

public void createPreviewImage(ExternalCommandData commandData)
{
     TaskDialog.Show("Notification", "Starting creation of preview image.");

     UIDocument uidoc = commandData.Application.ActiveUIDocument;
     Document doc = uidoc.Document;

     var opt = new ImageExportOptions
     {
          ZoomType = ZoomFitType.FitToPage,
          PixelSize = 128,
          FilePath = "C:/Users/Dan/Desktop",
          FitDirection = FitDirectionType.Horizontal,
          HLRandWFViewsFileType = ImageFileType.JPEGLossless,
          ImageResolution = ImageResolution.DPI_600,
      };

      doc.ExportImage(opt);

      TaskDialog.Show("Notification", "Preview image created!");
}

Although the IDE does not give any errors on compilation and the task dialogs are shown when the method is run, then the exported image is not created on the desktop. Is the problem somewhere in the code or does the export of an image work differently?

Upvotes: 1

Views: 2042

Answers (2)

mustafa.salaheldin
mustafa.salaheldin

Reputation: 73

Fist, you will find the exported image in the "Dan" folder, this image will be named "desktop.jpg".

Secondly, you have to add the file name and extension to the file path, however the API will concatenate the view type and the view name to the file path you already defined.

Upvotes: 0

DomCR
DomCR

Reputation: 573

Your code is correct, but the FilePath is incomplete.

FilePath = "C:/Users/Dan/Desktop/somefilename.jpg"

Upvotes: 2

Related Questions