Export PDF in Revit 2022/2025 - Quick Example

Thanks for contributing!!! Great Work

1 Like

Hello. I ask you for help. I get this error: “Warning: IronPythonEvaluator.Error in operation EvaluateIronPythonScript.
Traceback (most recent call last):
File “”, line 26, in
NameError: name ‘PDFExportOptions’ is not defined”
I use Adobe Acrobat PDF
How do I solve it?

Sounds like maybe you are missing imports. Can you share the node / code entirely?

Export PDF Revit 2023 v2.dyn (12.3 KB)

Hi @SeanP, please can you adjust the python script in the first post, to just export a single sheet not a list of sheets? Thanks

Probably the quickest way would be to just make the single item coming in a List even if it’s only one item.

The List.Create node should get you there.

2 Likes

Yep that did it. Thanks!

1 Like

Hi @SeanP … firstly thanks so much for providing this, which has been in regular (and much appreciated) use since R2022 came out.
R2025 includes the option to PDF in the background, and I can’t see any reason not to have this as a default setting as it seems to be a bit of game-changer.
Do you know if this is possible? I have tried, but my extremely limited Python knowledge just returns endless failures :slightly_smiling_face:

PDFExportOptions.SetExportInBackground() ?

1 Like

Yes, this is 100% possible and I am already using it on my latest version of tools that we have.

opts = PDFExportOptions()
opts.SetExportInBackground(True)
doc.Export(path,viewIds,opts)
1 Like

Great news. Please excuse my Python ignorance (my initial attempt is returning errors)… how do I integrate this into the code from your original post?

1 Like

You should just be able to add this line in with the other options and if you’re in R25 it should work.

What error is it giving you?

opts.SetExportInBackground(True)

Amazing, it is now working. Thanks so much! :slightly_smiling_face:

Sorry @SeanP , it looks like I spoke too soon. It works when I send a single sheet, but when multiple sheets are sent it only PDF’s the first sheet in the list, then throws an error:

#Sean Page, 2021
import clr

clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *

clr.AddReference('System')
from System.Collections.Generic import List

clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.Elements)

clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager

doc = DocumentManager.Instance.CurrentDBDocument

Sheets = UnwrapElement(IN[0])
Names = IN[1]
Folder = IN[2]
result = []
sheets = List[ElementId]()

opts = PDFExportOptions()
#This will uses the Sheet Size for Paper size, or default to Letter
opts.SetExportInBackground(True)
opts.PaperFormat = ExportPaperFormat.Default
for sheet,name in zip(Sheets,Names):
	opts.FileName = name
	Sheet = List[ElementId]()
	Sheet.Add(sheet.Id)
	result.append(doc.Export(Folder,Sheet,opts))

OUT = result

Have you tried to do it with a list of one sheet? Everything looks like it should be working so I am wondering if there may be an issue with a file / sheet name or folder name?

Yes, it all works well if I feed a list of one sheet and one file name (each via a List.Create). It fails when I feed a list of multiple Views and Sheets directly (i.e. keeping the same list structure). It works both ways without opts.SetExportInBackground(True) added.

OK, I think what is probably happening is you are trying to send multiple print in background processes which isn’t going to be allowed. You should set the naming rules vs using string if you want to do it that way.

options = PDFExportOptions()
options.PaperFormat = ExportPaperFormat.Default
options.HideReferencePlane = True
options.HideScopeBoxes = True

rules = options.GetNamingRules()
rules.Clear()
NumberRule = TableCellCombinedParameterData.Create()
NumberRule.CategoryId = BuiltInCategory.OST_Sheets
NumberRule.ParamId = BuiltInParameter.SHEET_NUMBER
NumberRule.Separator = " - "
rules.Add(NumberRule)

NameRule = TableCellCombinedParameterData.Create()
NameRule.CategoryId = BuiltInCategory.OST_Sheets
NameRule.ParamId = BuiltInParameter.SHEET_NAME
NameRule.Separator = ""
rules.Add(NameRule)

#The above rules would give you something like this:
# A01.10 - FLOOR PLAN LEVEL 1

options.SetNamingRule(rules)

#This should be where "Sheets" is multiple view ids.
doc.Export(Folder,Sheets,options)

Please understand that I am simply taking your original code and blindly butchering it, having had no butchery training, and with the dullest of knives.
This is a much simplified graph from our office PDF writer, and has been prepared just for testing the PDF in background potential. In reality, our file naming convention is fairly complex, and can vary depending on a number of variables / parameters prior to being fed into your Python PDF writer as a list of sheets and corresponding file names.
I think you are suggesting that this process is no longer going to be possible if we are to take benefit of the background PDF option? I fear that trying to re-write the file naming process within the Python code will be too much of a challenge.

1 Like

Sounds like how I got my start, but back in my day all we had were flimsy plastic spoons…

3 Likes

:rofl: