Blender: developing scripts as external modules

The code under the cut could be used to auto-update module’s code in Blender’s environment.

It could be useful when you developing in external editor.

import bpy import os import sys def reload_module(module): global sys from importlib import import_module for s in list(sys.modules.keys()): if s == module.__name__ or s.startswith(module.__name__+'.'): del sys.modules[s] globals()[module.__name__] = import_module(module.__name__) sys.modules[module.__name__] = globals()[module.__name__] modulePathVar = "MODULENAME_PATH" modulePath = os.environ.get(modulePathVar) if modulePath is None or not os.path.exists(modulePath): print("Required path of module passed through env '{0}'".format(modulePathVar)) else: if modulePath not in sys.path: sys.path.append(modulePath) import yourmodulename reload_module(yourmodulename) from yourmodulename import Foo # Under that line write your code, e.g.: xfoo = Foo.Foo(bpy=bpy, obj=None, target=None) xfoo.process() HH

Leave a Reply

Your email address will not be published. Required fields are marked *