Титульная страница
ISO 9000 ISO 14000
GMP Consulting
 
Mastering 3D Studio MAX R3

Previous Table of Contents Next


Prompt Line

MAX commands use the prompt line to ask the user to perform certain actions, and as an output result of actions. You can also use the prompt line in MAXScript.

You can use PUSHPROMPT to add a string to the prompt line. The previous string will be stored in a temporary buffer. To restore the previous string, you can use POPPROMPT(). For instance, type:

pushprompt “Select Shapes to be trimmed:”

The text string will be displayed in the prompt. If you enter popprompt(), the previous prompt will be restored.

You can use PUSHPROMPT as many times as needed, and the previous prompts will be stored in memory. POPPROMPT() can restore each of them, backwards one at a time, until the first prompt is reached.

The REPLACEPROMPT command will substitute the actual prompt with a specified string, regardless of the usage of PUSHPROMPT and POPPROMPT. The only drawback is that the old prompt cannot be restored; essentially, the POPPROMPT buffer is cleared.

Displaying Calculation Progress

Some plug-ins show a progress bar in the status bar, as seen in Figure 17.6, to show the user that some processing is taking place. You can do this with scripts also.


FIGURE 17.6  Sample progress bar

The PROGRESSSTART command creates a progress bar and sets it to 0%. Its only argument is the title of the progress bar. Then, you need PROGRESSUPDATE to update the progress bar, specifying the actual percentage as an integer number. At the end of the process, you need PROGRESSEND() to remove the progress bar.


WARNING Do not enter progressstart in the Listener, because it may lock MAX and you will not be allowed to cancel the command.

Here is an example script using a progress bar to show the progress of a script. This script will create Editable Mesh vertex animation, moving the vertices sequentially. For instance, it moves vertex 1 in frame 1, vertex 2 in frame 2, and so on. The offset is specified, so you will have the whole object shifted after it ends.

Open the offset_vert.ms file from the CD, or start a new script and type all the commands shown in Listing 17.4.


LISTING 17.4: The Progress Bar script (offset_vert.ms)
utility move_vertex “Move Vertex”
(
local obj2, offset_vert
pickbutton sel “Select Object” width:120
button go “Process” width:120
label verts “”
spinner nov “# verts/frame” type:#integer range:[1,100,1]
label fr “”
spinner x “Offset X”
spinner y “Offset Y”
spinner z “Offset Z”
fn offset_vert sel_obj ox oy oz nov =
 (
 local obj = sel_obj
 n_frames = (obj.numverts/nov)
 if animationrange.end < n_frames then
 animationrange = interval animationrange.start n_frames
 local c_frame = 1
 progressstart “Moving Vertices...”
 setwaitcursor()
 for i in 1 to obj.numverts do
 (
 str3 = (“deletekeys $” + obj.name + “.vertex_” + i as string + \
 “.controller #allkeys”)
 execute str3
 local p = execute (“$” + obj.name + “.vertex_” + i as string)
 local p2 = p + [ox,oy,oz]
 local str = “$” + obj.name + “.vertex_” + i as string + “ = ” + \
 p as string
 local str2 = “$” + obj.name + “.vertex_” + i as string + “ = ” + \
 p2 as string
 animate on
 (
 at time (c_frame-1) (execute str)
 progressupdate ((i*100/obj.numverts))
 at time c_frame (execute str2)
 )
 if (execute (“numkeys $” + obj.name + “.vertex_” + i as string + \
 “.controller”)) > 2 then
 execute (“deletekey $” + obj.name + “.vertex_” + i as string + \
 “.controller 1”)
 if (mod i nov) == 0 then c_frame += 1
 )
 progressend()
 setarrowcursor()
 )
on sel picked obj2 do
 (
 global move_vertex_object = undefined
 move_vertex_object = snapshot obj2
 delete obj2
 animatevertex move_vertex_object #all
 verts.text = (move_vertex_object.numverts as string + “ vertices”)
 fr.text = ((move_vertex_object.numverts/nov.value) as string + “ frames”)
 )
on nov changed value do
 (
 try
 (
 fr.text = ((move_vertex_object.numverts/nov.value) as string + \
 “ frames”)
 )
 catch()
 )
on go pressed do
 try(offset_vert move_vertex_object x.value y.value z.value nov.value) \
 catch()
)

To use this script, create a cone and select it using the script. Then, type 10 in Z, and press Start. After the script is done, play the animation. You will see the vertices moving systematically.

Notice you used execute several times in this script. This is because you need to access the different vertices, and they were accessed using .vertex_n. Notice also the use of the progress bar and the wait cursor. They both let you know that the script is working.

To ensure that the script will work correctly, you also used TRY/CATCH to call the function when the spinner values are adjusted. This is to prevent failure due to missing objects.

File Management

MAXScript has several commands that help us manage files, particularly keeping them filed and being able to locate them.

System Folders

Sometimes you need to know which directory MAX is installed in. This can be done using GETDIR.

GETDIR lists all MAX directories, simply specifying the folder from among these options: #autoback, #drivers, #export, #expression, #font, #help, #image, #import, #matlib, #plugcfg, #preview, #scene, #scripts, #sound, #startupscripts, #ui, and #vpost. #maxroot is used to specify the MAX root folder—in other words, the folder where 3dsmax.exe is located.

If you need to know the scripts’ path, you can use SCRIPTSPATH, instead of getdir #scripts. Both will return the same result.

Paths

Bitmap paths and Xref paths are very important for MAX to work properly. You can add, get, and delete paths for both categories.

MAPPATHS.ADD or XREFPATHS.ADD allows us to add paths to each of the search paths.

MAPPATHS.COUNT or XREFPATHS.COUNT lists how many paths exist in the list of search paths.

MAPPATHS.GET or XREFPATHS.GET lists one of the paths. Each requires an index number.

MAPPATHS.DELETE or XREFPATHS.DELETE removes a path from the search paths. Again, each requires an index number to identify the path.

User Interface

Using MAXScript, you can load and save CUI files. CUI files hold all toolbars and tabs configuration, menu, and Command Panel positions, and all display colors.

You can use CUI.LOADCONFIG to load any CUI file. All it needs is the filename to be loaded. CUI.SAVECONFIG() will save the current UI configuration. CUI.GETCONFIGFILE() will list the current CUI file.

To access UI colors, use GETUICOLOR and SETUICOLOR. Both require an index that will define which UI item that color relates to. Check the Online Help, under User Interface Colors, for a list of all colors you can access.


Previous Table of Contents Next

© 2000, Frol (selection, edition, publication)

 
Rambler's Top100