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.
|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|
|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
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.
utility u3DS_to_MAX "Convert .3DS to .MAX" ( -- 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 ) -- USER INTERFACE ITEMS button btnTargetDir "Where to save .MAX files" button btnSourceDir "Where are the .3DS files" enabled:false 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 ) on btnSourceDir pressed do ( local dir = getSavePath caption:"Select which directory \ holds the .3DS files:" if dir == undefined do return false 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) ) )4. Save the script as 3DS_to_MAX.ms by selecting the File menu, then Save.
5. Run the script by selecting the File menu, then Evaluate All. All the commands in the script will be executed as if they were manually input.
6. Select the MAXScript rollout, then ‘Convert .3DS to .MAX’ from the Utilities panel drop down list. A rollout of the same name will display.
Tip: A shortcut for evaluating one line of text in a script is to place the cursor at the end of that line in the script and press and hold the Shift button while pressing the Enter key. To evaluate multiple lines, highlight the area and press and hold the Shift button while pressing the Enter key. The Enter button on the number keypad also evaluates lines of code.
7. Select ‘Where to save .MAX file’ and browse to the directory where you want the new .MAX files to be saved.
Note: You must activate the drop down menu and select ‘Convert .3DS to .MAX’.
8. Choose the ‘Where are the .3DS files’ button.
Note: The button will take the name of the target directory.
9. Browse to the directory where the .3DS files reside. Once you have selected the source directory, the conversion automatically begins. The .3DS files are converted to .MAX files.
10. Open the Asset Manager and browse to the target directory, filtering for .MAX files. You will see previews of the new .MAX scenes.
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.
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:falseThese 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 falseThese 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 is only example code, and can be refined in error handling or for your interface.
| Was this article helpful?
(very helpful) 5 43 21 (not helpful)
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.
Comment on Technical Assistance