0
$\begingroup$

I'm trying to create a button, when I press it the Middle Mouse Action setting should change from Orbit to Pan and back.

enter image description here

When I change manually, in the python console, this text is displayed:

 bpy.data.window_managers["WinMan"].(null) = 'PAN'

But impossible to do anything with it. When I introduce it into a script, there is this error:

 Python: File "\Text", line 9
     bpy.data.window_managers["WinMan"].('PAN')
                                        ^
 SyntaxError: invalid syntax

How can I go about it?

$\endgroup$
2
  • $\begingroup$ Hi. I'm sure that I'm overlooking a reason why you would like to have a script for this. Unless the Keymap has been changed you probably know that holding down Shift->Middle Mouse will switch between Orbit and Pan. $\endgroup$
    – curious_1
    Commented Apr 5 at 4:46
  • 1
    $\begingroup$ Hi @curious_1 yes I know that you probably know that holding down Shift->Middle Mouse will switch between Orbit and Pan. What I want to do is with a simple button I can switch from my way of working in 3D to 2D. I want to make 2D architectural plans and holding the wheel half the time is not optimized. $\endgroup$
    – André Ruf
    Commented Apr 5 at 13:11

1 Answer 1

0
$\begingroup$
import bpy

active_keyconfig = bpy.context.preferences.keymap.active_keyconfig
preferences = bpy.context.window_manager.keyconfigs[active_keyconfig].preferences
if preferences:
    preferences.v3d_mmb_action = 'PAN' if preferences.v3d_mmb_action == 'ORBIT' else 'ORBIT'
$\endgroup$
2
  • $\begingroup$ Thank you very much, this is exactly what I was looking for. I always want to improve my mastery of bpy and yet I have not been able to find this information without your help. Could you tell me how you managed to find out about this? What if there are resources or documentation that I missed? How can I become even more independent in my learning of bpy? $\endgroup$
    – André Ruf
    Commented Apr 7 at 14:26
  • $\begingroup$ It is an extensive topic on its own. It needs a separate question. $\endgroup$
    – unwave
    Commented Apr 7 at 17:58

You must log in to answer this question.

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