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?

image

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(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

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!

2 Likes

Thanks to both of you!

1 Like