Site Navigation

BackTechnical Solutions


Advanced Search
E-mail This Page

Batch conversion of .3DS files to .MAX files with MAXScript

Summary: This document defines and discusses, for MAXScript beginners, a script that will batch convert files from the 3DS for DOS file format to the 3D Studio MAX 2.x and VIZ 2 file format.
Product(s) Release(s) Platform(s)
3D Studio MAX (TM) 2.0, 2.5 Win95, WinNT
3D Studio VIZ 2.0 Win95, WinNT
Audience: For Public Distribution – Global
Keywords: 3DS MAX MAXScript 5512
Related documents: None
Document: US-XT-TD805512.DOC Revision: A
Creation date: November 5, 1998 Last revised: January 18, 1999  Expires: February 28, 2000

The tips, tricks, examples and suggestions outlined in Autodesk Product Support technical documents are suggested for use at your own risk. Document contents are subject to change without notice. Autodesk is not responsible or liable for damage or events that may occur as a result of following suggestions from any Autodesk Product Support technical document.
© 1999 Autodesk. Autodesk and the Autodesk logo are registered trademarks of Autodesk Inc. All other brand names, product names or trademarks belong to their respective holders.

Table of Contents

Overview

You may need to create a script to import 3D Studio for DOS files into 3D Studio MAX 2.x or 3D Studio VIZ 2 file format. This document will explain how to do this by creating an example script. It will also explain how to save preview images for use with the Asset Manager. This document contains example code for defining a browser for input and output directories, as well as an example of directory path syntax.

The document first explains defining and running the script then discusses each section of the script in detail. See the MAXScript Reference for further information on any of the functions used in this script. To use MaxScript, select the Help Menu, then MAXScript Reference. When the Index tab displays, you can then perform a search.

Defining the Script

This section explains how to define a script by creating an example script.

Discussion of script

This section will explain each part of the script that was created in the previous section. The description of the code will follow each section of code.
 
 
resetMaxFile #noPrompt

This resets the current session without further prompting to ensure a new start. This option can be commented out.


Tip: ‘Commenting’ is a method of including text in code that the program ignores. This is useful for commenting on lines of the code as you write it and for disabling parts of a routine without deleting the code. In MAXScript, the comment symbol is two dashes [ -- ]. MAXScript ignores whatever follows the two dashes as it evaluates that line of code. Comments only last for one line of code. You will see many comments in MAXScripts; they are the programmer’s notes to you. In this example you could type [-- resetMaxFile #noPrompt] to ‘comment out’ the reset command.
-- FUNCTION DECLARATIONS
-- A function used to modify file names containing '\' to "\\"
fn replaceChar str oChar rChar = 
    (
        tStr = ""
        for i=1 to str.count do
        (
            if str[i] == oChar then tStr += rChar
            else tStr += str[i] 
        )
        TStr
    )
This is the function declaration section. There is only one custom function defined for this script. The replaceChar function replaces the single backslashes in a string with double backslashes, so they will work with the MAXScript syntax for directory structure. In MAXScript, a single backslash signifies the line continuation character, while double backslashes signify a single '\' character.

Note: See the MAXScript Reference for a discussion of Language Tokens and syntax. To do this, search in the index tab for ‘Strings’ and ‘Source Code Layout and Continuation Lines’.
-- USER INTERFACE ITEMS
button btnTargetDir "Where to save .MAX files"
button btnSourceDir "Where are the .3DS files" enabled:false
These lines add two buttons to the utility rollout, allowing you to choose the target directory for the converted .MAX files. This also allows you to choose the source directory of the .3DS files. This opposite order of the buttons is necessary, since the function called by the btnSourceDir button requires that the target directory be pre-defined. You can work around this by choosing a target directory if the target is undefined.
on btnTargetDir pressed do
(
    target = getSavePath caption:"Select directory for .MAX files:"
    if target == undefined do return false
    btnTargetDir.text = ("Target =" + target)
    btnSourceDir.enabled = true
)
These lines are specifying the target directory button being selected. A variable named target is assigned to the getSavePath browsing action. getSavePath is a built-in function, which invokes the familiar Windows Explorer browsing interface. Once the target directory is chosen, the button takes that name, and the .3DS source directory becomes available for input.
on btnSourceDir pressed do 
(
    local dir = getSavePath caption:"Select which directory \
        holds the .3DS files:"
    if dir == undefined do return false
These lines are specifying the source directory button being selected. A variable named dir is assigned to the getSavePath browsing action. Notice the use of the single backslash as a line continuation character.
files = getFiles ( (replaceChar (dir as string) "\\" "\\\\") + "\\*.3DS" )
    for f in files do 
        (
        ResetMaxFile #noPrompt
        ImportFile f #noPrompt
        max views redraw
        saveMaxFile (target + "\\" + getFilenameFile f + ".MAX")
        )
        btnSourceDir.text = ("Source =" + dir)
    )
)

Another variable, files, is assigned to the .3DS files in the source directory path. The argument for the getFiles function is an expression, which reformats the source directory path to the double backslash convention and looks for files of the .3DS extension. If the source path that the user browsed to was: This expression will reformat that to read: For all the .3DS files listed in the files variable, the scene is reset and the file is imported. The scene is redrawn, to create a preview for the Asset Manager. The file is then saved. The argument for the saveMaxFile function is also an expression, which appends the target variable with the filename (stripped of paths) and the .MAX extension.

This is only example code, and can be refined in error handling or for your interface. 

 Was this article helpful?
(very helpful) 421 (not helpful) 
Top of Page

Home | Products | Tech Assist | Autodesk | Prof Net | Search | Sitemap | Purchase

© Copyright 1999 Autodesk, Inc. All rights reserved.
Autodesk legal notices and trademark attributions.
Reproduction or copying of images is prohibited.
Autodesk Privacy Policy

Comment on Technical Assistance