Convert multiple text files from Unicode to ANSI


#1

Hi,

I have used the “export schedule” Dynamo script shared in this website to export my Revit schedules to text files. However, I would like expand the script to further convert the text files format from Unicode to ANSI with Python script.
Is it possible? Can anyone help me on this?

Thank you.

Regards,
Chin


#2

Please sum up first some infos out of your preliminary researches that make clear that Dynamo is the best tool for this task:


#3

Hi Yna_Db,

Thanks for the reply. My current solution is batch file too, similar to the one that you shared with me.
However, I still hope that I can combine the procedure in a Dynamo script to ease the work.

Thank you again for the prompt reply. :slight_smile:

Regards,
Chin


#4

Please send also related researches links, you will easily find online resources and will need to make a first proposal:


#5

Hi Yna_Db,

Thanks for the reply. I have try the Python script with “import io”. Unfortunately I get warning message as below:
Warning: IronPythonEvaluator.EvaluateIronPythonScript operation failed.
Traceback (most recent call last):
File “”, line 1, in
ImportError: No module named io

I am not sure what caused this. :frowning_face:


#6

You can paste your code here this way:


By doing so, you make it easier for everyone to grasp where the problem lies and what could be the appropriate answer


#7

Hi Yna_Db,

Screenshot of my dynamo script:

Here is the code:

import io

src_path = (IN[0])

with io.open(src_path, mode="r", encoding="Unicode") as fd:
    content = fd.read()
with io.open(dst_path, mode="w", encoding="ANSI") as fd:
    fd.write(content)

Hope you can help me on this.

Thanks & regards,
Chin


#8

Hi guys,

I readed your problems about change enconding in dynamo and would I like to know if you solved this problems if you can help me with it? because I have the same question

I am export my schedules in unicode and I want change to ANSI with python script.

Thank you!


#9

Hi @oliveira.luma,

Unfortunately i am still looking for solution to this problem until today. However, i have just requested for help from Autodesk technical support team. Hopefully they will get back to me with a solution soon. If they do, i will update here.

Thank you.

Regards,
Chin


#10

Thank you so much for reply!

I am waiting for reply with you. But how did you send the question to them? Existy some email or anything like this? Because I can send to them the same question, some times we can get the answer fastest


#11

Hi
Just stumbled upon your issue.
In order to import libraries form the IronPython lib you need to add a reference to the location in your python script, so in order to use “io” you should add this line above “import io”:

import sys
sys.path.append("C:\Program Files (x86)\IronPython 2.7\Lib")

#12

Hi @oliveira.luma,

I met one of the Autodesk technical specialists during an event recently. I just verbally told him my issue and passed him my name card. Looking forward to his reply shortly.

Thanks & regards,
Chin


#13

Hi @Jonathan.Olesen,

Thanks for your reply. Yes, i noticed about that and added that in my Python script. Unfortunately it’s still not working.

Thank you.

Regards,
Chin


#14

I would like to give it a go, it should very well be possible to do the convertion from unicode to ANSI within python. If you would like me to try please upload a .dyn file, and a sample .rvt file that I can perform the test on. (.rvt file should contain relevant schedules, and .dyn file should contain working graph for “standard” export of schedues incl python script).


#15

Can you Share Your Unicode file?


#16

Hi @Jonathan.Olesen,

That would be great! Thank you very much.
I will upload the files on next Monday, when i back to office.

Thank & regards,
Chin


#17

Hi @robert12546358,

I do not have the files with me now. I will upload a sample on the next Monday when i back to office.

FYI, any Revit schedule exported from Revit will be saved in Unicode encoding by default.

Thanks & regards,
Chin


#18

Hi @ddd-team,

The script below works :

import sys
sys.path.append(r'C:\Program Files (x86)\IronPython 2.7\Lib')
import codecs

src_path = IN[0]
dst_path = IN[1]

with codecs.open(src_path, 'r', encoding = 'UTF-16') as file:
	lines = file.read()  

#write output file
with codecs.open(dst_path, 'w', encoding = 'latin-1') as file:
	file.write(lines)

OUT = 0

You can modify it to handle a list of text files or make a custom node with lacing on longest.


#19

Hi and happy Friday.

First I found out that Python doesn’t have an ANSI encoding which made me look up what is ANSI.
https://docs.python.org/2/library/codecs.html#standard-encodings


And it turns out it can be different on different systems.
Other than that what @Alban_de_Chasteigner posted should work :slight_smile:
or even something as simple as that:

Have a great weekend!


#20

Hi, guys, Thanks for reply!

Your tips worked to my documents, but one document for time. However, I have diferents documents and I would like change enconding in the same time of every documents and I tried to do like this:

But It didn’t work :frowning: