0
$\begingroup$

I want the addon search bar to be filled on startup:

import bpy
from bpy.app.handlers import persistent


@persistent
def addon_search(scene):
    bpy.data.window_managers["WinMan"].addon_search = "editor"

def register():
    bpy.app.handlers.load_post.append(addon_search)

This works but can I just check that this isn't looping or dangerous? Do I need to remove the load_post handler after it has loaded?

Also why does it not work in an addon, it adds the handler but never runs.

bl_info = {
    "name": "Test",
    "author": "Test",
    "version": (1, 0),
    "blender": (2, 80, 0),
    "description": "Auto-fills addon search field",
    "category": "3D View"}

import bpy
from bpy.app.handlers import persistent


@persistent
def addon_search(scene):
    bpy.data.window_managers["WinMan"].addon_search = "editor"
    return None


def register():
    bpy.app.handlers.load_post.append(addon_search)

def unregister():
    bpy.app.handlers.load_post.remove(addon_search)

if __name__ == "__main__":
    register()
$\endgroup$
0
$\begingroup$

Ok figured it out, addons get loaded after the startup.blend is loaded, so load_post wouldn't work. Also in 2.8 scene_update_post has been replaced with depsgraph_update_post. (Which is much better imo) So i run the search and then delete the handler:

bl_info = {
    "name": "test",
    "author": "test",
    "version": (1, 0),
    "blender": (2, 80, 0),
    "description": "Auto-fills addon search field",
    "category": "3D View"}

import bpy
from bpy.app.handlers import persistent


@persistent
def addon_search(scene):
    bpy.data.window_managers["WinMan"].addon_search = "editor"
    bpy.app.handlers.depsgraph_update_post.remove(addon_search)


def register():
    bpy.app.handlers.depsgraph_update_post.append(addon_search)

def unregister():
    bpy.app.handlers.depsgraph_update_post.remove(addon_search)

if __name__ == "__main__":
    register() 
$\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.