Exporting Schedules to Excel via csv

Hi @c.poupin thank you for your answer, on Revit 2021 it’s works on dynamo but not properly when I open a Excel file

related topic



instead of image
if i export txt file and open into Excel it’s works:

but not if I use the “drag and drop” method:

Is there any workaround? maybe with “TextQualifier Property” ?
https://www.revitapidocs.com/2020/8448fbb8-efe9-4b4d-0c87-7dedbef3b5a0.htm

# Schedules Exporter
# "SchedulesExporter" node from Modelical
# Batch export of schedules to CSV files. You can select the schedules with the nodes "Element Types">ViewSchedule + "All Elements of Type".
# modified by @c.poupin
# https://forum.dynamobim.com/t/exporting-schedules-to-csv-format/51791/4
"""
View.ViewName property is deprecated in Revit 2019 (remove in Revit 2020).
Replace by View.Name property

for s in schedules:
	n = s.Name +".csv"
"""
import clr

clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
doc = DocumentManager.Instance.CurrentDBDocument

clr.AddReference("RevitAPI")
from Autodesk.Revit.DB import *

clr.AddReference("RevitAPIUI")

clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)

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]
if not exportColumnHeaders:
	opt.ColumnHeaders = 0
opt.HeadersFootersBlanks = IN[4]

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

OUT = i.ToString() + " schedules exported"

Thanks in advance
Cheers

Hello @paris
try to change the delimiter to ;

opt = ViewScheduleExportOptions()
opt.Title = IN[2]
opt.TextQualifier = ExportTextQualifier.DoubleQuote
opt.FieldDelimiter = ';'
1 Like

Hi @c.poupin great! it’s working like a charm, thank you very much, you save my day !
Now for Converting the CSV Excels format files to XLSX file I use a macro, is there any tips with python?
Have a good day
Cheers

Hello, here a workaround


# Schedules Exporter
import clr
import sys
import System
import csv

clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
doc = DocumentManager.Instance.CurrentDBDocument

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

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
	with open(fullPathCsv, 'rb') as csvfile:
		reader = csv.reader(csvfile, delimiter=';')
		outCsv.append([row for row in reader])
	
OUT = outCsv

Hi @c.poupin thank you very much for your workaround, I have only a bit problem with some characters:


Thanks
Cheers

Hello,
try this version


# 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
2 Likes

Hi @c.poupin great ! I’ll try your new version. Thank you very much for your help.
Have a good day.
Cheers

1 Like

Hi @c.poupin great ! Your new version works as expected:

Thank you very much for your help.
Have a good day.
Cheers