- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
In Max 22 python 3.7 ships with pathlib, a convenient library to handle file ops. Pathlib correctly resolves the directory picked via a dialog as a windows path, but the mxs wrapper for openBitMap only appears to work with paths as string literals:
def blenddir():
filedir = mxs.getBitmapOpenFilename()
return Path(filedir).parent
returns:
(print(type(img), img)
<class 'pathlib.WindowsPath'> C:\Users\user\Documents\test.tif
#---------
if img.is_file():
print("Image found")
works, indicating the file exists/path is valid.
however
#---------
try:
my_img = mxs.openBitMap(img)
throws an error:
MAXScript exception raised.
-- Unable to convert: C:\Users\user\Documents\test.tif to type: FileName
If I hardcode the path C:\\Users\\user\\Documents\\test.tif then the mxs.openBitMap(img) function works, so it would appear that the mxs wrapper for openBitMap requires a string literal as a file path.
Is this a bug? Is there a convenient way of having pathlib return a string literal so I don't have to re-write my code base with os.walk?
Thanks!
Solved! Go to Solution.