5.8 KiB
MzTranslator
Maya .mz file format Translator plugin, developed using Maya Python API. This plugin allows Maya to read and write .mz files, which are ZIP-compressed archives containing Maya ASCII (.ma) files.
File Format
.mz files are ZIP compressed archives that contain a data.ma file (Maya ASCII format). This format provides:
- Compression: Reduces file size compared to plain
.mafiles - Single file: All scene data in one archive
Directory Structure
d:/workspace/MzTranslator/
├── MzTranslate.mod # Maya module definition file
├── setup.py # Setup configuration (Cython build)
├── plug-ins/
│ └── mz_translator.py # Plugin entry point (MPxFileTranslator)
├── python/
│ └── mz_core/
│ ├── __init__.py # Module initialization & exports
│ ├── reader.py # Reader module (extract .mz to temp)
│ ├── reader.c # Reader C extension (compiled)
│ ├── writer.py # Writer module (export scene to .mz)
│ └── writer.c # Writer C extension (compiled)
├── plans/
│ └── plan.md # Project architecture plan
├── .vscode/
│ └── settings.json # VS Code settings
└── README.md # This documentation
Project Components
MzTranslate.mod
Maya module definition file that defines the module name and Python path.
plug-ins/mz_translator.py
Main plugin entry point that:
- Implements
MzFileTranslatorclass inheriting frommaya.api.OpenMayaMPx.MPxFileTranslator - Registers the plugin with Maya via
initializePlugin()anduninitializePlugin() - Provides file identification via
identifyFile() - Handles writing via
writer()method - Handles reading via
reader()method - Provides export options UI via
optionsScript()
python/mz_core/
init.py
Module initialization that exports:
read_scene_from_mz- Read scene from .mz fileread_to_temp_file- Extract .mz to temporary fileget_file_info- Get .mz file informationwrite_scene_to_mz- Write scene to .mz fileget_export_options- Get export options
reader.py
Reader module that:
read_scene_from_mz()- Reads .mz file, returns content or writes to bufferread_to_temp_file()- Extracts .mz to temporary directoryget_file_info()- Returns file size and archive contents
writer.py
Writer module that:
write_scene_to_mz()- Exports current Maya scene to .mz file_export_to_ma()- Exports scene as Maya ASCII formatget_export_options()- Returns compression level options
Installation
Method 1: Direct Python Module Loading
Execute in Maya's Python Script Editor:
import sys
# Add plugin path
plugin_path = 'd:/workspace/MzTranslator'
if plugin_path not in sys.path:
sys.path.insert(0, plugin_path)
# Load plugin
import plug-ins.mz_translator as mz_translator
import maya.cmds as cmds
cmds.loadPlugin(mz_translator.__file__)
Method 2: Using PluginManager
- Open Maya
- Go to
Window > Settings/Preferences > Plugin Manager - Click
Browseto findmz_translator.pyin theplug-insfolder - Check
Loadedto load the plugin
Method 3: Maya Module (Optional)
Copy MzTranslate.mod to Maya's modules directory and configure the path.
Usage
Save/Export
- Select
File > Save As...orFile > Export All... - Select
MayaZip (*.mz)from the file type dropdown - Choose save location and click
Save - Configure compression level in the options dialog (0=none, 9=maximum)
Open/Import
- Select
File > Open...orFile > Import... - Select
MayaZip (*.mz)from the file type dropdown - Select the
.mzfile and clickOpen
Features
- Read Support: Extract and read
data.mafrom.mzfiles - Write Support: Export Maya scenes to
.mzfiles with compression - Export Options: Configurable compression level (0-9)
- File Identification: Automatic detection of
.mzformat - Temporary File Management: Automatic cleanup of temporary files
Technical Details
writer.py
- Uses
tempfileto create temporary directory - Uses Maya's
cmds.file()to export as.maformat - Uses
zipfileto compressdata.mainto.mz - Supports configurable compression levels (0-9)
reader.py
- Uses
zipfileto read.mzfiles - Extracts
data.mato temporary directory - Uses Maya's
MFileIOorcmds.file()to read the scene - Auto cleanup temporary files via
SceneClosedscriptJob
mz_translator.py
- Inherits
maya.api.OpenMayaMPx.MPxFileTranslator - Implements all required virtual methods
- File translator name: "MayaZip"
- Extension: "mz"
- Provides export options UI dialog
Requirements
- Maya 2017 or later
- Maya Python API
- Python standard library (zipfile, tempfile, os, etc.)
Version Info
- Version: 1.0.0
- API: Maya Python API (OpenMayaMPx)
- Supported Maya versions: 2017+
Troubleshooting
Issue: Plugin fails to load
Verify plugin path is correct:
import plug-ins.mz_translator as mz_translator
print(mz_translator.__file__) # Confirm path is correct
Also check for import errors in the mz_core module.
Issue: Cannot recognize .mz files
Confirm .mz file is valid ZIP format (contains data.ma):
import zipfile
with zipfile.ZipFile('your_file.mz', 'r') as zf:
print(zf.namelist()) # Should contain 'data.ma'
Issue: Scene not updated after reading
Check if temporary files have permission issues, or try restarting Maya. The plugin registers a SceneClosed scriptJob for cleanup.
Issue: Export options not appearing
The options dialog is provided via optionsScript() method. Some Maya versions may handle this differently.