Community
3ds Max Programming
Welcome to Autodesk’s 3ds Max Forums. Share your knowledge, ask questions, and explore popular 3ds Max SDK, Maxscript and Python topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Bulk Processing via Python Script

6 REPLIES 6
SOLVED
Reply
Message 1 of 7
Anonymous
1426 Views, 6 Replies

Bulk Processing via Python Script

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)

 

Labels (1)
6 REPLIES 6
Message 2 of 7
attilaszabo
in reply to: Anonymous

What is the error you are encountering?

Attila Szabo
Product Owner, 3ds Max
Autodesk
Message 3 of 7
Anonymous
in reply to: attilaszabo

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

 

 

 

Message 4 of 7
attilaszabo
in reply to: Anonymous

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
Message 5 of 7
Anonymous
in reply to: attilaszabo

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'

 

Message 6 of 7
eric.brosseau
in reply to: Anonymous

@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
Message 7 of 7
Anonymous
in reply to: eric.brosseau

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. 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report