export schedule to csv dynamo revit
# Schedules Exporter
import clr
import sys
import System
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
uidoc = uiapp.ActiveUIDocument
app = uiapp.Application
sdkNumber = int(app.VersionNumber)
clr.AddReference("RevitAPI")
from Autodesk.Revit.DB import *
clr.AddReference("RevitAPIUI")
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)
pf_path = System.Environment.GetFolderPath(System.Environment.SpecialFolder.ProgramFilesX86)
sys.path.append(pf_path + '\\IronPython 2.7\\Lib')
import csv
import codecs
def tolist(obj1):
if hasattr(obj1,"__iter__"): return obj1
else: return [obj1]
schedules = UnwrapElement(tolist(IN[0]))
path = IN[1]
exportTitle = IN[2]
exportColumnHeaders = IN[3]
exportHeadersFooters = IN[4]
opt = ViewScheduleExportOptions()
opt.Title = IN[2]
opt.TextQualifier = ExportTextQualifier.DoubleQuote
opt.FieldDelimiter = ';'
if not exportColumnHeaders:
opt.ColumnHeaders = 0
opt.HeadersFootersBlanks = IN[4]
outCsv = []
i = 0
for s in schedules:
#n = s.ViewName.ToString()+".csv" # before, for Revit 2019 and before
n = s.Name +".csv" # for Revit 2020 and after
s.Export(path, n, opt)
i=i+1
fullPathCsv = path + "\\" + n
codec_reader = "utf-8" if sdkNumber > 2020 else "utf-16"
with codecs.open(fullPathCsv, "rb", encoding = codec_reader) as csvfile:
csv_reader = csv.reader(csvfile, delimiter=';')
outCsv.append([row for row in csv_reader])
OUT = outCsv