open_blend.py was Japanized?

Hi,

I modified a script, load_blend.py.
Already you know , it is a file chooser script that pops windows dialogue.

This script has a problem when it encode filepath.
I use

sys.stdout.encoding

as encoding , but I should use

sys.getfilesystemencoding()

in this case,I think.

I tested follow three pattern…
(1):sys.getdefaultencoding() - x(utf-8) not exitst
(2):sys.stdout.encoding - o(cp932)
(3):sys.getfilesystemencoding() - ?(mcbs) critical error

My environment:
OS : Windows 2000(JP)
blender: Ver. 2.44
python: Ver. 2.5

#!BPY

""" Registration info for Blender menus:
Name: 'Open .blend'
Blender: 237
Group: 'Help'
Tooltip: 'Open .blend files using standard Windows file dialog'
"""

# --------------------------------------------------------------------------
# ***** BEGIN GPL LICENSE BLOCK *****
#
# Copyright (C) 2005-2006 Mariano Hidalgo
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
#
# ***** END GPL LICENCE BLOCK *****
# --------------------------------------------------------------------------


__author__ = "Mariano Hidalgo AKA uselessdreamer"
__url__ = ("blender", "elysiun")
__version__ = "1.0"

__bpydoc__ = """
Allows you to open a .blend file using the standard Windows file dialog.
The script recalls your last chosen folder and defaults there. If the
folder no longer exists, it defaults to C:\\.

Needs a full Python installation to work (www.python.org).
"""
##modified for Japanese env , by manda[2007.05.20]

import Blender
import os
import sys
import tkFileDialog
import Blender.sys as Bsys
from Blender import Registry

from Tkinter import Tk

# get a encoding string (Is this correct?)
file_enc = sys.stdout.encoding

t = Tk()
t.wm_title("Open Blend")
t.wm_state("icon")

d = Registry.GetKey('OpenBlend', True)
if d:
	last_folder = d['last_folder'].encode(file_enc) # encodings
else:
	last_folder = u"C:\\"
	
if Bsys.exists(last_folder):
	os.chdir(last_folder)
else:
	os.chdir(u"C:\\")
	
f = tkFileDialog.askopenfilename(title="Open Blend",filetypes=[(".blend files", "*.blend")])
t.destroy()

if f:
	d = {}
	d['last_folder'] = Bsys.dirname((f).replace("/","\\"))
	Registry.SetKey('OpenBlend', d, True)
	if f[-6:] == ".blend":
		g = f.encode(file_enc)	# encodings
		if Bsys.exists(g):
			Blender.Load(g)
		else:
		Draw.PupMenu("Error!%t|Not a .blend file")

and sitecustomize.py ( C:/python25/Lib/site-packages/)

import sys
sys.setdefaultencoding("utf-8")

in blender 2.44 ,it can display Unicode characters on File Window.
but it is… :frowning:

Thanks,

Hi MandaSan, i’m afraid but i think i’m not the only one who does not get the point. What about posting a blend?

1 Like

Hi 3D-Penguin san,

sorry for my poor english.

I’ts not about posting a .blend file.
This issue about loading blendfile to blender.exe (using python) when filename (or filepath) includes Japanese character,like this;

C:\dir\パス\ぶれんだあ.blend

I want to get this filepath to use Tk’s(windows) file dialog,and load the file to blender.exe.

This code is Ok;

import sys
import Blender.sys as Bsys

f="C:\dir\path\blender.blend"
Bsys.Blender.Load(f)

but this code can’t find filepath

f=u"C:\dir\パス\ぶれんだあ.blend"
Bsys.Blender.Load(f)

I modify to reading a .blend file that it has Japanese name,
it requiers convert from unicode encoding to system encoding.

I try first, it coud’t find a path;

f = u"C:\dir\パス\ぶれんだあ.blend"
g = f.encode(sys.getdefaultencoding())	# encodings unicode -> (utf-8)
Bsys.Blender.Load(g)

Second, I caught a critical error ;

f = u"C:\dir\パス\ぶれんだあ.blend"
g = f.encode(sys.getfilesystemencoding())	# encodings unicode -> (mcbs)
Bsys.Blender.Load(g)

Finally, I could ;

f = u"C:\dir\パス\ぶれんだあ.blend"
g = f.encode(sys.stdout.encoding)	# encodings unicode -> (cp932)
Bsys.Blender.Load(g)

what’s the difference?

I use windows200 (JP).

thanks,

I think this script opens blend files out of exe files except it can now open Japanese files too. Am I right?

Hi C-106 Delta san,
thank for your reply.

Probably yes… ah, I forgot to write about that…

Here is two screenshot, do you think about?
(Most of you , this may not big deal.)
http://image.blog.livedoor.jp/lab1092/imgs/4/a/4ad12c2d-s.jpg
With tk

http://image.blog.livedoor.jp/lab1092/imgs/c/d/cd1c57ae-s.jpg
File window x2

thanks,

I think the computer running the script may need both English and Japanese text in order work correctly but it is still very helpful. Thank.

I was looking the script over again and I don’t think it hacks the file, it only converts it from Japanese to English, very cool.

Hi,

Now I can read/write .blend file via Tkinter :smiley:
bl2tkaccess.zip

thanks,

Bump.
Hey does anyone know where I can fidn the original version of this script(englis version hopefully)?

plec, I have all the scripts…
check the system toolkit on the wiki (in my sig) for a working version.

Manda.
the easy way around this should be:
Add:

# -*- coding:Shift_JIS -*-

below

#!BPY

This should fix your problem.

Edit: if it appears again due to changes in the API.

Meta-Androcto

thanks I got the scripts. However. how do you use dialog script?

hi, Windows Dialog Pack:
there are 3 scripts included in the System Bundle.
open_blend_248.py
open_image_248.py
open_text_248.py.
Place these in afolder called Py_system in .blender/scripts.
then run them from the Scripts System menu in Blender.

Note: These scripts need a full Python install to work.
Also they are for Windows xp os only. not tested with vista.

.

It was giving me an error that is why I asked about it. I am under xp64 and here is the message

import tkFileDialog

File “E:\Python25\lib\lib-tk kFileDialog.py”, line 43, in <module>
from tkCommonDialog import Dialog
File “E:\Python25\lib\lib-tk kCommonDialog.py”, line 11, in <module>
from Tkinter import *
File “E:\Python25\lib\lib-tk\Tkinter.py”, line 37, in <module>
import FixTk # Attempt to configure Tcl/Tk without requiring PATH
File “E:\Python25\lib\lib-tk\FixTk.py”, line 24, in <module>
import _tkinter
ImportError: DLL load failed with error code 193

That is a problem with tkinter module, probably not ported to 64bit Windows. Check google for the many errors that are related to that - you’d need a properly compiled module, but I’ve no idea how to get that (other than maybe 64bit python install?)

/Nathan

jesterKing, that would make sense. Thanks for shedding some light on this.

Thanks for your reply to my old post :).

but i think ,about their encoding ,UTF-8 is better than Shift_JIS

# あああ

if this script file’s encoding is Shift_JIS,you may cought an error, you sould specify,

# -*- coding:Shift_JIS -*-
# あああ

but UTF-8 (encoded), you can run even if you forgot to add “# -- coding:UTF-8 --”:smiley:

by the way, I think blender need some improvement for localization.

for my environment, i cought many time an encoding error with commented line with French when run the script:(
text window in blender cannot display non-ascii character(most of Kanji ,Hiragana…) correctly,even if “International Fonts” is on.
and dosplay on the file window ,too:(
sorry,it is off-topic…