diff options
author | Campbell Barton <ideasman42@gmail.com> | 2013-09-13 03:48:10 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2013-09-13 03:48:10 +0400 |
commit | ac7e79ea35be9d2b9fd2d87ad09c4dc1aa26e248 (patch) | |
tree | 4fc40b10993e38c222d4a7d88491bebf8ee45438 | |
parent | e8434f0e4f4bada0a8380d0abe646d86ba92259e (diff) |
add check for reading ascii fbx files, was common annoyance that users are unaware that they try to import ascii files.
-rw-r--r-- | io_scene_fbx/import_fbx.py | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/io_scene_fbx/import_fbx.py b/io_scene_fbx/import_fbx.py index b386e47a..22a4279d 100644 --- a/io_scene_fbx/import_fbx.py +++ b/io_scene_fbx/import_fbx.py @@ -828,6 +828,17 @@ def blen_read_light(fbx_tmpl, fbx_obj, global_scale): return lamp +def is_ascii(filepath, size): + with open(filepath, 'r', encoding="utf-8") as f: + try: + f.read(size) + return True + except UnicodeDecodeError: + pass + + return False + + def load(operator, context, filepath="", global_matrix=None, use_cycles=True, @@ -843,6 +854,11 @@ def load(operator, context, filepath="", import os from . import parse_fbx + # detect ascii files + if is_ascii(filepath, 24): + operator.report({'ERROR'}, "ASCII FBX files are not supported %r" % filepath) + return {'CANCELLED'} + try: elem_root, version = parse_fbx.parse(filepath) except: |