|
|||||||||||||
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.
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.
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 ManagementMAXScript 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 folderin 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.
© 2000, Frol (selection, edition, publication) |
|||||||||||||
|
|||||||||||||