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

Previous Table of Contents Next


External Commands

MAXScript can execute external programs and applications. You can execute DOS commands and applications.

To execute DOS commands, as well as to execute BAT files or CMD files, you can use DOSCOMMAND. It requires a simple string that will be the command executed. For instance, doscommand “dir c:\\maps\\anim*.jpg /b >anim.ifl” will create an IFL file with all anim*.jpg files present in the specified folder.

You can also start applications and specify parameters to this application. To do so, you can use SHELLLAUNCH. It will start any application either directly or through association, and allows us to specify a command-line parameter to this application. For instance, shelllaunch “d:\\movies\\anim_qt3.mov” will start QuickTime or any other associated program and open this video.


NOTE Always remember to use \\ instead of a single backslash in path names.

Scene Properties

MAXScript also can access Scene Properties. This way, you can assign the properties through scripts, and create a utility that would help us manage our assets.

To access these properties, you use FILEPROPERTIES.command, where command can be a series of commands to get, set, find, and remove properties. The File Properties dialog box (see Figure 17.7) is divided into three tabs: Summary, Contents, and Custom. You access these as #summary, #contents, and #custom.

You can use FILEPROPERTIES.ADDPROPERTY to add properties to each of the sections. For instance, fileproperties.addproperty #summary “Title” “Animation Project” will add this text to the Title field in the Summary section. The Summary section has the following fields: Title, Subject, Author, Keywords, and Comments. The Contents section is where you can edit Manager and Company, despite the fact that they are also located in the Summary page in the File Properties dialog window.


TIP Use MAX HOLD after changing any property in the Contents section, since they are only updated when saved.


FIGURE 17.7  The File Properties dialog window

To retrieve a property’s value, you can use FILEPROPERTIES.GETPROPERTYVALUE, but to do so, you need to know the index of the property. This is done using FILEPROPERTIES.FINDPROPERTY. If a property does not exist, it will return 0; if the property does exist, it will return the index of that property.

For instance, you can add some properties and retrieve their values later:

fileproperties.addproperty #summary “Title” “Animation Project”
fileproperties.addproperty #summary “Subject” “First Shot”
fileproperties.addproperty #summary “Author” “Chris Murray”
t = fileproperties.findproperty #summary “Title”
v_value = fileproperties.getpropertyvalue #summary t

As you can see, the correct property value was retrieved and stored in v_value.

Let’s create a script that will manage our files, requiring the user to enter the information to be saved in the file, as seen in Figure 17.8.


FIGURE 17.8  Properties Manager script

Open manage_properties.ms from the CD, or start a new script and type all the commands in Listing 17.5.


LISTING 17.5: The Properties Manager script (manage_properties.ms)
rollout manage_properties_rollout “Properties”
(
label company “CME 3D Enterprises”
edittext manager fieldwidth:200 align:#right
label man “Manager:” offset:[0,-20] align:#left
edittext title fieldwidth:200 align:#right
label tit “Title:” offset:[0,-20] align:#left
edittext subject fieldwidth:200 align:#right
label sub “Subject:” offset:[0,-20] align:#left
edittext author fieldwidth:200 align:#right
label aut “Author:” offset:[0,-20] align:#left
button edit “Edit values” width:98 offset:[-26,0] enabled:false
button ok “Exit” width:98 offset:[75,-26]
on manage_properties_rollout open do
 (
 fileproperties.addproperty #contents “Company” company.text
 fn read_properties section header UI =
 (
 local m = fileproperties.findproperty section header
 if m > 0 then
 (
 try
 (
 UI.text = fileproperties.getpropertyvalue section m
 UI.enabled = false
 )
 catch(UI.enabled = true)
 )
 )
 read_properties #contents “Manager” manager
 read_properties #summary “Title” title
 read_properties #summary “Subject” subject
 read_properties #summary “Author” author
 if manager.enabled == false or title.enabled == false or \
 subject.enabled == false or author.enabled == false then
 edit.enabled = true
 )
on manage_properties_rollout oktoclose do
 (
 return_value = true
 if manager.text == “” or title.text == “” or subject.text == “” or \
 author.text == “” then
 (
 messagebox “Please, all fields need to be filled.”
 return_value = false
 )
 else
 return_value = true
 return_value
 )
on edit pressed do
 (
 manager.enabled = true
 subject.enabled = true
 author.enabled = true
 title.enabled = true
 )
on manager entered text do
 (
 fileproperties.addproperty #contents “Manager” manager.text
 max hold
 )
on title entered text do
 (
 fileproperties.addproperty #summary “Title” title.text
 )
on author entered text do
 (
 fileproperties.addproperty #summary “Author” author.text
 )
on subject entered text do
 (
 fileproperties.addproperty #summary “Subject” subject.text
 )
on ok pressed do
 (
 closerolloutfloater manage_properties_floater
 )
on oktoclose manage_properties_rollout do
 (
 return_value = false
 if manager.text == “” or title.text == “” or subject.text == “” or \
 author.text == “” then
 messagebox “Please, all fields need to be filled.”
 else return_value = true
 return_value
 )
)
fn initiate_manage_properties =
 (
 callbacks.removescripts id:#manage_properties
 callbacks.addscript #systempostnew “initiate_manage_properties()” \
 id:#manage_properties
 callbacks.addscript #systempostreset “initiate_manage_properties()” \
 id:#manage_properties
 callbacks.addscript #filepostopen “initiate_manage_properties()” \
 id:#manage_properties
 try(closerolloutfloater manage_properties_floater) catch()
 manage_properties_floater = newrolloutfloater “File Properties” 300 200
 addrollout manage_properties_rollout manage_properties_floater
 )
initiate_manage_properties()

You can now save this script in the Startup folder. When any new file starts, you will be asked to enter this data. The callbacks are used to allow this to happen when the system is reset, a file is opened, or a new file is created.

Notice you used a new event handler for the rollout. It is an oktoexit event. It allows us to check whether the user can or cannot close the dialog box. In our case, the user can only close the window if all fields are filled. To do this we set return _value = false, and if the user can close the dialog box, we set return_value = true. Then, the last line passes return_value as an argument to the event, which controls whether the dialog box can be closed.

You also created an exit button, which calls CLOSEROLLOUTFLOATER. You can enhance this script, adding more fields to be filled, or automating some fields, like Author or Manager, if they are always the same people.

If you prefer not to have this script starting automatically, you can remove the callbacks, remove it from the Startup folder, and create a Macro Script for it.

Summary

MAXScript can help us in many more areas than direct object manipulation. You can create scripts to do virtually anything in scene and asset management, working with files, folders, events, etc.

In the next chapter, you will learn how to create plug-in scripts to create geometry, modifiers, and render effects.


Previous Table of Contents Next

© 2000, Frol (selection, edition, publication)

 
Rambler's Top100