Interfaces > Core Interfaces > python |
NEW in 3ds Max 2015: The Python Core Interface exposes the Python engine's controls to MAXScript.
<enum>python.Init throwOnError:<bool> Init enums: {#success | #pathError | #initError | #scriptFileError | #executeError} throwOnError default value: true
Initializes the Python engine and returns #success .
If the initialization failed, returns an enum describing the cause of the failure - path error, initialization error, script file error or execution error.
If the optional argument throwOnError: is set to False, no error will be thrown if one is encountered.
<enum>python.Execute <string>script fileName:<filename> throwOnError:<bool> clearUndoBuffer:<bool> Execute enums: {#success | #pathError | #initError | #scriptFileError | #executeError} fileName default value: undefined throwOnError default value: true clearUndoBuffer default value: true
Executes the Python script specified by the string in the first argument, or, if the optional fileName: argument is provided, executes the specified Python script file.
Returns #success if the execution was successful, or one of the other enums describing the cause of the failure - path error, initialization error, script file error or execution error.
If the optional argument throwOnError: is set to False, no error will be thrown if one is encountered.
If the optional argument clearUndoBuffer: is set to False, the Undo Buffer will not be cleared before execution.
<enum>python.ExecuteFile <filename>fileName throwOnError:<bool> clearUndoBuffer:<bool> ExecuteFile enums: {#success | #pathError | #initError | #scriptFileError | #executeError} throwOnError default value: true clearUndoBuffer default value: true
Executes the Python script file specified by the first argument.
Returns #success if the execution was successful, or one of the other enums describing the cause of the failure - path error, initialization error, script file error or execution error.
If the optional argument throwOnError: is set to False, no error will be thrown if one is encountered.
If the optional argument clearUndoBuffer: is set to False, the Undo Buffer will not be cleared before execution.
<String by value>python.GetLastError()
Returns the last error message as string.
This is especially useful when executing with throwOnError: set to False - if the return value is not #success , you can use this method to display your own error message without throwing an error.
EXAMPLE: |
( result = python.Init throwOnError:false if result == #success do ( result = python.Execute "print \"Hello World!\"" throwOnError:false ) if result != #success then ( format "Python Initialization Failed due to %\n" (result as string) format "ERROR: %\n" (python.GetLastError()) ) else format "The Python Execution Was A World-Wide Success!\n" OK ) |
OUTPUT: |
Hello World! The Python Execution Was A World-Wide Success! OK |
CHANGE LINE 5 - MISTYPE PRINT AS PRUNT: |
result = python.Execute "prunt \"Hello World!\"" throwOnError:false |
OUTPUT: |
Python Initialization Failed due to executeError ERROR: <type 'exceptions.SyntaxError'> invalid syntax (, line 1) OK |