Write Module
write_moduleCreate reusable Python modules in an active Maya session by injecting in-memory functions into sys.modules, enabling agents to define helper libraries that persist during the session.
Instructions
Create a virtual in-memory Python module in an active Maya session.
Injects reusable Python functions into the target Maya session's sys.modules. Modules are virtual and in-memory: they do not persist across Maya restarts, and existing modules are protected unless overwrite=True is explicitly set. Requires an active Maya session.
Boundary: Use write_module to define reusable libraries and helper functions; use execute_code for one-shot imperative execution or expression evaluation.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| code | Yes | Python source code for the module. | |
| name | Yes | Module name. Can be a dotted path (e.g., 'mypackage.utils') in which case parent packages are created automatically. | |
| overwrite | No | If True, overwrite and replace existing module. If False, raise error if module already exists. | |
| session_key | No | Maya session key (optional if only one active session exists). |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |