5月 24, 2021

Design Automation for Revit 2022 now support exporting to PDF directly

Follow @JohnOnSoftware

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

 

Posted by

Developer Advocate

Zhong Wu started his career in Autodesk since 2006 on AutoCAD Architecture as a software developer with more than 6 years working experience. After that, Zhong moved to Autodesk Development Network(now is renamed to Forge Partner Development) team as a Developer Advocate mainly focus on the API support/consultant for Maya/MotionBuilder, and started to contribute in Forge evangelism and support with the growing of...

Related Posts