24 May 2021
Design Automation for Revit 2022 now support exporting to PDF directly
Today, the great news is Revit Design Automation now support exporting to PDF directly starting from Revit engine 2022. Check out the release note.
Some background information, we got requests from our developers from time to time who are trying to export PDF files from Revit Design Automation, but due to some limitation, this can not be achieved directly by previous Revit Design Automation engine, the way to export Dwgs from Revit first, and then from Dwg to Pdf is usually suggested as a workaround of "Rvt->Dwgs->Pdfs". But with the latest improvement, this could be just a simple export on Revit Design Automation as you can do with Revit Desktop, the main code snippets as follow:
private static bool ExportingPdf(Document doc)
{
using (Transaction tx = new Transaction(doc))
{
tx.Start("Export PDF");
List<View> views = new FilteredElementCollector(doc)
.OfClass(typeof(View))
.Cast<View>()
.Where(vw =>
vw.ViewType == ViewType.DrawingSheet && !vw.IsTemplate
).ToList();
IList<ElementId> viewIds = new List<ElementId>();
foreach (View view in views)
{
ViewSheet viewSheet = view as ViewSheet;
viewIds.Add(viewSheet.Id);
}
if (0 < views.Count)
{
PDFExportOptions options = new PDFExportOptions();
options.FileName = "result";
options.Combine = true;
string workingFolder = Directory.GetCurrentDirectory();
doc.Export(workingFolder, viewIds, options);
}
tx.RollBack();
}
return true;
}