|
|||||||||||||||||||||||||||||||||||||||||||||
To update the Xref object, you simply use UPDATEXREF obj, where obj is the proxy object name. This will load the Xref file and update the mesh on screen if any change has occurred to the original. Xref Scene The Xref scene works just like the Xref object, except that it is not an object you can select. To add Xref scenes, use XREFS.ADDNEWXREFFILE. The only parameter required is the filename. To access the scenes parameters, you can assign them to variables at the creation time, or you can read their values later, using XREFS.GETXREFFILE index, where index is the number of the Xref. To know how many Xref scenes you have loaded, you can use XREFS.GETXREFFILECOUNT. For instance, you could Xref the Creature scene. To do so, youd use creature = xrefs.addnewxreffile “Creature.max” You can access and set all properties that appear in the Xref Scene dialog box. For instance, wed create a dummy and bind the Xref to it using d = dummy() creature.parent = d We can also turn on Automatic Update using creature.autoupdate = true MAXScript can also access all objects inside an Xref file. This is read-only access, so you will not be able to change any information. You will now write a script that will copy all materials in an Xref scene to the Material Editor Samples (see Figure 17.4).
Open the copy_xref_materials.mcr file from the CD, or start a new script and type all the commands shown in Listing 17.3.
LISTING 17.3: The Xref to Medit script (copy_xref_materials.mcr) Macroscript Read_Xref_Materials category:“Tools” tooltip:“Copy all Xref Scene Materials to Medit” ( Rollout read_xrefmat_rollout “Parameters” ( local selected_xref = 1 Listbox xref_list “Xref Scenes” width:280 height:10 align:#center button go “Copy Materials” width:280 enabled:false align:#center on read_xrefmat_rollout open do ( local n = xrefs.getxreffilecount() local l = #() for i in 1 to n do append l (xrefs.getxreffile i).filename xref_list.items = l ) on xref_list selected x do ( selected_xref = x go.enabled = true) on go pressed do ( local yn = false yn = querybox “Do you want to overwrite the Material Editor?” \ title:“Overwrite Alert!” if yn then (local xref_scene = xrefs.getxreffile xref_list.selection local n = xref_scene.tree.children.count local lib = materiallibrary() for i in 1 to n do append lib xref_scene.tree.children[i].material if lib.count <= 24 then n = lib.count else n = 24 for i in 1 to n do meditmaterials[i] = lib[i] ) ) ) try (closerolloutfloater read_xrefmat_floater) catch() global read_xrefmat_floater read_xrefmat_floater = newrolloutfloater “Xref Materials to Medit” 330 253 addrollout read_xrefmat_rollout read_xrefmat_floater ) The script uses a listbox that will list all Xrefs available in the scene. The list is created in the on open action and added to the UI. Then the user is asked to select an Xref in the list. Notice that if an Xref is not selected, the Go button is not enabled. When the user presses Go, the script uses a querybox to make sure they know that all slots in the Material Editor will be overwritten. If the user clicks yes, the script creates a temporary material library with the materials from the Xref scene and copies it to the Material Editor. It is important to notice that you need to test to see how many materials are in this library, before you copy its contents to the Material Editor. Otherwise, if you had more than 24 materials, you would have crashed the script,since there are only 24 slots in the Material Editor.
Customizing ViewportsYou can control the viewport layout and the viewport type using MAXScript. It is also possible to adjust several parameters in each viewport. Viewport LayoutYou can set 14 different viewport layouts using MAXScript. This is done using viewport.setlayout layoutname. Layouts are named as shown in Table 17.2.
Hands-on MAXScript: Adding Viewport Layouts to the Shortcut Menu You can add options to set the viewport layout using the Ctrl+right-click shortcut menu, shown in Figure 17.5.
To do so, Ctrl+right-click anywhere in your screen and select Customize Menu. Answer Yes in the dialog box that follows, then add these lines below separator sep_222: Submenu “Viewport Layout” ( menuitem mi_layout1 “Single Viewport” separator vpl_1 menuitem mi_layout2v “2 Viewports - Vertical” menuitem mi_layout2h “2 Viewports - Horizontal” menuitem mi_layout2ht “2 Viewports - Top Smaller” menuitem mi_layout2hb “2 Viewports - Bottom Smaller” separator vpl_2 menuitem mi_layout3vl “3 Viewports - 2 Left” menuitem mi_layout3vr “3 Viewports - 2 Right” menuitem mi_layout3ht “3 Viewports - 2 Top” menuitem mi_layout3hb “3 Viewports - 2 Bottom” separator vpl_3 menuitem mi_layout4 “4 Viewports” menuitem mi_layout4vl “4 Viewports - 3 Left” menuitem mi_layout4vr “4 Viewports - 3 Right” menuitem mi_layout4ht “4 Viewports - 3 Top” menuitem mi_layout4hb “4 Viewports - 3 Bottom” ) These will add a submenu with options for all possible viewport layouts. Now create the actions. Below the line that reads Start Custom button picks, add: on mi_layout1 picked do viewport.setlayout #layout_1 on mi_layout2v picked do viewport.setlayout #layout_2v on mi_layout2h picked do viewport.setlayout #layout_2h on mi_layout2ht picked do viewport.setlayout #layout_2ht on mi_layout2hb picked do viewport.setlayout #layout_2hb on mi_layout3vl picked do viewport.setlayout #layout_3vl on mi_layout3vr picked do viewport.setlayout #layout_3vr on mi_layout3ht picked do viewport.setlayout #layout_3ht on mi_layout3hb picked do viewport.setlayout #layout_3hb on mi_layout4 picked do viewport.setlayout #layout_4 on mi_layout4vl picked do viewport.setlayout #layout_4vl on mi_layout4vr picked do viewport.setlayout #layout_4vr on mi_layout4ht picked do viewport.setlayout #layout_4ht on mi_layout4hb picked do viewport.setlayout #layout_4hb These will define the actions that will change the layout to any possible combination of viewports. Using VIEWPORT.RESETALLVIEWS will reset the layout to the default.
© 2000, Frol (selection, edition, publication) |
|||||||||||||||||||||||||||||||||||||||||||||
|