Python evoking Maxscript command failed to return customized values


#1

Hello,

I have 3DS Max 2019 running on a Win 10 PC, and I have a Python script which I run automated tasks with through 3dsmaxbatch.exe. I wanted it to return customized values, so I tried evoking quitMax with either MaxPlus.Core.EvalMAXScript or MaxPlus.Core.ExecuteMAXScript, as suggested here:

Right now I am encountering a problem where the return value (by obtaining %ERRORLEVEL%) of the 3dsmaxbatch.exe call will be -130, despite the system log and debug outputs stating otherwise.

ExportArtAssets.bat:

SETLOCAL EnableDelayedExpansion
SET /A BATCH_RES=1
3dsmaxbatch.exe .\3DSMaxArtExport\ExportArtAssets.py -listenerlog N:/MaxListener-manualTest.log -v 5 -log N:/MaxSysLog-manualTest.log %*
SET /A BATCH_RES=%ERRORLEVEL%

echo 3dsmaxbatch result val: %BATCH_RES%

REM ECHO Batch result: %BATCH_RES%
EXIT /B %BATCH_RES%

ExportArtAssets.py:

import MaxPlus
class MyJob( object ):
    def __init__(self, ….. ):
        self.successCnt = 0
        self.failCnt = 0
        self.errorCnt = 0         
        # Looped calls to maxscript using MaxPlus.Core.EvalMAXScript
        # Increments successCnt, failCnt, and errorCnt based on results

def main():
    # Parse Parameters

    retVal = 0
    try:
        job = MyJob( …… )  # Runs maxscripts, tallies results
        successCnt = job.successCnt
        failedCnt = job.failCnt
        errorCnt = job.errorCnt

        if errorCnt == 0 and failedCnt == 0:
            print “Job completed with no error.”
            retVal = 0
        elif successCnt > 0:
            print “Job completed with partial success.”
            retVal = 2  # Partial success
        else:
            print “MaxExportGTArtAssetsJob failed.”
            retVal = 1

    except Exception as err:
        print “Got exception: {}”.format( err )
        retVal = 99
    finally:
        strMaxCmd = “quitMAX quiet:true exitCode:{}”.format(retVal)
        print “To run command with Exit code [{1}] => {0}”.format(strMaxCmd, retVal)
        # MaxPlus.Core.EvalMAXScript( strMaxCmd )
        MaxPlus.Core.ExecuteMAXScript( strMaxCmd )

if __name__ == ‘__main__’:
    main()

This is what I’m seeing in the console:

4/23/2020 20:56:54 PM; 3ds Max Exit Code = 0

C:\jenkins\workspace\3DSMaxArtExport>SET /A BATCH_RES=-130

C:\jenkins\workspace\3DSMaxArtExport>echo 3dsmaxbatch result val: -130
3dsmaxbatch result val: -130

C:\jenkins\workspace\3DSMaxArtExport>REM ECHO Batch result: -130

C:\jenkins\workspace\3DSMaxArtExport>EXIT /B -130

And this is part of what I see in the listener log:

………
Job completed with no error.
To run command with Exit code [0] => quitMAX quiet:true exitCode:0

The system log didn’t show any particular errors either. It did end with this, though.

……
2020/04/23 20:56:52 DBG: [12084] [06080] Stop network

I learned that 3dsmaxbatch returns -130 if an error occurred while executing a command. I doubt it’s one of the maxscripts running under MyJob, since the output suggested that it has made it near the end of ExportArtAssets.py:main().

Is it possible it occurred when it tries to execute quitMAX instead? Are there other debug logs I can find any leads? Are there any workaround for me to return a custom value?This text will be hidden


#2

Use the pymxs.runtime module to execute maxscript as python:

from pymxs import runtime as mxRt

mxRt.QuitMax(Quiet=True, ExitCode=retVal)

#3

I’ve tried that today. It returns the values correctly sometimes, but it can still return -130 some times.

The listener log shows the same thing, that it’s returning retVal = 0, but the batch script still claims 3dsmaxbatch.exe returns -130.

The following is what appears on the console:

4/27/2020 17:20:59 PM;  3ds Max Exit Code = 0


C:\jenkins\workspace\3DSMaxArtExport>SET /A BATCH_RES=-130 

C:\jenkins\workspace\3DSMaxArtExport>echo 3dsmaxbatch result val: -130 
3dsmaxbatch result val: -130