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” ?

# 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

1 Like

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
3 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

1 Like

@c.poupin
Not working in REVIT 2022



Did I miss something? I’m new to python

Hello,
Input IN[2] is not a boolean
He created an export csv file
cordially
christian.stan

@christian.stan
IN[2] = ExportTitles (yes-No) ?
Sorry I don’t understand.

I think the issue is with your path. You usually can’t write a file directly to C:\, but something like C:\dynamo\fileName.csv might work.

1 Like

@jacob.small
still Not working, same error.

@vishalghuge2500 please post a sample RVT and DYN for review. We’re guessing otherwise.

@jacob.small @christian.stan
image
image


SAMPLE1.rvt (5.2 MB)
Export Many Schedules.dyn (9.9 KB)

please try now, Revit 2022
(also I’m trying not to use the nodes which requires Excel installed for extraction)

hello, you had connected a boolean while Mr. Poupin had connected a string
That’s what I meant



Cordially
christian.stan

@vishalghuge2500 - the code is working fine. However it is set to utilize a semicolon (;) as the separator to account for parts of the world where a comma j(,) is used in number formatting or as the units demarcation indicator instead of a decimal point (.).

In excel if you start a new file and got to the data tab, you can import the CSV and get a result like this:

Or you can use file > open and configure the delimitator to be a semicolon in the wizard that pops up to get a result like this:

If you want to double click and have it open correctly, you’ll either need to reconfigure excel which would cause issues with other CSVs that utilize a comma, or update line 42 of the code to be this: opt.FieldDelimiter = ','

This will utilize a comma (,) instead of a semicolon (;) and you should be all set for a double click.

1 Like

@jacob.small @christian.stan
thanks

1 Like