Stumbled upon this thread…
For anyone who is interested:
I altered @Konrad_K_Sobon Konrad script a bit and was able to print and rename in the same run. So when i press run it starts plotting my sheets and when that’s done it renames them according to the parameters i have entered.
I use a wait function based on the amount of sheets I plot, not an ideal solution but it works.
Going to replace the wait function by a file counter so Dynamo waits with plotting the next file until the former was actually saved in the folder.
Code looks like this now:
# Copyright(c) 2015, Konrad K Sobon
# @arch_laboratory, http://archi-lab.net
import clr
import time
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
# Import Element wrapper extension methods
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)
# Import geometry conversion extension methods
clr.ImportExtensions(Revit.GeometryConversion)
# Import DocumentManager and TransactionManager
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
app = uiapp.Application
# Import RevitAPI
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 os
import System
# The inputs to this node will be stored as a list in the IN variable.
dataEnteringNode = IN
# The sheets to print
sheets = IN[0]
# Set to select to print only the selected views/sheets
pRange = System.Enum.Parse(Autodesk.Revit.DB.PrintRange, IN[1])
# True if saving as a single combined file, false if saving as separate files
combined = IN[2]
# The printer/pdf creator to send the selected files to
printerName = IN[3]
# List of sheet sizes to print
printInstellingen = IN[4]
# String: A prefix to give to the files that are to be saved, like a project name. Leave empty if not desired.
prefix = IN[5]
# Sheet numbers
identifiers = IN[6]
# List of the new sheet names, to be given to the identifiers specified sheets
newNames = IN[7]
# String: Directory path to the folder in which the sheet files can be saved/renamed
filePath = IN[8]
# Reset the script when run with false, when true actually runs the script
runIt = IN[9]
if isinstance(sheets, list):
viewSheets = []
for viewset in sheets:
viewSheets.append(UnwrapElement(viewset))
else:
viewSheets = UnwrapElement(sheets)
if isinstance(printInstellingen, list):
printSettings = []
for viewset in printInstellingen:
printSettings.append(UnwrapElement(viewset))
else:
printSettings = UnwrapElement(printInstellingen)
TransactionManager.Instance.EnsureInTransaction(doc)
printManager = doc.PrintManager
printSetup = printManager.PrintSetup
printManager.SelectNewPrintDriver(printerName)
if isinstance(printInstellingen, list):
printSetup.CurrentPrintSetting = printSettings[0]
else:
printSetup.CurrentPrintSetting = printSettings
printManager.Apply()
TransactionManager.Instance.TransactionTaskDone()
#
# Prints a given sheet as the provided filePathAndName, obeying the other parameters like printSettings about how to do so.
#
# param doc: The current revit document you're working in
# param sheet: A view sheet to be printed/saved
# param pRange: The range of which files are to be saved, "selected" in this case
# param printerName: The printer name or pdf application to send the files to
# param combined: Boolean - True if to be saved as a single file, false if to be saved separately
# param filePathAndName: String - The full path and name, indicating where to save the file and under which name
# param printSetting: PrintSetting - Represents the print setup within autodesk revit about how to save the files
def PrintView(doc, sheet, pRange, printerName, combined, filePathAndName, printSetting):
# create view set
viewSet = ViewSet()
viewSet.Insert(sheet)
# determine print range
printManager = doc.PrintManager
printManager.PrintRange = pRange
printManager.Apply()
# make new view set current
viewSheetSetting = printManager.ViewSheetSetting
viewSheetSetting.CurrentViewSheetSet.Views = viewSet
# set printer
printManager.SelectNewPrintDriver(printerName)
printManager.Apply()
# set combined and print to file
if printManager.IsVirtual:
printManager.CombinedFile = combined
printManager.Apply()
printManager.PrintToFile = True
printManager.Apply()
else:
printManager.CombinedFile = combined
printManager.Apply()
printManager.PrintToFile = False
printManager.Apply()
# set file path
printManager.PrintToFileName = filePathAndName
printManager.Apply()
# apply print setting
try:
printSetup = printManager.PrintSetup
printSetup.CurrentPrintSetting = printSetting
printManager.Apply()
except:
pass
# save settings and submit print
TransactionManager.Instance.EnsureInTransaction(doc)
viewSheetSetting.SaveAs("tempSetName")
printManager.Apply()
result = printManager.SubmitPrint()
viewSheetSetting.Delete()
TransactionManager.Instance.TransactionTaskDone()
return result
try:
viewSets = FilteredElementCollector(doc).OfClass(ViewSheetSet)
for viewset in viewSets:
if viewset.Name == "tempSetName":
TransactionManager.Instance.EnsureInTransaction(doc)
doc.Delete(viewset.Id)
TransactionManager.Instance.ForceCloseTransaction()
else:
continue
errorReport = None
message = "Success"
if runIt:
timeToWaitBeforeRenaming = 25
if isinstance(viewSheets, list) and isinstance(printSettings, list):
timeToWaitBeforeRenaming = max([25, len(viewSheets) * 4])
for viewset, printSetting in zip(viewSheets, printSettings):
PrintView(doc, viewset, pRange, printerName, combined, prefix, printSetting)
elif isinstance(viewSheets, list) and not isinstance(printSettings, list):
timeToWaitBeforeRenaming = max([25, len(viewSheets) * 4])
for viewset in viewSheets:
PrintView(doc, viewset, pRange, printerName, combined, prefix, printSettings)
elif not isinstance(viewSheets, list) and not isinstance(printSettings, list):
PrintView(doc, viewSheets, pRange, printerName, combined, prefix, printSettings)
# Give the PDF Creator to save the files
time.sleep(timeToWaitBeforeRenaming)
for file in os.listdir(filePath):
currentFileName = filePath + "\\" + file
for identifier, newName in zip(identifiers, newNames):
newFileName = filePath + "\\" + newName
if identifier in file and currentFileName != newFileName:
os.rename(currentFileName, newFileName)
else:
message = "Set RunIt to True"
except:
# if error accurs anywhere in the process catch it
import traceback
errorReport = traceback.format_exc()
# Assign your output to the OUT variable
if errorReport == None:
OUT = message
else:
OUT = errorReport