Export PDF in Revit 2022 - Quick Example

I wanted to share this quick graph that enables you to export PDF’s in Revit 2022. I can’t believe just how easy it is now.

#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.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

Export PDF Revit 2022.dyn (11.9 KB)

24 Likes

Hi Sean,
That looks really easy!
How come there is no print setting needed?

There are several setting you can set with the opts like Unreferenced Views, Blue Callouts etc, you just got to set them, but this basic example just uses the current project settings.

Hi Sean thanks for your response, I should have said paper sizes…

How are sheets exported as pdf without determining what paper size to use in the printer? :slight_smile:

I edited the Python above to include the option for PaperFormat which you can set for Default and it will use the TitleBlock size for sheet size, or defaults to Letter if one isn’t available. You can also use sheet names like ARCH_E1 or ISO_A2 etc.

Awesome!! very nice :slight_smile:

1 Like

Here is a better list of the majority of options available.

opts.ColorDepth = ColorDepthType.Color
opts.Combine = False
opts.ExportQuality = PDFExportQualityType.DPI600
opts.HideCropBoundaries = True
#This will use the TitleBlock size to create the sheet size
opts.PaperFormat = ExportPaperFormat.Default
#This will use a specific size for every view exported
opts.PaperFormat = ExportPaperFormat.ARCH_E1
opts.HideReferencePlane = True
opts.HideScopeBoxes = True
opts.HideUnreferencedViewTags = True
opts.MaskCoincidentLines = True
#Don't think of this as a "continue" but rather as a silent mode
opts.StopOnError = True
#Make sure to not use these settings as they don't work if 'Default' size is used above
opts.PaperPlacement = PaperPlacementType.LowerLeft
#Make sure to not use these settings as they don't work if 'Default' size is used above
opts.ZoomType = ZoomType.Zoom
#Make sure to not use these settings as they don't work if 'Default' size is used above
opts.ZoomPercentage = 100
opts.ViewLinksInBlue = False
6 Likes

And update to this is that with Hotfix 2022.0.1 now allows you to set some of these options while using Default for PaperFormat without breaking the method.

2022.0.1 Hotfix | Revit Products 2022 | Autodesk Knowledge Network

1 Like

[quote=“erfajo, post:8, topic:62697”]
There is also the option to use this set of nodes, revealed in the Orchid package…

erfajo.blogspot.com

PDF export nodes

[/quote]That looks like a very useful image of how those nodes are used. However, the original image is missing. Anybody got a backup or a new reference to the use of PDFexport.ByViewSheetSetin Orchard?

1 Like

Thanks for those. opts.Combine = True does not combine all the Views into one PDF?

I am doing this as a workaround:

1 Like

I believe it is dependent on the other settings you use as well including how you group the sheets and names together. Base on this link, I think in order to use this you have to use the naming rules set up. You can also manipulate these in python / dynamo as well.

Hmm, I’d assume it was as easy as checking the box in the print setup. Can you make opts.Combine = True work?

Hi,

The Export PDF node of the Genius Loci package includes this option.
This is indeed more complicated than

(And it doesn’t appear fully logical to me)

1 Like

Here is a working example.
The main idea is that you have to Export them as a single collection, not individual ones.

#Sean Page, 2022
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])
Folder = IN[1]
result = []
sheets = List[ElementId]([x.Id for x in Sheets])

opts = PDFExportOptions()
opts.Combine = True
opts.FileName = "test"
rules = opts.GetNamingRule();
rules.Clear()

NumRule = TableCellCombinedParameterData.Create()
NumRule.CategoryId = ElementId(BuiltInCategory.OST_Sheets)
NumRule.ParamId = ElementId(BuiltInParameter.SHEET_NUMBER)
NumRule.Separator = " - "
rules.Add(NumRule)

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


OUT = doc.Export(Folder,sheets,opts)

image

5 Likes


how to resolve this error

Hello,
works only on Revit 2022 and higher

1 Like

is there any solution for revit 2021?
i am trying to export sheets as pdf in black and white except the logos along with file name containing “Sheet name - Revsion - Sheet NUmber”
i have modified the script but shows a error.
could someone help me with its solution?
Export PDF Revit.dyn (16.6 KB)
image

There are some example in forum with PDF printer (as PDF Creator)

https://forum.dynamobim.com/search?q=PDF%20Creator

I’m a very serious diroots fanboy, so I have to give their batch-pdf creator a shout-out here.

It’s free on the autodesk app store. Check it out if you don’t have it. MUST HAVE!!!

Can i get the name of Naming rules??