0
$\begingroup$

I've written a custom addon for a few Pie menus but can't figure out how to load them together from a __init.py

Currently they are all split into these four files:

PIE_context.py, PIE_mode.py, PIE_uvcontext.py, PIE_uvmode.py

They all work when installed on their own, register shortcuts and everything. Despite reading around I can't figure out how to import them together from the __init__.py file below. The shortest of the four PIE_uvcontext.pyis below that:

bl_info = {
    "name": "Context Pie",
    "blender": (2, 80, 0),
    "category": "User Interface",
    "version": (0, 1, 0, 0),
    "location": "UV Editor, View3D, Mesh, Curve",
}

# Blender imports
import bpy

#from bpy.props import *
from . import PIE_context
from . import PIE_mode
from . import PIE_uvcontext
from . import PIE_uvmode

addon_keymaps = []

def register():
    
    PIE_context.register()
    PIE_mode.register()
    PIE_uvcontext.register()
    PIE_uvmode.register()

def unregister():

    PIE_context.unregister()
    PIE_mode.unregister()
    PIE_uvcontext.unregister()
    PIE_uvmode.unregister()
 
if __name__ == "__main__":
    register()
bl_info = {
    "name": "UV Pie: 'Shift + Right Mouse'",
    "description": "UV Pie Menu",
    "version": (0, 1, 2),
    "blender": (2, 80, 0),
    "location": "UV Editor",
    "category": "Pie Menu"}

import bpy
from bpy.types import (
    Header,
    Menu,
    Panel,
)
from bpy.app.translations import contexts as i18n_contexts

# Reference context menu: IMAGE_MT_uvs_context_menu
class IMAGE_PIE_MT_uvContext(Menu):
    bl_label    = ""

    def draw(self, context):
        layout = self.layout
        layout.operator_context = 'INVOKE_REGION_WIN'
        pie = layout.menu_pie()
        
        # WEST
        pie.operator("uv.pin").clear = False
        # EAST
        pie.operator("uv.pin", text='Unpin').clear = True
        # SOUTH
        pie.operator("uv.minimize_stretch")
        # NORTH
        pie.operator("uv.unwrap")
        # NORTH-WEST
        pie.operator("uv.pack_islands")
        # NORTH-EAST
        pie.operator("uv.average_islands_scale")
        # SOUTH-WEST
        pie.operator("mesh.mark_seam", text='Mark Seam').clear = False
        # SOUTH-EAST
        pie.operator("mesh.mark_seam", text='Clear Seam').clear = True

        # Static face menu
        pie.separator()
        pie.separator()

        dropdown = pie.column()
        gap = dropdown.column()
        gap.separator()
        gap.scale_y = 8

        dropdown_menu = dropdown.box().column()
        dropdown_menu.scale_y=1

        dropdown_menu.operator("uv.stitch")
        dropdown_menu.operator("uv.weld")
        dropdown_menu.operator("uv.remove_doubles")


classes = [
    IMAGE_PIE_MT_uvContext]

addon_keymaps = []

def register():
    for cls in classes:
        bpy.utils.register_class(cls)

    wm = bpy.context.window_manager
    if wm.keyconfigs.addon:
        km = wm.keyconfigs.addon.keymaps.new(name='UV Editor')
        kmi = km.keymap_items.new('wm.call_menu_pie', 'RIGHTMOUSE', 'PRESS', shift=True)
        kmi.properties.name = "IMAGE_PIE_MT_uvContext"
        addon_keymaps.append((km, kmi))

def unregister():
    for cls in classes:
        bpy.utils.unregister_class(cls)

    wm = bpy.context.window_manager
    kc = wm.keyconfigs.addon
    if kc:
        for km, kmi in addon_keymaps:
            km.keymap_items.remove(kmi)
    addon_keymaps.clear()

if __name__ == "__main__":
    register()

Thanks!

$\endgroup$
3
  • $\begingroup$ I have the files in the same folder and simply press 'install...' in blender preferences and select the __init__.py file. Perhaps that is just not the way to do it?!? $\endgroup$ – bastian Dec 3 '20 at 0:53
  • $\begingroup$ blender.stackexchange.com/questions/183773/… (make a zip file to install multi-file addons) $\endgroup$ – batFINGER Dec 3 '20 at 1:15
  • $\begingroup$ Thank you! That got it working. Did think I had missed something simple. Can't wait to release it (: $\endgroup$ – bastian Dec 3 '20 at 1:37
0
$\begingroup$

Answered by @batFINGER in comment:

Just had to zip the folder with files in! Trying to make a menu using multiple modules

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.