|
|||||||||
Querybox Sometimes we might need a more complex alert box. We also have a way to ask the user which direction to follow, using a Yes or No alert box. This is a querybox. Continuing to use the previous example, we can ask the user whether he wants us to assign a standard material to the object, if the object has no material. Lets do it, as in Figure 15.10.
Substitute the line we edited previously with the following ones: query = false if obj.material == undefined then ( query = querybox Assign a default Standard Material to the object? \ title:Object has no material assigned if query == true then obj.material = standardmaterial() ) else query = true if query == true then We created a variable called query. If the object has no material, we ask the user if he wants us to assign a default material to it. If the user chooses Yes, the variable value will be true. Then, well assign the material and the script will process the rest. If the user chooses No, the variable value will be false, and the script will not proceed. In case the object already has a material assigned, the script will skip the querybox and will assign true to the variable, so it can proceed. This version of the script is saved as utility_bump3.ms on the CD. Yesnocancelbox A yesnocancelbox is the same as the querybox, but also has a cancel button. Instead of returning true or false, itll return #yes, #no, or #cancel. Building RolloutsRollouts are used when we have too much information and we want to organize it better. A good example is SuperSpray; its parameters are organized through rollouts, grouping like items together and rolling them up to save space. A rollout is self-contained. All actions related to all UI items must be performed for each rollout, but there are ways to access other rollouts UI items values also. For instance, suppose you have the following rollouts: rollout r1 Rollout 1 ( button b1 First Button ) rollout r2 Rollout 2 ( button b2 Second Button ) You could not use on b1 pressed do while in the second rollout (r2), because this button only exists in the first rollout (r1). On the other hand, you can enable or disable it using r1.b1.enabled = false ; by adding the rollout name before the UI item, you can access and change its properties. Adding and Removing RolloutsEvery utility has a rollout automatically, but we can add as many more rollouts as needed to each utility. The rollouts we add work exactly the same as the utilitys main rollout, but more rollouts only appear when explicitly added to a utility or a floater. To add or remove rollouts we can use ADDROLLOUT and REMOVEROLLOUT. The following script is an example of adding and removing rollouts; its output is shown in Figure 15.11.
rollout first First Rollout ( label f This is the First Rollout ) rollout second Second Rollout ( label s This is the Second Rollout ) utility main Main Utility ( radiobuttons menus labels:#(First,Second) on main open do addrollout first on main close do ( removerollout first removerollout second ) on menus changed state do ( case state of ( 1: ( removerollout second addrollout first ) 2: ( removerollout first addrollout second rolledup:true ) ) ) ) In the second rollout, we added the rolledup option. Itll define whether the rollout starts out opened or not. Notice we also used two more events: on main open and on main close. Theyre events to be executed when the utility is opened and closed. You can use them with utilities and rollouts. FloaterInstead of using rollouts in utilities, we can use them in floaters. Floaters are dialog boxes with several rollouts; they look like areas from the Command Panel but float separately in the MAX window. An example of a floater is the Batch Renderer. We can create a floater using the NEWROLLOUTFLOATER command and close any floater using CLOSEROLLOUTFLOATER. NEWROLLOUTFLOATER requires a caption string and the floater width and height (see Listing 15.4 for an example of this command). Lets adjust the script we created to Divide Splines in Chapter 14 and make it a rollout floater script. Well need two UI items: a pickbutton to select the object and a spinner to specify the number of segments (the final result is shown in Figure 15.12).
Open a new script and type all the commands shown in Listing 15.4, or access this code on the CD that accompanies this book, in the file named floater_ divideshape.ms.
LISTING 15.4: The Floater script (floater_divideshape.ms) rollout divide_params Parameters ( pickbutton pick_shape Select Shape Object width:160 spinner steps Steps: range:[3,1000,10] type:#integer enabled:false fn convert_it shp = ( x = shp tmp = copy x pick_shape.text = shp.name obj = converttosplineshape tmp ns = numsplines obj nv = numknots obj size = steps.value ratio = 1.0/size if ss != undefined then delete ss ss = splineshape() ss.name = x.name + _Divided ss.wirecolor = x.wirecolor ss.pivot = x.pivot for i in 1 to ns do ( addnewspline ss for j in 1 to size do ( pt = lengthinterp obj i (ratio*(j-1)) addknot ss i #smooth #curve pt ) if (isclosed obj i) then close ss i else ( pt = lengthinterp obj i 1.0 addknot ss i #smooth #curve pt ) updateshape ss ) delete tmp ) on pick_shape picked shp do ( ss = undefined x = shp convert_it x steps.enabled = true ) on steps changed val do ( convert_it x ) ) try (closerolloutfloater divide) catch() divide = newrolloutfloater Divide Splines 200 116 addrollout divide_params divide Basically, the spline creation is defined as a function that will be called from either the pickbutton or the spinner. When we pick a new shape, we define ss = undefined, resetting the function and creating a new spline. In addition, when selecting an object, we enable the spinner so the number of segments can be adjusted. As always, some new concepts were introduced here. We used TRY and CATCH to make sure the floater was closed before opening a new one. TRY tests the function and CATCH will execute another function if the one that was tried didnt work. In our situation, well not have any function inside CATCH. If we did not use this, executing the script would create many floaters, one on top of the other.
© 2000, Frol (selection, edition, publication) |
|||||||||
|