2

I was looking through some add-ons that ship with blender so I could better understand how to use multiple files for an add-on.

I tried running the add_curve_extra_objects plugin's init.py however when I do I get this error:SystemError: Parent module '' not loaded, cannot perform relative import

So how do I specify the parent directory or get this to work?

sajdnv
  • 294
  • 5
  • 9

1 Answers1

4

Organize your folder structure like this:

myaddon/
├── __init__.py
├── operators/
    ├── first_operator.py

In the __init__.py do this:

import bpy

from .operators.first_operator import FirstOperator

bl_info = {
    "name": "MyAddon",
    "description": "A demo addon",
    "author": "myname",
    "version": (1, 0, 0),
    "blender": (2, 7, 9),
    "wiki_url": "my github url here",
    "tracker_url": "my github url here/issues",
    "category": "Animation"
}

def register():
    bpy.utils.register_module(__name__)

def unregister():
    bpy.utils.unregister_module(__name__)

In the operators/first_operator.py file, do this:

import bpy

class FirstOperator(bpy.types.Operator):
    bl_label = "First Operator"
    bl_idname = "myaddon.first_operator"
    bl_description = "A demo operator"

    def execute(self, context):
        print("hello world")

        return {"FINISHED"}

You'll have to install the addon to use it. You can't just run the __init__.py from the text editor in Blender to make it work.

doakey3
  • 1,946
  • 11
  • 24