Bulk Processing via Python Script

This widget could not be displayed.

Bulk Processing via Python Script

Anonymous
Not applicable

For the record, I am more artist than I am technical so I am still learning and open minded to my code. But basically I have a situation that I have been trying to solve for weeks.... and I am stumped like no other.

 

This script works in Max 2019 but does not work in Max 2020... I don't have the slightest clue, could someone help guide me?

 

#
#import modules
#
import MaxPlus as max
import pymxs
import os

#
#define a master folder and suffix name
#

folder = r"C:\Users\me\Desktop\test2"

convertedEndingName = "_BUILD"


# Find any .max files in the folder specified, if max exist, open, export # entire scene to fbx.
for root, dirs, files in os.walk(folder):
    for item in files:
      if item.endswith((".max", ".MAX")):
		  filePath = os.path.join(root, item)
		  filePath = filePath.replace('\\', '\\\\')
		  
		  filePath1 = r'"' + filePath + '"'
		  
		  print(filePath1)
		  
		  
		  filePathExported = filePath.replace('.max', '').replace('.MAX', '')
		  
		  sm = r'loadMaxFile ' + filePath1 + ' quiet:true prompt:false useFileUnits:false'
		  
		  max.Core.EvalMAXScript(sm)
		  
		  filePathExported = r'"' + filePathExported + '_MAX' + convertedEndingName +'.fbx"'
		  
		  print(filePathExported)
		  
		  efbx = r'exportFile ' + filePathExported  + '#noPrompt ' + ' selectedOnly:false'
		  
		  max.Core.EvalMAXScript(efbx)

 

0 Likes
Reply
Accepted solutions (1)
1,519 Views
6 Replies
Replies (6)

attilaszabo
Alumni
Alumni

What is the error you are encountering?

Attila Szabo
Product Owner, 3ds Max
Autodesk
0 Likes

Anonymous
Not applicable

Whoops, I am sorry, I got my versions mixed up, It works in Max 2020 but not 2021.

 

The error I am getting looks like this:

 

maxError.png

 

 

 

0 Likes

attilaszabo
Alumni
Alumni

Sounds like you may have introduced an inconsistency in the white space that you use for code indentation.

Turn on "show whitespace" in your editor (in 3ds Max's editor, it's Ctrl+Shift+8, or View menu > Whitespace) and look for the problem.

Attila Szabo
Product Owner, 3ds Max
Autodesk
0 Likes

Anonymous
Not applicable

Thanks! That helped me get to the real problem....

 

If there is no MaxPlus Module... then how do I rewrite the two functions that use MaxPlus on line 

 

unknown.png

 

The lines I am referring to are

 

			sm = r'loadMaxFile ' + filePath1 + ' quiet:true prompt:false useFileUnits:false'

and

			efbx = r'exportFile ' + filePathExported  + '#noPrompt ' + ' selectedOnly:false'

 

0 Likes

eric.brosseau
Autodesk
Autodesk
Accepted solution

@Anonymous ,

The script already uses a MAXScript way of loading and exporting a file. You simply need to use the 'pymxs' module to achieve the same. The module is a Python wrapper over MAXScript. Your script would now read like this:

#
#import modules
#
from pymxs import runtime as mxs
import os

#
#define a master folder and suffix name
#

folder = r"C:\Users\me\Desktop\test2"

convertedEndingName = "_BUILD"

# Find any .max files in the folder specified, if max exist, open, export # entire scene to fbx.
for root, dirs, files in os.walk(folder):
    for item in files:
        if item.endswith((".max", ".MAX")):
            filePath = os.path.join(root, item)
            filePath = filePath.replace('\\', '\\\\')
            print(filePath)

            filePathExported = filePath.replace('.max', '').replace('.MAX', '')
            mxs.loadMaxFile(filePath, quiet=True, prompt=False, useFileUnits=False)

            filePathExported = filePathExported + '_MAX' + convertedEndingName + '.fbx'
            print(filePathExported)

            mxs.exportFile(filePathExported, mxs.Name('noPrompt'), selectedOnly=False)

 

You can read more on translating MAXScript to Python on this help page.

 

Eric Brosseau
Senior Software Developer, 3ds Max, Autodesk

Anonymous
Not applicable

THANK YOU SO MUCH!  IT WORKS!

 

The resources you linked are really helpful, especially seeing it used in example.. You rock for correcting this for me. Thanks again.