blender-to-gmstudio / blender-to-smf

Import-Export of Blender model from/to SMF model format
MIT License
11 stars 2 forks source link

Reload imported modules at the top of scripts for more convenient debugging #42

Closed bartteunis closed 2 years ago

bartteunis commented 2 years ago

This is how many of Blender's official add-ons do it, including the FBX exporter, the glTF exporter and the OBJ exporter.

The idea is as follows:

if "bpy" in locals():
    import importlib
    if "module_name" in locals():
        importlib.reload("module_name")

import bpy

A reload is triggered for every module that we maintain ourselves since it may have changes made to its code, even while Blender is running.

When the module is first imported, its name is not in locals yet. On subsequent reloads this is the case and so this can be used as the condition to determine whether a reload is needed (this of course doesn't mean that a file's contents have been changed!).

bartteunis commented 2 years ago

Example code at: https://blenderartists.org/t/how-to-reload-add-on-code/1202715/6