import clr
clr.AddReference(‘System’)
from System.Collections.Generic import List
clr.AddReference(“RevitServices”)
import RevitServices
from RevitServices.Persistence import DocumentManager
Current doc/app/ui
doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
app = uiapp.Application
Get revit version
revit_version = int(app.VersionNumber)
Define list/unwrap list functions
def tolist(input):
result = input if isinstance(input, list) else [input]
return result
def uwlist(input):
result = input if isinstance(input, list) else [input]
return UnwrapElement(result)
Preparing input from dynamo to revit
directoryPath = IN[0]
sheets = uwlist(IN[1])
fileNames = tolist(IN[2])
options = IN[3]
If we are in Revit 2022 or higher, print
if revit_version > 2021:
# Import the references
clr.AddReference(“RevitAPI”)
import Autodesk
from Autodesk.Revit.DB import PDFExportOptions, ElementId, ExportPaperFormat
# Collect and set export options
opts = PDFExportOptions()
opts.HideCropBoundaries = options[0]
opts.HideScopeBoxes = options[1]
opts.HideReferencePlane = options[2]
opts.HideUnreferencedViewTags = options[3]
opts.MaskCoincidentLines = options[4]
# This will uses the Sheet Size for Paper size, or default to Letter
opts.PaperFormat = ExportPaperFormat.Default
# Variables to append to
results =
sheetList = ListElementId
# Execute the batch export
for s, n in zip(sheets, fileNames):
# Set file name
opts.FileName = n
# Add sheet to a list
sheetList.Add(s.Id)
# Export and append the result
result = doc.Export(directoryPath, sheetList, opts)
results.append(result)
sheetList.Clear()
# Preparing output to Dynamo
OUT = results, “SUCCESS: Version is 2022 or higher.”
Otherwise tell the user we can’t proceed
else:
OUT = [False for s in sheets], “ERROR: Only works in Revit 2022 or higher.\n\nUse Revit.PrintToPdf node instead.”
![image|690x213](upload://iRcW0tYUaOBNU2YmVNDTGMecgXx.png)