Read data in Pre-created schedule in Revit

I have created a schedule in Revit and i just want to select that view in Dynamo and read the data as strings, so it gives me nested lists of each of the columns/rows in the schedule. I know I can return the elements but i want the entire table of information as it has been filtered and sorted. Any ideas?

Hi Mark

You’ll need Python / Revit API. I believe there is a package that does this too but not sure which so maybe someone else on the forum can point you in the right direction.

I use this python script…next time, I’ll need to invoice you :wink:

If you use filters, this script will simply pick up the data thats visible

#Copyright 2016. All rights reserved. Bimorph Consultancy LTD, 5 St Johns Lane, London EC1M 4BH
#Written by Thomas Mahon @Thomas__Mahon

import clr
from Autodesk.DesignScript.Geometry import *

# Import DocumentManager and TransactionManager
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
from System.Collections.Generic import *
# Import RevitAPI
import Autodesk
from Autodesk.Revit.DB import *

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

schedule = UnwrapElement(IN[0])

# "Start" the transaction
#count the number of rows and columns in the schedule
table = schedule.GetTableData().GetSectionData(SectionType.Body)
nRows = table.NumberOfRows
nColumns = table.NumberOfColumns

#Collect all of data from the schedule
dataListRow = []
for row in range(nRows): #Iterate through the rows. The second row is always a blank space
	dataListColumn = []
	for column in range(nColumns): #Iterate through the columns
		dataListColumn.Add( TableView.GetCellText(schedule, SectionType.Body, row, column) )
	dataListRow.Add( dataListColumn );

# "End" the transaction

OUT = dataListRow

Haha cheers Tom, I thought I had seen a node in someones package that did it.


This is great. Thanks for sharing. I would just have two small comments:

  • you don’t need a Transaction for this as you are not creating anything but merely reading a data in a ViewSchedule

  • You don’t need a ProtoGeometry import since you never use any methods from that library.

Also, @Mark_Thorley1 as an alternative, and I am not sure what you want to do with the data, but if you want to take the data and write it out to Excel, you can do this:

# Copyright(c) 2016, Konrad K Sobon
# @arch_laboratory,

# Import Element wrapper extension methods
import clr
import Revit

# Import RevitAPI
import Autodesk
from Autodesk.Revit.DB import *

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

#The inputs to this node will be stored as a list in the IN variable.
dataEnteringNode = IN

def ProcessList(_func, _list):
    return map( lambda x: ProcessList(_func, x) if type(x)==list else _func(x), _list )

def Unwrap(item):
	return UnwrapElement(item)

if isinstance(IN[0], list):
	schedules = ProcessList(Unwrap, IN[0])
	schedules = [Unwrap(IN[0])]

directory = IN[1]

def ExportSchedule(schedule, dir = directory):
	options = ViewScheduleExportOptions()
	# there are couple of options that can be set here:
	# ColumnHeaders: options are None, OneRow and MultipleRows
	options.ColumnHeaders = ExportColumnHeaders.MultipleRows
	# FieldDelimiter: input is a string. By default Tab is used
	options.FieldDelimiter = ","
	# HeadersFootersBlanks: if you want to export blank headers and footers just set it to True
	options.HeadersFootersBlanks = True
	# ExportTextQualifier: how to identify text fields. Options are None, Quote or DoubleQuote
	options.TextQualifier = ExportTextQualifier.DoubleQuote
	# Title: set to True if you wish to export it.
	options.Title = True
	schedule.Export(dir, schedule.Name + "_export.csv", options)

	errorReport = None
	ProcessList(ExportSchedule, schedules)
	# 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 = schedules
	OUT = errorReport

Result when you import it into an Excel would be this:

This is a method that is available in API for exporting ViewSchedules directly to CSV, TSV or any other delimited text files. Hope this helps!



@Konrad_K_Sobon nice one, appreciate the tips!