Blender is used in our business, in our scenes, there are a lot of objects. We need to know the name, material...of the objects ... quickly. The only way is to select the object and then read his name and material.

This default operation of Blender is very painful for us because the fact of selecting each object wastes time. I thought to use the raycast to return the information (name, material ...) objects under the mouse and it works fine (I used Templates > Python > Operator Modal View3D Raycast script).

When the modal operation is running, it is not to other operations at the same time. I am looking for a way to stop and restart the raycast automatically. E.g. when the mouse cursor leaves the viewport raycast is stopped and restart when you come back in the viewport.


1 Answer 1


You could modify the example operator a bit to make it work in a non-modal way. The operator can be run after MOUSEMOVE events instead, using a keymap entry.

Here's a quick example, modifying the operator (the main function is unchanged). It requires pressing the ctrl key to avoid running the operator all the time (since ray casts can be quite expensive on heavy scenes). This can be any suitable combination of events. You may also want to put this in a different keymap, e.g. for an addon.

class ViewOperatorRayCast(bpy.types.Operator):
    """Modal object selection with a ray cast"""
    bl_idname = "view3d.modal_operator_raycast"
    bl_label = "RayCast View Operator"

    def poll(cls, context):
        return context.space_data.type == 'VIEW_3D'

    def invoke(self, context, event):
        main(context, event)
        return {'PASS_THROUGH'}

def register():

    wm = bpy.context.window_manager
    kc = wm.keyconfigs['Blender User']
    km = kc.keymaps['3D View']
    kmi = km.keymap_items.new(ViewOperatorRayCast.bl_idname, 'MOUSEMOVE', 'ANY', ctrl=True)
  • $\begingroup$ Perfect. I did not know you could add shortcuts with Pyhton !! what if I want discativer (not delete) the shortcuts with python? $\endgroup$ Sep 8, 2015 at 15:20

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .