Read data in Pre-created schedule in Revit

@Thomas_Mahon,

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, http://archi-lab.net

# Import Element wrapper extension methods
import clr
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)

# 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)

#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])
else:
	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)

try:
	errorReport = None
	ProcessList(ExportSchedule, schedules)
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 = schedules
else:
	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!

Cheers!

13 Likes