Skip to main content

Charcoal Editor 2 Documentation

Avoiding reload() with Module States

Python's reload() function, a big inconvenience to anyone writing tools for Maya that span multiple Python files. This video explains why reload is used and introduces a new feature in Charcoal Editor 2 (added in v2.4.1) that aims to eliminate the need for it.

Usage

The module state commands are available through the main menu (Command->Python) and the code editor's right-click context menu (when a Python tab is active). Custom hotkeys can be set in the Hotkey Manager.

Update Module State - Replace the existing module list with a list of all loaded modules.

Revert Module State - Remove any modules that are not included in the saved module state.

Revert Module State on Execute (toggle) - Automatically revert the module state when executing code in Charcoal Editor 2.

Notes

Under the hood, the module state is saved when Charcoal Editor 2 is first opened. When the module state is reverted, any modules that are not included in the saved state are removed. This does come with the caveat that modules which are imported during startup will persist. So if modules are actively being developed, and you wish to use the Revert Module functionality, those modules cannot be imported prior to opening Charcoal Editor 2.

Additionally, the Update Module State command can be used to overwrite the startup modules with the current modules. So, if there are modules that should persist, this command can be called after they are imported.