Modification to "List TitleBlocks on Sheets" - To output in Excel using caret "^" as delimeter

Hello, possibly this will be helpful to others? Or possibly some suggestions could help me improve this? I am not sure if this post is even appropriate for the forum? We shall see…

I have a need to get a listing of all sheets and title blocks into an Excel spreadsheet. By modifying the “List TitleBlocks on Sheets” python script I was able to accomplish this! As I am a newbie to python, this was not too difficult. Here are the details:

The existing output from this tool is formatted like this:
SHEET: A-101 - FLOOR PLAN - BASEMENT TITLEBLOCK: AFC REV PRINT [966501]

Since spaces are used both in the sheet name and the title block name, it’s difficult to copy/paste this to a spreadsheet and have the results fall into the correct columns.

So how about modifying the output so it lists the items separated by commas? Or separated by something else if there are commas used in the Sheet Name? How about separating the items by a caret symbol “^” and then using that as the separator when importing the data into excel? (I have used the caret symbol successfully as a column separator in other programming languages, but I don’t know if it will work in python scripts?)

Here is how I did that. Maybe there is a better way? :upside_down_face:

I edited the python script file located here with Notepad++:
C:\Users(my username removed)\AppData\Roaming\pyRevit-Master\extensions\pyRevitTools.extension\pyRevit.tab\Drawing Set.panel\Sheets.pulldown\List TitleBlocks on Sheets.pushbutton\script.py

On lines 39 and 79 of the script I found this statement:
“SHEET: {0} - {1}\t\tTITLEBLOCK: {2} {3}”.format(

I was able to modify these statements on lines 39 and 79 to look like this. And now I have the output separated by caret symbol:
“SHEET:^{0}^{1}^TITLEBLOCK:^{2}^{3}”.format(

And here is a sample of the results:
SHEET:^A-101^FLOOR PLAN - BASEMENT^TITLEBLOCK:^AFC REV PRINT^966501

Its all nicely delimited with carets. :slightly_smiling_face:

Then:
Open the data in Browser
Select all and copy/paste into notepad
Save as txt file type
Import the file to Excel using the caret symbol “^” as your delimiter.

Yay! it works!
I know there is some python scripts for outputting directly to csv listed on this forum. They seem too complex for a newbie like me. And possibly if there is a comma in the Sheet Name, the results may not end up in the correct columns.

Any feedback would be appreciated!

Hi @BHashman,
I’m glad you find a way to solve your problem!

Since that code could be overwritten in a future pyrevit release, I suggest you to copy the “List TitleBlocks on Sheets.pushbutton” folder to your own extension (if you don’t already know how to create one, check this guide, so that you can keep it and further tinker along with it.

To select a destination CSV file and save the data in it, you can use the following function; I’ve already set the default delimiter to ^:

import codecs
import csv
from pyrevit.forms import save_file

def save_csv(data, delimiter='^'):
    filepath = save_file(file_ext='csv', default_name='title blocks.csv')
    if not fileath:  # cancel has been selected
        return
    with codecs.open(filepath, 'wb', encoding='utf-8') as csvfile:
        writer = csv.writer(csvfile, delimiter=delimiter, quotechar='\"')
        writer.writerows(data)

the input data needs to be a list of lists (the outer list represents the rows, the inner lists are the contents/columns of each row), so the original print_titleblocks function needs to be adapted:

def get_titleblocks(sheets):
    # initializing the first row with column titles
    all_tblocks = [["SHEET CODE", "SHEET NAME", "BLOCK NAME", "BLOCK ID"]]
    for sheet in sheets:
        tblocks = revit.query.get_sheet_tblocks(
        for tblock in tblocks:
            # here we add the row for a single title block
            all_tblocks.append(
                [sheet.SheetNumber, sheet.Name, tblock.Name, tblock.Id]
            )
    return all_tblocks

and the last line should be changed to

    save_csv(get_titleblocks(get_source_sheets()))
1 Like

Thanks so much for the feedback. Yes, I need to make it unique but in the meantime, I reset the code back to the original statements by installing the latest version. Because somehow, somewhere, I broke the script! ha ha ha! Well. wait a minute… the new original script also bonks too.

Details of what I broke: After creating a list, I was not able to use the application to select all the title blocks to modify them. The code was returning an error - “URL was too long and discarded”

Possibly this is a bug? After restoring the script to the latest version it still throws the same error message.

so I will put this on my task list… maybe I can get back to this next week.

again, thanks so much for the clear guidance! :slightly_smiling_face:

Here are more details about the error:
Installed pyRevit version:
pyRevit_4.8.13.23182

Script version date and location:

Error message from application:

Learn & Explore:
By unselecting some the sheets in my sheet list that have really really long Sheet Names, I was able to select the remaining title blocks and do stuff. Yay!

Conclusion: It appears there may be a limit set somewhere in the script settings or elsewhere that does not allow for really really long sheet names. I will investigate this further before creating a bug report. I want to know just how long is too long by doing further testing…

More feedback on the error. It appears that…
The routine can process up to 108 sheets. It bonks at 109 or more sheets in the selection.

So the length of the Sheet Name is not the issue with this error. Its possibly that the list is too long to handle at 109 sheets? Or maybe it is from the long sheet names and the limit is the number of characters in the URL? This is getting outside of my abilities to understand.

  • I would like to learn and explore, but how to I look at the generated URL that is throwing the error?

  • Or how would i look at the URL that does not throw an error when there are only 108 sheets in the selection?

I will test this a few more times to confirm this.

Yes, there is a limit on the length of the url hidden behind the selection button, but i don’t know the exact maximum length.
I don’t remember how the url is built, but you can open the output window in a browser (via one of the buttons in the upper bar) and inspect the html code from there