New Addon: Import Autodesk .max #105013

Closed
Sebastian Sille wants to merge 136 commits from (deleted):nrgsille-import_max into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.
Showing only changes of commit 59a70e946b - Show all commits

View File

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