Python error in line 180, but line 180 is an empty line?

Hello all,

I have no idea what’s going on in my workflow…
It is a large script to automatically print and rename all sheets in a selected workset.

This works great in Revit 2018 but i recently moved it to 2020, after some adjusting i got it to print correctly but it wont rename the files.

The script node output gives me an traceback error to line 180 in the code but there is nothing in line 180…
But when i open the "print en hernoem"node (script was originally made by @Konrad_K_Sobon , edited by me and a friend to get it to rename automatically.)

As you can see in the image below, line 180 is an empty line… So how exactly can i get an error in this line as shown above?


Any help would be greatly appreciated, I need to print at least 80 PDF files tomorrow and i need to get it to work.
To clarify, it does print correctly but it doesnt rename the files because there is something wrong with the script or name input i believe…
For anyone who wants to see the entire python script see below:
multiple edits to get the script to show up so its readable…

Copyright© 2015, Konrad K Sobon


import clr
import time

from Autodesk.DesignScript.Geometry import *

Import Element wrapper extension methods

import Revit


Import geometry conversion extension methods


Import DocumentManager and TransactionManager

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

import Autodesk
from Autodesk.Revit.DB import *

import sys

pyt_path = r’C:\Program Files (x86)\IronPython 2.7\Lib’

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 = UnwrapElement(sheets)

if isinstance(printInstellingen, list):
printSettings =
for viewset in printInstellingen:
printSettings = UnwrapElement(printInstellingen)

printManager = doc.PrintManager
printSetup = printManager.PrintSetup
if isinstance(printInstellingen, list):
printSetup.CurrentPrintSetting = printSettings[0]
printSetup.CurrentPrintSetting = printSettings

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()
# determine print range
printManager = doc.PrintManager
printManager.PrintRange = pRange
# make new view set current
viewSheetSetting = printManager.ViewSheetSetting
viewSheetSetting.CurrentViewSheetSet.Views = viewSet
# set printer
# set combined and print to file
if printManager.IsVirtual:
printManager.CombinedFile = combined
printManager.PrintToFile = True
printManager.CombinedFile = combined
printManager.PrintToFile = False
# set file path
printManager.PrintToFileName = filePathAndName
# apply print setting
printSetup = printManager.PrintSetup
printSetup.CurrentPrintSetting = printSetting

# save settings and submit print
result = printManager.SubmitPrint()

return result

viewSets = FilteredElementCollector(doc).OfClass(ViewSheetSet)
for viewset in viewSets:
if viewset.Name == “tempSetName”:

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

    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)

    message = "Set RunIt to True"

# 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
OUT = errorReport

Yeah i cant get the python script to show up how i like… for some reason the text is formatted like that.
Sorry, i hope its readable

script probleem.txt (6.9 KB)

Here is the script as a text file to ease your eyes…

Check that your IN[8] is receiving a single string, and not a list.

You can try to set an output as type(filePath), or you could see if you can access an item at an index.

Those are my best guesses, since the only “+” operators seem to be around your filepath operations.

Hello @MVE1112 - That error message was unfortunately bugged and has now been fixed in Dynamo 2.8 :slight_smile: Please look to the error on the line above, 179.

Check out your filePath or newName lists as one of these will be a list, rather than an object!


Thanks to both of you!

1 Like