Dynamo Schedule Exports as UTF-8 BOM txt files in Revit '21 and 22

Hello - I used the python script to export Revit schedules automatically and until Revit 2020, the .txt files were encoded in UTF-16LE. In Revit 2021 and Revit 2022, the same tool is exporting as .txt files in the UTF-8 BOM version. How can I revert this back to UTF-16LE or just UTF-8 encoding? So that my excel macros can import it properly.

Below is the current Python script. I use to export the Revit schedules in txt files.

import clr
clr.AddReference("RevitAPI")
from Autodesk.Revit.DB import *
#The inputs to this node will be stored as a list in the IN variables.
schedule_list = IN[0]
path = IN[1]
filename_list= IN[2]
result_list=[]

for index, sched in enumerate(schedule_list):
	schedule = UnwrapElement(sched)
	filename = filename_list[index]
	try:	
		export_options = ViewScheduleExportOptions()
		schedule.Export(path, filename, export_options)
		result_list.append("Schedule exported")
	except: result_list.append("Export Failed")

OUT = result_list

Hello
try this conversion

import clr
import sys
import System
from System.IO import *
clr.AddReference("RevitAPI")
from Autodesk.Revit.DB import *
import codecs
import shutil
		
#The inputs to this node will be stored as a list in the IN variables.
schedule_list = IN[0]
path = IN[1]
filename_list= IN[2]
result_list=[]

for index, sched in enumerate(schedule_list):
	schedule = UnwrapElement(sched)
	filename = filename_list[index]
	export_options = ViewScheduleExportOptions()
	schedule.Export(path, filename, export_options)
	# conversion
	with codecs.open(path + '\\' + filename, "r", encoding="utf-8-sig") as input_file:
		with codecs.open(path + '\\out_utf16_' + filename, "w", encoding="utf-16") as output_file:
			shutil.copyfileobj(input_file, output_file)		
	result_list.append(path + '\\out_utf16_' + filename)	
	
OUT = result_list
1 Like

Iā€™m sorry it did work. Can the script automatically delete the original .txt files with UTF-8 BOM in the folder?

sure

import clr
import sys
import System
from System.IO import *
clr.AddReference("RevitAPI")
from Autodesk.Revit.DB import *
import codecs
import shutil
		
#The inputs to this node will be stored as a list in the IN variables.
schedule_list = IN[0]
path = IN[1]
filename_list= IN[2]
result_list=[]

for index, sched in enumerate(schedule_list):
	schedule = UnwrapElement(sched)
	filename = filename_list[index]
	export_options = ViewScheduleExportOptions()
	schedule.Export(path, filename, export_options)
	# conversion
	with codecs.open(path + '\\' + filename, "r", encoding="utf-8-sig") as input_file:
		with codecs.open(path + '\\out_utf16_' + filename, "w", encoding="utf-16") as output_file:
			shutil.copyfileobj(input_file, output_file)		
	result_list.append(path + '\\out_utf16_' + filename)	
	# Delete old
	System.IO.File.Delete(path + '\\' + filename)
	
OUT = result_list

I share a website to check encoding file
https://charsetnormalizerweb-ousret.vercel.app/