Basically for an addon, import as a module, call the modules register method to enable.
The folder your addon is in is the module name, eg
mesh_stairs/
__init__.py
operators/
__init__.py
foo.py
bar.py
The operators you have in the operators folder already have a register and unregister method. Can from ./operators import foo
and in register call foo.register()
(as answered by @RJG while I was dawdling along)
Dynamically loading each module in operators folder.
Here is a method I played around with for bat_tools
to manage a number of "addons" into one. Enabling / disabling addons for workspaces has prompted somewhat of a rethink.
Pretty generic. Using __all__
and globals. Could load any list or dict etc instead.
Script: mesh_stairs/operators/__init__.py
"""
BATTOOLS edit re stairs q.
"""
__all__ = []
def register_tools():
""" """
for name in __all__:
register_tool(globals()[name])
def register_tool(tool):
"""
:param tool:
"""
print("REGTOOLS", tool)
tool.register()
def unregister_tools():
""" """
for name in __all__:
unregister_tool(globals()[name])
def unregister_tool(tool):
"""
:param tool:
"""
print("UNREGTOOLS", tool)
tool.unregister()
def check_dependencies(tool):
"""
:param tool:
"""
print(tool.dependencies)
return all(importlib.util.find_spec(d) for d in tool.dependencies)
def load_tools():
""" """
__all__.clear()
import pkgutil
for m in pkgutil.iter_modules(__path__):
tool = __import__(m.name, globals(), level=1)
__all__.append(m.name)
load_tools()
Script: mesh_stairs/__init__.py
bl_info = {
"name": "Curved Stairs Mesh Generator",
"description": "Adds new mesh builders for quickly creating staircases.",
"author": "Mark McKay",
"version": (1, 0),
"blender": (2, 80, 0),
"location": "View3D > Add > Mesh",
# "warning": "", # used for warning icon and text in addons panel
"wiki_url": "https://github.com/blackears/blenderStairs",
"tracker_url": "https://github.com/blackears/blenderStairs",
"support": "COMMUNITY",
"category": "Add Mesh"
}
from . import operators
def register():
operators.register_tools()
def unregister():
operators.unregister_tools()