Skip to content

init.py - Technical Documentation

PLACE IMAGE OF init.py SOURCE CODE IN THE EDITOR HERE

The __init__.py file is the core of DAMTools. It defines the addon information, imports and registers all modules, operators, panels, and preferences, and manages QuickSnap integration and global shortcut configuration.


Index


General Purpose

  • It is the entry point of the DAMTools addon.
  • Defines the metadata for Blender (bl_info).
  • Imports and registers all modules and tools.
  • Integrates QuickSnap functionality.
  • Manages global preferences and shortcuts.

File Structure

  1. bl_info: Addon metadata (name, author, version, description, etc).
  2. Module Import: Imports properties, operators, ui, menu, and QuickSnap.
  3. QuickSnap Integration: Imports QuickSnap classes and menus, handles import errors.
  4. Preferences Definition: DAMToolsPreferences class with properties for shortcuts and global options.
  5. Shortcut Capture Operators: Allows configuring shortcuts from preferences.
  6. Registration and Unregistration: register() and unregister() functions to register all components.

Key Blocks and Explanation

bl_info and Metadata

bl_info = {
    "name": "DAMTools",
    "author": "NDSynrg",
    "version": (1, 1, 0),
    "blender": (3, 0, 0),
    "location": "View3D > Sidebar (N Panel) > DAMTools | Pie Menu (configurable)",
    "description": "Import/Export, align, join, rename by X, organize by X (Configurable Panel and Pie Menu).",
    "warning": "Overrides keyboard shortcuts configured for the Pie Menu.",
    "doc_url": "",
    "category": "Import-Export",
}
- Defines the information Blender shows in the addon list.

Module Import

from . import properties
from . import operators
from . import ui
from . import menu
- Imports the addon's main modules.

QuickSnap Integration

try:
    from .quicksnap.quicksnap import QuickVertexSnapOperator, QuickVertexSnapPreference, ...
    print("DAMTools: QuickSnap import successful.")
except ImportError as e:
    print(f"DAMTools: Error importing QuickSnap: {e}")
    # Define placeholder classes to prevent failures
- Imports QuickSnap classes and menus, handles errors to prevent the addon from failing if there are issues.

Preferences Definition

class DAMToolsPreferences(AddonPreferences):
    bl_idname = __name__
    # Properties for global shortcuts and options
    hotkey_key_str: StringProperty(...)
    # ...
- Allows configuring global shortcuts and options from the addon preferences.

Registration and Unregistration

def register():
    # Registers all modules, operators, panels, and preferences
    ...
def unregister():
    # Unregisters all components
    ...
- Standard functions for the addon lifecycle in Blender.


Key Code Snippets

Custom Shortcut Capture

class DAMTOOLS_OT_CaptureHotkey(Operator):
    bl_idname = "damtools.capture_hotkey"
    # ...
    def modal(self, context, event):
        # Captures the key combination and saves it in preferences

Preferences and Shortcut Registration

class DAMToolsPreferences(AddonPreferences):
    bl_idname = __name__
    # Properties for global shortcuts and options

Suggested Images

  • PLACE IMAGE OF init.py SOURCE CODE IN THE EDITOR HERE
  • PLACE DIAGRAM OF DEPENDENCIES BETWEEN MODULES
  • PLACE IMAGE OF THE ADDON PREFERENCES IN BLENDER

To see the integration with each tool and menu, consult the documentation for the corresponding modules in the [DOCUMENTATION] folder.