2
$\begingroup$

So I'm fairly new to the Blender API, and I have a script that needs to be run every time the 3D cursor is moved. I can get the current location with bpy.context.scene.cursor_location, but that's only usable from the script itself.

Can this be used to trigger my script?

$\endgroup$
3
$\begingroup$

A quick and dirty solution would be to use a scene_update_post handler.

Event handler access in Blender.

import bpy
def my_handler(scene):
    cursorLoc = bpy.context.scene.cursor_location
    # do something
    print(cursorLoc)

bpy.app.handlers.scene_update_post.append(my_handler)

Run the script once, then your function will be called as soon as the scene updates.

This is highly inefficient and will affect the performance depending on the design of the script. It provides an easy solution though and Blender was always fast enough for me to not notice a difference.

$\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.