New Addon: Import Autodesk .max #105013
@ -397,8 +397,7 @@ class MaxFileDirEntry:
|
|||||||
|
|
||||||
class ImportMaxFile:
|
class ImportMaxFile:
|
||||||
"""Representing an interface for importing .max files."""
|
"""Representing an interface for importing .max files."""
|
||||||
def __init__(self, filename=None, write_mode=False):
|
def __init__(self, filename=None):
|
||||||
self.write_mode = write_mode
|
|
||||||
self._filesize = None
|
self._filesize = None
|
||||||
self.byte_order = None
|
self.byte_order = None
|
||||||
self.directory_fp = None
|
self.directory_fp = None
|
||||||
@ -433,7 +432,7 @@ class ImportMaxFile:
|
|||||||
self.sector_size = None
|
self.sector_size = None
|
||||||
self.transaction_signature_number = None
|
self.transaction_signature_number = None
|
||||||
if filename:
|
if filename:
|
||||||
self.open(filename, write_mode=write_mode)
|
self.open(filename)
|
||||||
|
|
||||||
def __enter__(self):
|
def __enter__(self):
|
||||||
return self
|
return self
|
||||||
@ -445,18 +444,13 @@ class ImportMaxFile:
|
|||||||
unicode_str = utf16_str.decode('UTF-16LE', errors)
|
unicode_str = utf16_str.decode('UTF-16LE', errors)
|
||||||
return unicode_str
|
return unicode_str
|
||||||
|
|
||||||
def open(self, filename, write_mode=False):
|
def open(self, filename):
|
||||||
self.write_mode = write_mode
|
|
||||||
if hasattr(filename, 'read'):
|
if hasattr(filename, 'read'):
|
||||||
self.fp = filename
|
self.fp = filename
|
||||||
elif isinstance(filename, bytes) and len(filename) >= MIN_FILE_SIZE:
|
elif isinstance(filename, bytes) and len(filename) >= MIN_FILE_SIZE:
|
||||||
self.fp = io.BytesIO(filename)
|
self.fp = io.BytesIO(filename)
|
||||||
else:
|
else:
|
||||||
if self.write_mode:
|
self.fp = open(filename, 'rb')
|
||||||
mode = 'r+b'
|
|
||||||
else:
|
|
||||||
mode = 'rb'
|
|
||||||
self.fp = open(filename, mode)
|
|
||||||
filesize = 0
|
filesize = 0
|
||||||
self.fp.seek(0, os.SEEK_END)
|
self.fp.seek(0, os.SEEK_END)
|
||||||
try:
|
try:
|
||||||
@ -467,7 +461,6 @@ class ImportMaxFile:
|
|||||||
self._used_streams_fat = []
|
self._used_streams_fat = []
|
||||||
self._used_streams_minifat = []
|
self._used_streams_minifat = []
|
||||||
header = self.fp.read(512)
|
header = self.fp.read(512)
|
||||||
|
|
||||||
fmt_header = '<8s16sHHHHHHLLLLLLLLLL'
|
fmt_header = '<8s16sHHHHHHLLLLLLLLLL'
|
||||||
header_size = struct.calcsize(fmt_header)
|
header_size = struct.calcsize(fmt_header)
|
||||||
header1 = header[:header_size]
|
header1 = header[:header_size]
|
||||||
@ -578,7 +571,7 @@ class ImportMaxFile:
|
|||||||
try:
|
try:
|
||||||
self.fp.seek(self.sectorsize * (sect + 1))
|
self.fp.seek(self.sectorsize * (sect + 1))
|
||||||
except:
|
except:
|
||||||
print('MAX sector index out of range')
|
print('IndexError: MAX sector index out of range')
|
||||||
sector = self.fp.read(self.sectorsize)
|
sector = self.fp.read(self.sectorsize)
|
||||||
return sector
|
return sector
|
||||||
|
|
||||||
@ -610,9 +603,8 @@ class ImportMaxFile:
|
|||||||
fat=self.minifat, filesize=self.ministream.size)
|
fat=self.minifat, filesize=self.ministream.size)
|
||||||
else:
|
else:
|
||||||
return MaxStream(fp=self.fp, sect=start, size=size,
|
return MaxStream(fp=self.fp, sect=start, size=size,
|
||||||
offset=self.sectorsize,
|
offset=self.sectorsize, sectorsize=self.sectorsize,
|
||||||
sectorsize=self.sectorsize, fat=self.fat,
|
fat=self.fat, filesize=self._filesize)
|
||||||
filesize=self._filesize)
|
|
||||||
|
|
||||||
def _find(self, filename):
|
def _find(self, filename):
|
||||||
if isinstance(filename, str):
|
if isinstance(filename, str):
|
||||||
|
Loading…
Reference in New Issue
Block a user