3ds Max File Loading and Saving

The following System Globals and Methods are used to access the file name and path and load, save, merge, import, and export 3ds Max scenes.

Topic Navigation:  

Scene File Path and Name

Loading MAX Files

Merging MAX Files

3ds Max Load and Save Dialogs

MAX File Object Names

Save MAX File

Hold and Fetch

Checking For MAX File

Importing Files

Exporting Files

Saving Nodes

Check For Save

System Globals:

Scene File Path and Name

maxFileName 

Contains a String value that defines the file name for the currently open scene.

This variable is read-only.

It will be set automatically when the scene is loaded or saved using the loadMaxFile() and saveMaxFile() methods described below.

See also the How do I get the file name of the current scene? FAQ entry.

   

maxFilePath 

Contains a String value that defines the directory path for the currently open scene.

This variable is read-only.

It will be set automatically when the scene is loaded or saved using the loadMaxFile() and saveMaxFile() methods described below.

See also the How do I get the file name of the current scene? FAQ entry.

   

Methods:

The following methods are used to load, save, merge, import, and export 3ds Max scenes.

Loading MAX Files

<boolean>loadMaxFile <filename_string> [useFileUnits:<bool>] [quiet:<bool>] 

Returns true if the file was found and loaded successfully, false otherwise.

If useFileUnits:false , the file objects will be rescaled to the current System's unit scale.

If true , the System's unit scale will be changed to the File's unit scale.

This option will apply regardless of the Respect System Units in Files option setting in the System Units Setup dialog.

Loading a file with useFileUnits:true will not change the system units setting in the 3dsmax.ini file.

useFileUnits defaults to false for 3ds Max, true for Autodesk VIZ.

For details on the quiet: option, please see Quiet Mode.

WARNING!

loadMaxFile() will replace the current scene content with the file content without warning!

The "The scene has been modified. Do you want to save your changes" prompt will not be issued when using this method, even when supplying quiet:false

See CheckForSave() and saveMaxFile() further on this page to ensure the current content of the scene is not lost if it requires saving.

Merging MAX Files

<boolean>mergeMAXFile <filename_string> [<name_array>] [#prompt] \ 
[ [ #select ] #noRedraw ] \ 
[ #deleteOldDups | #mergeDups | #skipDups | #promptDups | #autoRenameDups ] \
[ #promptMtlDups | #useMergedMtlDups | #useSceneMtlDups | #renameMtlDups ]\
[ #promptReparent | #alwaysReparent | #neverReparent ] \
[ quiet:<bool> ] \ 
[ missingExtFilesAction: <actions> ] [ missingExtFilesList: <&variable> ] \ 
[ missingXRefsAction: <actions> ] [ missingXRefsList: <&variable> ] \
[ mergedNodes: <&variable>

All arguments are optional except the initial file name. The flag arguments can be specified in any order.

The arguments details are as follows:

<name_array> 

An optional array of names or strings identifying the objects in the source scene file to be merged; all objects are merged if not specified.

#prompt 

If specified causes the standard merge dialog to be opened.

#select 

If specified causes the newly merged objects to be selected when merged.

#noRedraw 

If specified causes the screen redraw to be delayed in case you want to call mergeMAXFile() several times and delay the redraw until after the last file merge.

#deleteOldDups 

Deletes existing scene objects with the same names as incoming objects, equivalent to a replace.

#mergeDups 

Ignore name conflicts, merge anyway resulting in possibly duplicated names.

#skipDups 

Don't merge objects with duplicated names.

#promptDups 

Throw up the duplicates resolution dialog for the user to choose.

#AutoRenameDups 

Auto-renames the incoming objects that have names that already exist in the current scene. No dialog will pop up. Available in 3ds Max 2011 and higher.

#promptMtlDups 

Default, prompt the user when duplicated materials are found.

#useMergedMtlDups 

Merge using the incoming materials.

#useSceneMtlDups 

Merge using the scene materials.

#renameMtlDups 

Merge and rename duplicated incoming materials.

#promptReparent 

Default, prompt the user.

#alwaysReparent 

Don't ask the user, always reparent.

#neverReparent 

Don't ask the user, never reparent.

For details on the quiet: option, please see Quiet Mode

mergeMAXFile returns true if the file was found and loaded successfully. Returns false when the argument is a file with .DRF extension.

If you don't specify a full path name, the file is looked for in the 3ds Max scene directory, then in the 3ds Max executable directory, and then in the PATH environment directories.

mergedNodes <&variable>

On a successful merge, the specified variable will contain an array of merged nodes.

   

<nodes array>getLastMergedNodes()

NEW in 3ds Max 2017: Returns an array of the nodes merged in the last merge operation.

Returns an empty array #() if no merge operations have been performed in the current scene.

EXAMPLE

resetMaxFile #noPrompt --reset the scene
--> OK

getLastMergedNodes() --get the last merged nodes - returns an empty array, because nothing has been merged yet
--> #()

t = teapot() --create a teapot
--> $Teapot:Teapot001 @ [0.000000,0.000000,0.000000]

s = sphere pos:[100,0,0] --create a sphere to the right of the teapot
--> $Sphere:Sphere001 @ [100.000000,0.000000,0.000000]

b = box pos:[-50,0,0] --create a box to the left of the teapot
--> $Box:Box001 @ [-50.000000,0.000000,0.000000]

theFile = (GetDir #temp + @"\teapotAndSphere.max") --define a temp file to save
--> "C:\Users\YOURNAME\AppData\Local\Autodesk\3dsMax\2017 - 64bit\ENU\temp\teapotAndSphere.max"

saveNodes #(t,s,b) theFile --save the three objects to the file
--> OK

resetMaxFile #noPrompt --reset the scene again
--> OK

mergeMAXFile theFile #("Teapot001") --attempt to merge two teapots
--> true
m1 = getLastMergedNodes() --check to see what was merged - only one teapot actually exists in the file
--> #($Teapot:Teapot001 @ [0.000000,0.000000,0.000000])

mergeMAXFile theFile #mergeDups #autoRenameDups --merge all objects, allowing duplicates to be renamed
--> true
m2 = getLastMergedNodes() --see what got merged...
--> #($Teapot:Teapot002 @ [0.000000,0.000000,0.000000], $Sphere:Sphere001 @ [100.000000,0.000000,0.000000], $Box:Box001 @ [-50.000000,0.000000,0.000000])

move m2 [0,100,0] --move the objects merged in the second attempt 100 units along Y
--> OK
select m1 --and select the object from the first merge
--> OK

   

3ds Max Load and Save Dialogs

getMAXSaveFileName [filename:<seed_filename_string>] 

Displays the standard 3ds Max file save dialog, returns the file name selected by the user, or the value 'undefined' if canceled.

If the optional filename: string argument is specified and it contains only a file name pattern, only the files matching the pattern will be displayed. If it also contains a file path, the content of the directory matching the pattern will be displayed.

No actual file saving will be performed, only the name of the selected file will be returned. You can perform the saving by passing the result of this function (as long as it is not 'undefined') as argument to saveMaxFile() documented further on this page.

EXAMPLE

--Open the dialog at the current path (can be found or set via sysinfo.currentdir):
theName = getMAXSaveFileName() 

--Open the dialog at "c:\temp\" and filter by pattern "test*.max"
--The user must click a specific file if the pattern contains wildcards
theName = getMAXSaveFileName filename:"c:\\temp\\test*.max"

--Open the dialog at "c:\temp\" and set the file name to "test.max"
--The user can click the Open button to get the specified file name if it exists,
--otherwise a prompt will show up saying the file does not exist...
theName = getMAXSaveFileName filename:"c:\\temp\\test.max"
--If the result is not undefined, we can actually save the file:
if theName != undefined do saveMaxFile theName

   

getMAXOpenFileName [filename:<seed_filename_string>] [dir:<seed_directory_string>] 

Displays the standard 3ds Max file open dialog, returns the file name selected by the user, or the value 'undefined' if canceled.

If the optional filename: string argument is specified and it contains only a file name pattern, only the files matching the pattern will be displayed. If it also contains a file path, the content of the directory matching the pattern will be displayed.

If the optional dir: string is specified, the dialog will open at the specified path and the File name field will be set to the current scene file name (found in the maxFileName global variable), or will be empty if the scene is still Untitled.

FOR EXAMPLE.

--Open the dialog at the current path (sysinfo.currentdir):
theName = getMAXOpenFileName() 

--Open the dialog at c:\temp and use current file name
theName = getMAXOpenFileName dir:"c:\\temp" 

--Open the dialog at "c:\temp\" and filter by pattern "test*.max"
--The user must click a specific file if the pattern contains wildcards
theName = getMAXOpenFileName filename:"c:\\temp\\test*.max"

--Open the dialog at "c:\temp\" and set the file name to "test.max"
--The user can click the Open button to get the specified file name if it exists.
theName = getMAXOpenFileName filename:"c:\\temp\\test.max"

   

MAX File Object Names

getMAXFileObjectNames <max_filename_string> [quiet:<bool>] 

Returns an array of strings, one for each of the names of the objects in the given 3ds Max file.

This provides a way to get a preview list of the objects in another scene file (by name) to set up user selection of the objects to be merged under script control using the mergeMAXFile() function,

FOR EXAMPLE.

p=[1000,1000,1000]
for i = 1 to 5 do box pos:(random p -p) -- create some boxes
savemaxfile "mergetest.max" -- save to file
for obj in objects do obj.name = "_"+obj.name -- rename the boxes
objects.pos += [0,-1000,0] -- move them off to the side
fobj_names = getmaxfileobjectnames "mergetest.max" -- get the object names from the file
deleteitem fobj_names 3 -- delete the third name from the array
mergemaxfile "mergetest.max" fobj_names #select -- merge in the objects and select them
selection.count -- should be 4
objects.count -- should be 9

getMAXFileObjectNames returns an empty array when the argument is a file with .DRF extension.

For details on the quiet: option, please see Quiet Mode

getMAXFileObjectNames in 3ds Max 7 and higher returns an array of string values, rather than the array of name values in previous 3ds Max versions. The object names used by mergeMaxFile are case sensitive, and name values are not guaranteed to maintain the case of the string they wrap.

Save MAX File

<bool>saveMaxFile <filename_string> [saveAsVersion:<integer>] [clearNeedSaveFlag:<bool>] [useNewFile:<bool>] [quiet:<bool>] 

Saves the scene to the current 3ds Max scene directory if there is no explicit directory path on the supplied file name. If no filename extension is specified, ".max" is automatically appended to the filename.

WARNING!

saveMaxFile() will overwrite existing files with the same name without warning!

See CheckForSave() and doesFileExist() further on this page!

The optional keywords are true by default to match the existing behavior prior to 3ds Max 6, except when saving as a previous version in 3ds Max 2011 and higher where the useNewFile: is assumed false to prevent the previous version file from becoming the current file.

In 3ds Max 2011 and higher, if a valid previous version is specified using saveAsPrevious: , the scene will be saved in the file format of the specified previous version. In 3ds Max 2011 the valid value is 2010. In 3ds Max 2012, the valid values are 2010 and 2011. Any other value will save using the current version's format.

If clearNeedSaveFlag: is set to false , the file is saved, but the need save flag will not be cleared and 3ds Max will still consider the scene as changed and requiring saving.

If useNewFile: is false , the saved file is not set as the current scene file and the file is not put in the Most Recently Used list. This lets you save a backup file of the scene to a different name without the name becoming the current one or appearing on the list of recent files.

For details on the quiet: option which was added to this method in 3ds Max 8, please see Quiet Mode

The method will return true on success or false if the saving failed (for example if attempting to overwrite an existing read-only file) in 3ds Max 8 and higher.

Hold and Fetch

holdMaxFile() 

Equivalent to the 3ds Max Edit > Hold operation.

   

fetchMaxFile [quiet:<boolean>] 

Equivalent to the 3ds Max Edit > Fetch operation. For details on the quiet : option, please see Quiet Mode

   

Checking For MAX File

<bool>isMaxFile <filename_string> 

Returns true if the specified file is a MAX file.

This method tests the internal structure of the file to see if it is consistent with a MAX file.

Returns false if the file is not a MAX file or if the specified file does not exist.

EXAMPLES:

isMaxFile "$scenes/ca_test1.max" --returns true if file exists
isMaxFile "$max/autoback/maxhold.mx" --returns true if file exists
isMaxFile "$matlibs/Nature.mat" --returns true if file exists
isMaxFile (maxFilePath + maxFileName) --returns true unless the scene is Untitled

Importing Files

importFile <filename_string> [#noPrompt] [using:<maxclass>] 

Lets you import files using any of the import plug-ins that are available. The kind of file imported is determined by the file name suffix such as DXF for .dxf , 3DS DOS for .3ds , etc.

The #noPrompt flag prevents any configuration or control dialogs from being displayed in which case the default configuration is used.

If the optional keyword argument using: is supplied, the respective I/O class will be used to perform the import. This can be useful when multiple plug-ins support the same file format extension. Available in 3ds Max 8 and higher.

To see all available importer plug-in classes, you can access the .classes property of the importerPlugin value - it returns an array of all installed importer plug-ins:

EXAMPLES:

print importerPlugin.classes

RESULT:

3D_Studio
3D_Studio_Shape
Adobe_Illustrator_Shape
AutoCADImport
FBXIMP
STL_Import
FileLinkAsDwgImporter
mental_ray_Import
IGES_Import
Wavefront_Object
VrmlImp
ImportTRC
Lightscape_Importer
XMLImp2
ImportHTR
InventorImport
LandXML___DEM_Model_Import
Wavefront_Material

See also the Import and Export Filters topic for MAXScript access to the settings of some Importer and Exporter plugins.

Exporting Files

exportFile <filename_string> [#noPrompt] [selectedOnly:<boolean>] [using:<maxclass>] 

Lets you export files using any of the export plug-ins that are available.

The kind of file exported is determined by the file name suffix such as DFX for .dxf , 3DS DOS for .3ds , etc.

The #noPrompt flag prevents any configuration or control dialogs from being displayed in which case the default configuration is used.

If the selectedOnly keyword parameter is set to true , only selected nodes are exported. Defaults to false .

If the optional using: keyword argument is supplied, the respective I/O class will be used to perform the export. This can be useful when multiple plug-ins support the same file format extension. Available in 3ds Max 8 and higher.

To get an array of all available exporter plug-in classes, you can access the .classes property of the exporterPlugin value:

FOR EXAMPLE,

theClasses =exporterPlugin.classes
exportFile (GetDir #scene + "/exportTest" ) using:theClasses[1]

In the example above, the export will use the first plug-in found in the array, which is by default the 3D_StudioExporterPlugin.

See also the Import and Export Filters topic for MAXScript access to the settings of some Importer and Exporter plugins.

Saving Nodes

<bool>saveNodes <node_collection> <filename_string> [saveAsVersion: <integer>] [quiet:<bool>] 

Creates a new .max scene file with the given name and stores the node collection to it.

The <node_collection> argument can be a single node, an array of nodes you gathered, a wild-card path name, one of the built-in objects sets such as selection or lights , or a <node>.children array.

If no filename extension is specified, ".max" is automatically appended to the filename.

NEW in 3ds Max 2011: If saveAsVersion: provides a value of 2010, the resulting file will be saved in the specified version's file format. Versions prior to 3ds Max 2010 are not supported. If any other value is specified, or if not specified at all, the current version's file format will be used.

For details on the quiet: option which was added to this method in 3ds Max 8, please see Quiet Mode

The method will return true on success or false if the saving failed (for example if attempting to overwrite an existing read-only file) in 3ds Max 8 and higher.

WARNING!

saveNodes() will overwrite existing files with the same name without warning!

See CheckForSave() and doesFileExist() below for solution.

Check For Save

checkForSave() 

If the scene has been modified since the last file save (if any), calling this function displays the message box prompting the user that the scene has been modified and requests to save.

The function returns false if the user cancels out of the save, true otherwise. The function itself does NOT perform any saving, it only issues the prompt if the scene has been modified and returns the user's decision about further actions. Any actual saving or checking for file existence have to be performed by the MAXScript code.

See also Exiting and Resetting3ds Max

WARNING!

saveNodes() and saveMaxFile() will overwrite existing files with the same name without warning!

FOR EXAMPLE

b = box()
saveNodes b "foo.max"
saveNodes b "foo.max"
saveMaxFile "foo.max"
--All these calls will overwrite the file "foo.max"
--without notice.

You should always use doesFileExist() to make sure the target file does not exist and prompt if it does.

Here are two examples of using doesFileExist() for these cases:

SCRIPT:

b = box()
-- if filename exists, ask user if ok to overwrite
-- function returns true if file was saved, false otherwise
fn maybe_saveNodes nodeArray filename =
(
if getFilenamePath filename == "" do
filename = getdir #scene + "\\" + filename
if (not (doesfileexist filename)) or
querybox ("filename: "+filename + "\nexists. Overwrite?") then
(
saveNodes nodeArray filename
true
)
else
false
)

SCRIPT:

fn maybe_saveMaxFile filename =
(
if getFilenamePath filename == "" do
filename = getdir #scene + "\\" + filename
if (not (doesfileexist filename)) or
querybox ("filename: "+filename + "\nexists. Overwrite?") then
(
saveMaxFile filename
true
)
else
false
)

USING THE ABOVE FUNCTIONS:

maybe_saveNodes b "foo.max"
maybe_saveNodes b "foo.max"
maybe_saveMaxFile "foo.max"

See Also