When 3ds Max is first started, MAXScript searches for any startup script files that it then automatically loads and runs. This feature is useful if you have function libraries you always use and want preloaded, or if you want to establish custom UI settings, define scripted plug-ins, or load scripted utility rollouts.
When 3ds Max starts up, it will always follow the script loading order described below. Certain parts of the software will still not be up and running at different stages of the startup process. Understanding the order and the reasons for it will help you organize your code and have all functions and UI auto-loading and working correctly together.
3ds Max will evaluate the shipping scripts found under stdplugs\stdscripts. These define functions needed by several scripted elements of the base 3ds Max software.
If you need to have some functions/global variables defined for use by your own MacroScript, those should go into an .ms file in stdplugs\stdscripts. This will ensure that they will be defined first.
Next, 3ds Max will load script files in directories defined in Customize... > Configure Paths... > Plug-Ins and their subdirectories. Note that this is different from the way regular plug-ins are loaded. Plug-ins will only load from the specified path and not search sub-directories. Here you can define functions, methods, and structures used by other scripts, particularly MacroScripts.
The 3ds Max scene has not been created and the viewports have not been created at this point. You cannot create scene objects or do anything UI related in these scripts. Of course you can define functions that do these operations, you just can't call these functions at this point.
In this pass, any script files with the name startup.ms are ignored. This allows you to place your scripted plug-in scripts in the plug-in folders for automatic loading. They can be managed like DLL plug-ins, and used to organize your startup scripts into groups in their own directories for easier management. You can prevent a nested directory from being scanned by placing its name in parentheses, for example "(old-versions)", allowing you to enable and disable scripts in handy directory-based groupings.
Next, MacroScript .mcr files in ui\macroscripts will be evaluated - they define Action Items that can be displayed in the UI. At this point, UI has not been built yet, the MacroScripts will be needed to fill in their related buttons.
Finally, the startup.ms and then any scripts found in the startup folders will be evaluated. At this point, scene, viewports, and UI are up. You can do anything here you want.
In 3ds Max 9 and higher, startup scripts in the 3ds Max system startup scripts directory are run first, then the startup scripts in the user startup scripts directory are run, providing that the user startup scripts directory is different than the max system startup scripts directory.
MAXScript first searches for a file named startup.ms in the following directories, in the order listed:
MAXScript stops searching when it finds the first occurrence of startup.ms.
The automatic loading of startup script files can be deactivated by turning off the Auto Start MAXScript option in the MAXScript page of the Preferences dialog, as described in the MAXScript Preferences Settings topic in the main product online help.
Consider the following two use cases:
Starting 3ds Max from the command line, eventually with a command line script:
In both cases, 3ds Max boots up as described above and then loads the file.
In 3ds Max 2009 and earlier, the order of script folders and callbacks getting executed was as follows:
As result, scripts loaded from the \Startup folder could NOT be used by #filePreOpen event callbacks!
In 3ds Max 2010 the load order has been changed to: