Hi,
I’m trying to make an addon and I would like to put all related scripts in a folder.
The problem is that I can’t import the modules properly from the __init __ and they aren’t taken into account by Blender. It works fine when I run all the scripts from the Text Editor but not when starting Blender and activating it from the Addon preferences (Note: I activate it without errors but the modules aren’t taken into account, only the __init __ script is).
I tried copying the already ported addons, I tried googling the errors I was getting, but couldn’t find a solution…
So the question is how do I properly include other modules?
It would be great if someone could look into it and write the lines of code I’m missing to make it work.
Here is the __init __ script:
bl_info = {
"name": "Pie Menu: Toolbox Edit Mode (Metaball)",
"blender": (2, 80, 0),
"description": "Pie Menu Toolbox for 3D VIEW Edit Mode (Metaball).",
"category": "Custom"
}
import bpy
from bpy.types import Menu
# import TestModule
#--------------------------------------------------------------------------------------
# F U N C T I O N A L I T I E S
#--------------------------------------------------------------------------------------
# EMPTY CLASS
class EmptyClass(bpy.types.Operator):
bl_idname = "empty.class"
bl_label = "Empty Class"
bl_options = {'REGISTER', 'UNDO'}
def execute(self, context):
return {'FINISHED'}
#--------------------------------------------------------------------------------------
# P I E M E N U
#--------------------------------------------------------------------------------------
class VIEW3D_PIE_EditModeToolbox_Metaball(Menu):
bl_label = "EDIT MODE TOOLBOX (METABALL)"
def draw(self, context):
layout = self.layout
pie = layout.menu_pie()
pie.operator("mball.delete_metaelems", text="Delete", icon="X")
pie.operator("test.class", text="Test Pie Button", icon="X")
#--------------------------------------------------------------------------------------
# R E G I S T R Y
#--------------------------------------------------------------------------------------
classes = (
EmptyClass,
VIEW3D_PIE_EditModeToolbox_Metaball
)
def register():
from bpy.utils import register_class
for cls in classes:
register_class(cls)
wm = bpy.context.window_manager
if wm.keyconfigs.addon:
km = wm.keyconfigs.addon.keymaps.new(name='Metaball')
kmi = km.keymap_items.new('wm.call_menu_pie', 'RIGHTMOUSE', 'PRESS', shift=True)
kmi.properties.name = 'VIEW3D_PIE_EditModeToolbox_Metaball'
def unregister():
from bpy.utils import unregister_class
for cls in classes:
unregister_class(cls)
addon_keymaps = []
wm = bpy.context.window_manager
if wm.keyconfigs.addon:
for km in addon_keymaps:
for kmi in km.keymap_items:
km.keymap_items.remove(kmi)
wm.keyconfigs.addon.keymaps.remove(km)
addon_keymaps.clear()
if __name__ == "__main__":
register()
And here is the TestModule script:
import bpy
from bpy.props import *
from bpy.types import WindowManager
#--------------------------------------------------------------------------------------
# F U N C T I O N A L I T I E S
#--------------------------------------------------------------------------------------
# EMPTY CLASS
class EmptyClass(bpy.types.Operator):
bl_idname = 'empty.class'
bl_label = 'Empty Class'
bl_description = "Empty Class"
bl_options = {'REGISTER', 'UNDO'}
def execute(self,context):
return{'FINISHED'}
#--------------------------------------------------------------------------------------
# O P E R A T O R
#--------------------------------------------------------------------------------------
class TestClass(bpy.types.Operator):
bl_label = "Test Class"
bl_idname = "test.class"
def draw(self, context):
layout = self.layout
box = layout.column()
box.label(text="TEST")
def invoke(self, context, event):
wm = context.window_manager
return wm.invoke_popup(self)
def execute(self, context):
self.report({'INFO'}, self.my_enum)
return {'FINISHED'}
#--------------------------------------------------------------------------------------
# R E G I S T R Y
#--------------------------------------------------------------------------------------
classes = (
EmptyClass,
TestClass
)
def register():
from bpy.utils import register_class
for cls in classes:
register_class(cls)
def unregister():
from bpy.utils import unregister_class
for cls in classes:
unregister_class(cls)
if __name__ == "__main__":
register()