Print PDF and rename the files

Is it by chance a archilab node? I can remember having some trouble getting that one to work myself so I wrote my own.

If you’re interested, see the code below.
I’m not sure if it exactly does what you want it to do, but it might help you find a solution to the problem.
I think that you should be able to make some small modifications to my code to have it so it takes a list of names and uses shortlacing to set the right name for your drawings. This would prevent having to rename them afterwards.

#Written by D.Kuurman
#FIMBLE print to pdf node
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)
clr.ImportExtensions(Revit.GeometryConversion)

clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

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

import sys
pyt_path = r'C:\Program Files (x86)\IronPython 2.7\Lib'
sys.path.append(pyt_path)
import System


doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
app = uiapp.Application

printManager = doc.PrintManager	
printManager.PrintRange = PrintRange.Select
printManager.PrintToFile = True
viewSheetSetting = printManager.ViewSheetSetting


sheetlists = IN[0]
papersizes = IN[1]
combineFiles = IN[2]
fileName = IN[3]
fileLocation = IN[4]
printerName = IN[5]

output = list()
temp = list()

TransactionManager.Instance.EnsureInTransaction(doc)
#print the sheets
i = 0
for sublist in sheetlists:
	printlist = list()
	newViewSet = ViewSet()	
	printManager.Apply()
	setupName = 'temporary %s' %(i)
	
	if isinstance(sublist, list):
		for sheet in sublist:
			printlist.append(UnwrapElement(sheet))
	else:
		printlist.append(UnwrapElement(sublist))
	
	output.append(printlist)
	
	#build viewset for printing
	for item in printlist:
		newViewSet.Insert(item)
	temp.append(newViewSet)
	
	#setup print settings
	printManager.ViewSheetSetting.CurrentViewSheetSet.Views = newViewSet
	printManager.Apply()
	
	printManager.PrintSetup.CurrentPrintSetting = printManager.PrintSetup.InSession
	pParams = printManager.PrintSetup.CurrentPrintSetting.PrintParameters
	
	for size in printManager.PaperSizes:
		if size.Name == papersizes[i]:
			printManager.PrintSetup.CurrentPrintSetting.PrintParameters.PaperSize = size
			printManager.PrintSetup.CurrentPrintSetting.PrintParameters.ZoomType = printManager.PrintSetup.CurrentPrintSetting.PrintParameters.ZoomType.Zoom
			printManager.PrintSetup.CurrentPrintSetting.PrintParameters.Zoom = 100
			printManager.PrintSetup.CurrentPrintSetting.PrintParameters.PageOrientation = printManager.PrintSetup.CurrentPrintSetting.PrintParameters.PageOrientation.Landscape
			printManager.PrintToFileName = fileLocation + fileName + ".pdf"
			printManager.SelectNewPrintDriver(printerName)
			
			printManager.PrintSetup.SaveAs(setupName)
			printManager.Apply()
	i += 1	
	
	printManager.CombinedFile = combineFiles
	printManager.Apply()
	
	printManager.SubmitPrint()
		
	li = list()
	for p in printManager.PaperSizes:
		li.append(p.Name)
		
	
OUT = output, temp, li 

TransactionManager.Instance.TransactionTaskDone()
3 Likes