I’ve been trying to wrap my head around this for 6 days now and have searched the net without finding a solution. So I’m throwing it out to you Blender Script Writing Experts.
I have a model that everything has been modelled entirely in a foreign language, (which of course is in UTF8, I think). The Blender Python console displays the data perfectly with international fonts turned on, however, if I try to send the data to a file that I can open in Notepad++, I get the age old error,
# my current code. I'm not a programmer but this works for me what the data fall in the cp1252 character set.
# ------------------
import bpy
import os
import codecs
user = getpass.getuser()
os.chdir("C:\\users\\" + str(user) + "[\\Desktop\\](file://\\Desktop\\)")
myFile = open('mesh.txt','w')
# or
# myFile = open('mesh.txt','wb')
g = ''
for mats in bpy.data.materials:
g = str(mats.name)
print(g)
myFile.write(g + '
')
myFile.close()
# ---------------------------------------------
This is the Console Output from the code above.
Material
9
材質1Traceback (most recent call last):
File "<blender_console>", line 4, in <module>
File "C:\Program Files (x86)\Steam\steamapps\common\Blender\2.78\python\lib\encodings\cp1252.py", line 19, in encode
return codecs.charmap_encode(input,self.errors,encoding_table)[0]
UnicodeEncodeError: 'charmap' codec can't encode characters in position 0-1: character maps to <undefined>
I’ve tried other work-arounds that I’ve found on the net (like trying to write to a binary file, various other python encoding and decoding codes to work with UTF8 and UTF-8-sig input, etc), but python still errs out every time I run a script or copy or paste the code into the python console and manually run it. I get the error and nothing is produced in the outfile.
I do currently have a work around that I’m using (which is to manual run code and send output to the console, then copy and paste it into Notepad,) but I would really like to just write the UTF8 characters straight to a file from Blender that I can open in Notepad++. (especially when the output is over 255 lines deep and I lose the first bit of data output due to the window limit and have to throw character line delimiters into code in order to keep the data from scrolling off the screen.)
Any suggestions? Please!