Added functionality to Console Search function

I have added functionality to Console Search function . . . You can now search the object that is
active in the 3D view using:
searcha(‘searchitem’)

I have also changed the way the search works. If you search for ‘axis’, it will bring up anything that
has the word axis in it, for example ‘track_axis’ would be considered a match.

So now there are three functions total:
searcha(‘searchitem’) Search active object

search(‘searchitem’, modulename=‘bpy’) Search normal, default module is bpy, any modules you
search will import that module.

searchx(‘searchitem’) Search extended - imports all modules meaning you probably want
to restart Blender to clear all the imports when done if you are working on
a project.

# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# Searches modules to level 2, beyond that not yet covered
# Search Usage example:
# search('sin', modulename='bpy')
# Default search is bpy module and submodules AKA the Application modules
# Note: **search imports any modules that you search**
# 
# Searchable Standalone Modules (for the above parameter "modulename")
# aud, bgl, bl_math, blf, bmesh, bpy, bpy_extras,
# freestyle, gpu, gpu_extras, idprop, imbuf, mathutils, math
# If you enter only the searchitem, it will search the bpy module.
#
# searcha('axis') --> searches the ACTIVE object in the 3d View.
# Select the object you want information on, then use searcha('item')
#
# Search Extended Usage example:
# searchitem = 'hypo'
# searchx(searchitem)
# searchx is (search extended) 
# Global search.  **imports ALL modules.**
#
# If you can't crack it, hack it! I've hacked Blender, ohhh nooo!
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
#
import bpy
from collections import deque

# Search active object
def searcha(searchitem):
    searchitem = str(searchitem)
    notfound = True
    act = dir(bpy.context.active_object)
    dir(bpy.context.active_object.data)
    act.insert(0, 'bpy.context.active_object')
    for item in act:
        if searchitem.lower() in item.lower():
            if item == 'bpy.context.active_object':
                print(item)
            else:
                print(act[0] + "." + item)
            notfound = False
    #
    if(notfound):
        print('Item not found')

# Search modules to level 2, beyond that not yet covered  
def search(searchitem, modulename='bpy'):
    searchitem = str(searchitem)
    q = deque()
    if(modulename=='bpy'):
        bpyque = dir(bpy)
        bpyque.insert(0, 'bpy')
        q.append(bpyque)
        bpy_app_que = dir(bpy.app)
        bpy_app_que.insert(0, 'bpy.app')
        q.append(bpy_app_que)
        armatures = dir(bpy.data.armatures)
        armatures.insert(0, 'bpy.data.armatures')
        q.append(armatures)
        bpy_context_que = dir(bpy.context)
        bpy_context_que.insert(0, 'bpy.context')
        q.append(bpy_context_que)
        bpy_data_que = dir(bpy.data)
        bpy_data_que.insert(0, 'bpy.data')
        q.append(bpy_data_que)
        bpy_msgbus_que = dir(bpy.msgbus)
        bpy_msgbus_que.insert(0, 'bpy.msgbus')
        q.append(bpy_msgbus_que)
        bpy_ops_que = dir(bpy.ops)
        bpy_ops_que.insert(0, 'bpy.ops')
        q.append(bpy_ops_que)
        bpy_path_que = dir(bpy.path)
        bpy_path_que.insert(0, 'bpy.path')
        q.append(bpy_path_que)
        bpy_props_que = dir(bpy.props)
        bpy_props_que.insert(0, 'bpy.props')
        q.append(bpy_props_que)
        bpy_types_que = dir(bpy.types)
        bpy_types_que.insert(0, 'bpy.types')
        q.append(bpy_types_que)
        bpy_utils_que = dir(bpy.utils)
        bpy_utils_que.insert(0, 'bpy.utils')
        q.append(bpy_utils_que)
    #
    if(modulename=='mathutils'):
        import mathutils
        mathutils_que = dir(mathutils)
        mathutils_que.insert(0, 'import mathutils, mathutils')
        q.append([mathutils_que])
    #
    if(modulename=='math'):
        import math
        math_que = dir(math)
        math_que.insert(0, 'import math, math')
        q.append([math_que])
    #
    if(modulename=='aud'):
        import aud
        aud_que = dir(aud)
        aud_que.insert(0, 'import aud, aud')
        q.append([aud_que])
    #
    if(modulename=='bgl'):
        import bgl
        bgl_que = dir(bgl)
        bgl_que.insert(0, 'import bgl, bgl')
        q.append([bgl_que])
    #
    if(modulename=='bl_math'):
        import bl_math
        bl_math_que = dir(bl_math)
        bl_math_que.insert(0, 'import bl_math, bl_math')
        q.append([bl_math_que])
    #
    if(modulename=='blf'):
        import blf
        blf_que = dir(blf)
        blf_que.insert(0, 'import blf, blf')
        q.append([blf_que])
    #
    if(modulename=='bmesh'):
        import bmesh
        bmesh_que = dir(bmesh)
        bmesh_que.insert(0, 'import bmesh, bmesh')
        q.append(bmesh_que)
        bmesh_geometry_que = dir(bmesh.geometry)
        bmesh_geometry_que.insert(0, 'import bmesh, bmesh.geometry')
        q.append(bmesh_geometry_que)
        bmesh_ops_que = dir(bmesh.ops)
        bmesh_ops_que.insert(0, 'import bmesh, bmesh.ops')
        q.append(bmesh_ops_que)
        bmesh_types_que = dir(bmesh.types)
        bmesh_types_que.insert(0, 'import bmesh, bmesh.types')
        q.append(bmesh_types_que)
        bmesh_utils_que = dir(bmesh.utils)
        bmesh_utils_que.insert(0, 'import bmesh, bmesh.utils')
        q.append(bmesh_utils_que)
    #
    if(modulename=='bpy_extras'):
        import bpy_extras
        bpy_extras_que = dir(bpy_extras)
        bpy_extras_que.insert(0, 'import bpy_extras, bpy_extras')
        q.append(bpy_extras_que)
        bpy_extras_io_utils_que = dir(bpy_extras.io_utils)
        bpy_extras_io_utils_que.insert(0, 'import bpy_extras, bpy_extras.io_utils')
        q.append(bpy_extras_io_utils_que)
        bpy_extras_node_utils_que = dir(bpy_extras.node_utils)
        bpy_extras_node_utils_que.insert(0, 'import bpy_extras, bpy_extras.node_utils')
        q.append(bpy_extras_node_utils_que)
        bpy_extras_object_utils_que = dir(bpy_extras.object_utils)
        bpy_extras_object_utils_que.insert(0, 'import bpy_extras, bpy_extras.object_utils')
        q.append(bpy_extras_object_utils_que)
    #
    if(modulename=='freestyle'):
        import freestyle
        freestyle_que = dir(freestyle)
        freestyle_que.insert(0, 'import freestyle, a standalone module')
        q.append(freestyle_que)
        freestyle_chainingiterators_que = dir(freestyle.chainingiterators)
        freestyle_chainingiterators_que.insert(0, 'import freestyle, freestyle.chainingiterators')
        q.append(freestyle_chainingiterators_que)
        freestyle_functions_que = dir(freestyle.functions)
        freestyle_functions_que.insert(0, 'import freestyle, freestyle.functions')
        q.append(freestyle_functions_que)
        freestyle_predicates_que = dir(freestyle.predicates)
        freestyle_predicates_que.insert(0, 'import freestyle, freestyle.predicates')
        q.append(freestyle_predicates_que)
        freestyle_shaders_que = dir(freestyle.shaders)
        freestyle_shaders_que.insert(0, 'import freestyle, freestyle.shaders')
        q.append(freestyle_shaders_que)
        freestyle_types_que = dir(freestyle.types)
        freestyle_types_que.insert(0, 'import freestyle, freestyle.types')
        q.append(freestyle_types_que)
        freestyle_utils_que = dir(freestyle.utils)
        freestyle_utils_que.insert(0, 'import freestyle, freestyle.utils')
        q.append(freestyle_utils_que)
    #
    if(modulename=='gpu'):
        import gpu
        gpu_que = dir(gpu)
        gpu_que.insert(0, 'gpu, gpu')
        q.append(gpu_que)
        gpu_types_que = dir(gpu.types)
        gpu_types_que.insert(0, 'import gpu, gpu.types')
        q.append(gpu_types_que)
        gpu_matrix_que = dir(gpu.matrix)
        gpu_matrix_que.insert(0, 'import gpu, gpu.matrix')
        q.append(gpu_matrix_que)
        gpu_select_que = dir(gpu.select)
        gpu_select_que.insert(0, 'import gpu, gpu.select')
        q.append(gpu_select_que)
        gpu_shader_que = dir(gpu.shader)
        gpu_shader_que.insert(0, 'import gpu, gpu.shader')
        q.append(gpu_shader_que)
    #
    if(modulename=='gpu_extras'):
        import gpu_extras
        gpu_extras_que = dir(gpu_extras)
        gpu_extras_que.insert(0, 'gpu_extras, gpu_extras')
        q.append([gpu_extras_que])
    #
    if(modulename=='idprop'):
        import idprop
        idprop_types_que = dir(idprop.types)
        idprop_types_que.insert(0, 'import idprop, idprop.types')
        q.append([idprop_types_que])
    #
    if(modulename=='imbuf'):
        import imbuf
        imbuf_que = dir(imbuf)
        imbuf_que.insert(0, 'import imbuf, imbuf')
        q.append([imbuf_que])
    #
    notfound = True # For printing "Module not found." if que is empty.
    while len(q)>0:
        list = q.popleft()
        # print('searched ', list[0])
        for item in list:
            #print('searchitem = ', searchitem, '  i = ', i)
            if searchitem.lower() in item.lower():
                print(list[0] + "." + item)
                notfound = False
    #
    if(notfound):
        print('Item not found')
        print()
        print('Searchable Standalone Modules:')
        print('aud, bgl, bl_math, blf, bmesh, bpy, bpy_extras,')
        print('freestyle, gpu, gpu_extras, idprop, imbuf, mathutils, math')



# Extended Search
def searchx(searchitem):
    searchitem = str(searchitem)
    q = deque()
    import mathutils
    mathutils_list = dir(mathutils)
    mathutils_list.insert(0, 'import mathutils, mathutils')
    q.append(mathutils_list)
    #
    import math
    math_list = dir(math)
    math_list.insert(0, 'import math, math')
    q.append(math_list)
    #
    import aud
    aud_list = dir(aud)
    aud_list.insert(0, 'import aud, aud')
    q.append(aud_list)
    #
    import bgl
    bgl_list = dir(bgl)
    bgl_list.insert(0, 'import bgl, bgl')
    q.append(bgl_list)
    #
    import bl_math
    bl_math_list = dir(bl_math)
    bl_math_list.insert(0, 'import bl_math, bl_math')
    q.append(bl_math_list)
    #
    import blf
    blf_list = dir(blf)
    blf_list.insert(0, 'import blf, blf')
    q.append(blf_list)
    #
    import bmesh
    bmesh_list = dir(bmesh)
    bmesh_list.insert(0, 'import bmesh, bmesh')
    q.append(bmesh_list)
    bmesh_geometry_list = dir(bmesh.geometry)
    bmesh_geometry_list.insert(0, 'import bmesh, bmesh.geometry')
    q.append(bmesh_geometry_list)
    bmesh_ops_list = dir(bmesh.ops)
    bmesh_ops_list.insert(0, 'import bmesh, bmesh.ops')
    q.append(bmesh_ops_list)
    bmesh_types_list = dir(bmesh.types)
    bmesh_types_list.insert(0, 'import bmesh, bmesh.types')
    q.append(bmesh_types_list)
    bmesh_utils_list = dir(bmesh.utils)
    bmesh_utils_list.insert(0, 'import bmesh, bmesh.utils')
    q.append(bmesh_utils_list)
    #
    import bpy_extras
    bpy_extras_list = dir(bpy_extras)
    bpy_extras_list.insert(0, 'import bpy_extras, bpy_extras')
    q.append(bpy_extras_list)
    bpy_extras_io_utils_list = dir(bpy_extras.io_utils)
    bpy_extras_io_utils_list.insert(0, 'import bpy_extras, bpy_extras.io_utils')
    q.append(bpy_extras_io_utils_list)
    bpy_extras_node_utils_list = dir(bpy_extras.node_utils)
    bpy_extras_node_utils_list.insert(0, 'import bpy_extras, bpy_extras.node_utils')
    q.append(bpy_extras_node_utils_list)
    bpy_extras_object_utils_list = dir(bpy_extras.object_utils)
    bpy_extras_object_utils_list.insert(0, 'import bpy_extras, bpy_extras.object_utils')
    q.append(bpy_extras_object_utils_list)
    #
    import freestyle
    freestyle_list = dir(freestyle)
    freestyle_list.insert(0, 'import freestyle, a standalone module')
    q.append(freestyle_list)
    freestyle_chainingiterators_list = dir(freestyle.chainingiterators)
    freestyle_chainingiterators_list.insert(0, 'import freestyle, freestyle.chainingiterators')
    q.append(freestyle_chainingiterators_list)
    freestyle_functions_list = dir(freestyle.functions)
    freestyle_functions_list.insert(0, 'import freestyle, freestyle.functions')
    q.append(freestyle_functions_list)
    freestyle_predicates_list = dir(freestyle.predicates)
    freestyle_predicates_list.insert(0, 'import freestyle, freestyle.predicates')
    q.append(freestyle_predicates_list)
    freestyle_shaders_list = dir(freestyle.shaders)
    freestyle_shaders_list.insert(0, 'import freestyle, freestyle.shaders')
    q.append(freestyle_shaders_list)
    freestyle_types_list = dir(freestyle.types)
    freestyle_types_list.insert(0, 'import freestyle, freestyle.types')
    q.append(freestyle_types_list)
    freestyle_utils_list = dir(freestyle.utils)
    freestyle_utils_list.insert(0, 'import freestyle, freestyle.utils')
    q.append(freestyle_utils_list)
    #
    import gpu
    gpu_list = dir(gpu)
    gpu_list.insert(0, 'gpu, gpu')
    q.append(gpu_list)
    gpu_types_list = dir(gpu.types)
    gpu_types_list.insert(0, 'import gpu, gpu.types')
    q.append(gpu_types_list)
    gpu_matrix_list = dir(gpu.matrix)
    gpu_matrix_list.insert(0, 'import gpu, gpu.matrix')
    q.append(gpu_matrix_list)
    gpu_select_list = dir(gpu.select)
    gpu_select_list.insert(0, 'import gpu, gpu.select')
    q.append(gpu_select_list)
    gpu_shader_list = dir(gpu.shader)
    gpu_shader_list.insert(0, 'import gpu, gpu.shader')
    q.append(gpu_shader_list)
    #
    import gpu_extras
    gpu_extras_list = dir(gpu_extras)
    gpu_extras_list.insert(0, 'gpu_extras, gpu_extras')
    q.append(gpu_extras_list)
    #
    import idprop.types
    idprop_types_list = dir(idprop.types)
    idprop_types_list.insert(0, 'import idprop, idprop.types')
    q.append(idprop_types_list)
    #
    import imbuf
    imbuf_list = dir(imbuf)
    imbuf_list.insert(0, 'import imbuf, imbuf')
    q.append(imbuf_list)
    #
    # Assuming the user has not thoroughly searched each of the modules
    # with the normal search function:
    import bpy    
    bpylist = dir(bpy)
    bpylist.insert(0, 'bpy')
    q.append(bpylist)
    bpy_app_list = dir(bpy.app)
    bpy_app_list.insert(0, 'bpy.app')
    q.append(bpy_app_list)
    armatures = dir(bpy.data.armatures)
    armatures.insert(0, 'bpy.data.armatures')
    q.append(armatures)
    bpy_context_list = dir(bpy.context)
    bpy_context_list.insert(0, 'bpy.context')
    q.append(bpy_context_list)
    bpy_data_list = dir(bpy.data)
    bpy_data_list.insert(0, 'bpy.data')
    q.append(bpy_data_list)
    bpy_msgbus_list = dir(bpy.msgbus)
    bpy_msgbus_list.insert(0, 'bpy.msgbus')
    q.append(bpy_msgbus_list)
    bpy_ops_list = dir(bpy.ops)
    bpy_ops_list.insert(0, 'bpy.ops')
    q.append(bpy_ops_list)
    bpy_path_list = dir(bpy.path)
    bpy_path_list.insert(0, 'bpy.path')
    q.append(bpy_path_list)
    bpy_props_list = dir(bpy.props)
    bpy_props_list.insert(0, 'bpy.props')
    q.append(bpy_props_list)
    bpy_types_list = dir(bpy.types)
    bpy_types_list.insert(0, 'bpy.types')
    q.append(bpy_types_list)
    bpy_utils_list = dir(bpy.utils)
    bpy_utils_list.insert(0, 'bpy.utils')    
    q.append(bpy_utils_list)
    #
    notfound = True
    for list in q:
        for item in list:
            if searchitem.lower() in item.lower():
                print(list[0] + "." + item)
                notfound = False
    #
    if(notfound):
        print('Item not found')

1 Like

Could you post updates to your script as replies to one of your other threads? No need to create a brand new thread for every update, and people who are interested can subscribe to the one topic.

1 Like