This feature in MAXScript allows a package of related files, possibly making up a scripted tool, to be bundled and compressed into a single zip format file. This package file can then be run like an ordinary .ms file. Any secondary files, needed by the tool, will be either automatically found in the package or they will be automatically extracted to specified locations prior to running the main tool scripts.
The file type for script packages is '.mzp'. These files are recognized as executable script files in the following situations:
Auto-loading at MAX startup, in scripts\startups, stdplugs\stdscripts, etc. any .mzp file found is run.
Choosing the Run Script menu item in the main MAXScript menu, or in the Listener menu, now shows .mzp files as one of the default kinds of executable files in the Open Script dialog and will run it if selected.
Specifying a fileName: parameter when adding a callBack script.
As executable files inside other .mzp archives, you can nest them if want.
using the fileIn
The package startup control file is 'mzp.run'. When a .mzp package is opened, it is scanned for an 'mzp.run' file and, if found, the package commands in it are executed in sequence.
If there is no mzp.run control file in the package, MAXScript will unzip all the files in it to a unique temporary directory in the system temp directory and run all the executable script files it finds, in unspecified order. The kinds of rundle script files in a .mzp package are .ms, .mse and nested .mzp files.
When the contents of the .mzp file is extracted to a destination folder, either the default temp folder or one defined in the mzp.run control file, MAXScript will build and replicate any folder structure that is present in the .mzp file.
When you cause a script file inside the package to be run, either through 'run' commands in the mzp.run file, or by the default running scheme described in the previous item, the package becomes a search context for files that the script may try to open while it is running such things as image .bmp files, include files, etc. Only files named by relative path names are searched for in the package, fully specified paths (with device names at the front) will be looked for at the specified location.
The names of files and directories in commands that take them now can be supplied WITHOUT surrounding double quotes if the name contains only the following kinds of characters:
alphanumeric, '_', '$', '*', '.', '-', '\'
which covers most file names. Any file names with embedded spaces or punctuation not in the above list needs double-quotes.
name "test package"
treeCopy flobber to $scripts
copy *.ms to $scripts\flobber\dobber
move foo.max $scenes
The zip package is a text file that contains one or more of the following commands. All are optional.
Names the package.
Describes the package. Normally, a readme file in the package would give extended operating instructions, if they are provided.
Returns the version number of the package.
Specifies the location in which to extract the contained files. This can be an absolute path name (starting with a drive letter or \) or a relative name. Relative names are taken as being relative to the default temp directory. The special prefix $max can be used to specify the main MAX executable directory
If the package is launched from a MAXScript run menu item or via a fileIn() function, run the named script file. There can be more than one run command and they are run in order. These are ignored if the package is launched via a fileIn() call that is supplied with an explicit script file to run. During the execution of an mzp.run file, any 'run' commands are ignored. See mzp drop protocol for details.
If the package is launched by drag-and-drop into MAX, run the named dropScript file. There can only be one of these per msp.startup file.
Copies the named file or
files (if the
Cause the temporarily-extracted files to be deleted once all the nominated scripts are run or dropped.
clear temp on MAX exit?
Cause the temporarily-extracted files to be deleted when the currently running MAX session exits.
clear temp on reset?
Cause the temporarily-extracted files to be deleted when a file open or reset is performed.
Prevents any deletion of the extracted files.
Opens the named MAX scene file.
During the execution of an mzp.run file, any 'open' commands are ignored. See mzp drop protocol for details.
Merges the named MAX scene file.
During the execution of an mzp.run file, any 'merge' commands are ignored. See mzp drop protocol for details.
Xrefs the named MAX scene file.
During the execution of an mzp.run file, any 'xref' commands are ignored. See mzp drop protocol for details.
Imports the named file.
During the execution of an mzp.run file, any 'import' commands are ignored. See mzp drop protocol for details.
Only one 'open' or 'import' command may be used per mzp.run file. Any number of 'merge' and 'xref' commands can be used.
The following functions will perform searches for files given as relative file names in the current package file:
Any saves will not go back into the package, but into the temp extracted file.
The following UI items will search for named bitmap .bmp files in the package:
Relative file names can contain path names, so
would search in the "libs" sub-folder in the extracted package for "myFns.ms". You can arrange the contents of the package in any kind of folder nesting desired and file names in running script or in the mzp.run control file are relative to the package directory structure.
Copy and Move:
These cause files from within the package to be copied or moved as specified. The treeCopy & treeMove variants move whole nested directories of files. By default, any existing files in the destination location are replaced with the newly extracted ones, add the 'noReplace' keyword to prevent this.
The file path names you can specify in the various commands (extract to, run, copy, move, etc.) can have a starting path that is one of several special names beginning with $. These name useful locations in the currently running MAX installation.
The $ names recognized are:
$max - main MAX executable directory
$maps - first directory in Maps directory config
$scenes - scenes directory
$fonts - fonts directory
$imports - imports directory
$sounds - sounds directory
$matlibs - matlibs directory
$scripts - scripts
$startupScripts - auto-load startup scripts
$plugins - first in the Plug-ins directory config
$plugcfg - plugcfg
$images - images
$ui - UI
$macroScripts - macroScripts in UI directory
$web - web directory
$temp - system temp directory
These directories reflect any customization the user has set up in the various preference dialogs.
If you had set up a package with several scenes, plug-ins & map files in several directories in the package, you could install them with some move commands in the mzp.run file, something like this:
move "plug-ins\*.*" to "$plugins"
move "*.max" to "$scenes"
move "texmaps\*.bmp" to "$maps"
As an added feature, if the scripts run from within a package define any functions, macroScripts, plug-ins, rollouts, or any major MAXScript value or construct that might live longer that the running script, then the package is 'associated' with that defined value or construct and will again become the initial search location whenever the functions or handlers in the rollouts/plug-ins/macroScripts/etc. are later run.
You can initially create a .mzp with a zip utility such as WinZip. You can then associate that utility with the .mzp type, so simple double-clicking a .mzp file will open it in that editor. You only need to set up this association once, and you can do this in the Windows Explorer by selecting a .mzp file, shift-right-clicking on the selected file and choosing "Open with..." in the popup menu that appears. Scroll the application list that appears to find you desired zip utility and check the "Always use this program ..." checkbox at the bottom of the dialog.
The MAXScript zip package interface has exposed 2 MAXScript-callable functions:
The 'fileInPackage' function is essentially the equivalent of:
will return true if success or false if there is a failure, or a
missing or invalid .mzp file, and it will also return the directory
that the package file were extracted to in the pass-by-reference
local extractDir = ""
if msZip.fileInPackage "foo.mzp" &extractDir then
-- extractDir contains the extracted-to directory name
The 'unloadPackage' function performs an extract and executes all the file copying and moving commands in any enclosed mzp.run file, but will not execute any scripts in the package. The extractTo directory and any 'drop' command file found will be returned in the pass-by-reference arguments.
local extractDir = "", dropFile = ""
if msZip.unloadPackage' "foo.mzp" &extractDir &dropFile then
-- extractDir contains the extracted-to directory name
-- dropFile contains any found drop file name (the path to extracted location )
i-drop - drag and drop