1
$\begingroup$

I would like to make addon that every time I enter sculpt mode it turns on "Emulate 3 Button Mouse" and when I leave it will turn off.

I am no programmer, I tried to find some parts of code and get it together, I will post it in here. It´s somehow working but for some reason in new projects it´s not working at all, only after reinstalling addon:

bl_info = {
    "name": "Emulate 3 Button Mouse",
    "blender": (2, 91, 2),
    "category": "Object",
}

import bpy

handle = object() 

def notify_test(*args):
    print( "Mode:", bpy.context.mode )
    bpy.context.preferences.inputs.use_mouse_emulate_3_button = bpy.context.object.mode == 'SCULPT'

subscribe_to = bpy.types.Object, "mode"

bpy.msgbus.subscribe_rna(
    key=subscribe_to,
    owner=handle,
    args=(1, 2, 3),
    notify=notify_test,
    )

def register():
    bpy.msgbus.subscribe_rna(
    key=subscribe_to,
    owner=handle,
    args=(1, 2, 3),
    notify=notify_test,
    )

def unregister():
    pass
    
if __name__ == "__main__":
    register()

Q: What's wrong and how to fix that bug?

$\endgroup$
4
  • $\begingroup$ The following script should work: pasteall.org/gGNy/raw Can you test it and report back? $\endgroup$ – brockmann Mar 30 at 18:06
  • $\begingroup$ It´s working until for example I open my project again next day its not working again. Then I need to reinstall addon in order to work again or when I open older project it´s the same problem $\endgroup$ – Adam Mar 31 at 8:06
  • $\begingroup$ Cool. Yeah, needs to be enabled per file using application handlers (on file load)... but it's working as expected? For now you can just copy/paste my code into the text editor and run it per session. $\endgroup$ – brockmann Mar 31 at 8:21
  • $\begingroup$ Oh sry, now I realized that code you posted was in that link. I was kinda confused. Previously I was talking about that my script again. *And I tried you code and it was working. Previously I did not get what you mean by enabled per file. Now I get it and it seems to work :-D I really appreciate your effort to help and also thanks for editing my question :-) $\endgroup$ – Adam Mar 31 at 8:48

Your Answer

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

Browse other questions tagged or ask your own question.