繁体   English   中英

Blender Python - 在导入所有类时强制重新加载模块

[英]Blender Python - Force reload of module while importing all its classes

我在 Python/Blender 中开发,这里有两个需求:

  1. 从我的模块中导入所有单独的类(因为它们每个都必须在搅拌机中注册)
  2. 每次执行脚本时重新加载模块本身(以防止在我开发插件时缓存并按“重新加载脚本”)

目前我正在这样做(在__init__.py中):

from importlib import reload
from .MyPlugin import *

reload(MyPlugin)

classes = [ClassA, ClassB, ClassC]
# register each class, not shown here

但是reload(MyPlugin)行会导致错误:“MyPlugin is not defined”。

最初我尝试重新加载每个类,但它引发了一个错误, reload需要一个模块。

一些同事帮我回答了,最终在__init__.py起作用的是:

from importlib import reload

if "MyModule" in locals():
    reload(MyModule)
else:
   import MyModule

from .MyModule import *

这在这里有详细说明: https : //blenderartists.org/t/how-to-reload-add-on-code/1202715/2

这适用于旧版本(使用 2.79 测试)首先重新启动!

del sys.modules['foo']    
from foo import *

对不起,答案对我来说不清楚。 我有一些我喜欢在外部编辑的脚本。 说 script1, script2, ...

import script1, script2, ...

这些脚本运行良好,但编辑后应重新加载。 执行此操作的代码是什么?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM