2
$\begingroup$

I know about the shortcut Ctrl + Left / Right arrow to switch between the screen layouts, but that forces you to go through all of them if you have many.

I'd like to give a screen layout (not only to an editor) a single shortcut like:

F1 = 3D View Full

F2 = Animation

F3 = Compositing ...

Is it possible via User preferences > Input? If so, what is the exact code operator I should put in the key map? (like "screen.screen_set" but with the specific name of my screen layout)

Thank you.

$\endgroup$
2
$\begingroup$

An operator to set screen by name.

import bpy    
from bpy.props import StringProperty

class SCREEN_OT_set_by_name(bpy.types.Operator):
    """Change Screen by Name"""
    bl_idname = "screen.set_by_name"
    bl_label = "Set Screen by Name"
    bl_options = {'REGISTER', 'UNDO'}
    name = StringProperty(default="",
                          description="Set the Screen by name")

    @classmethod
    def poll(cls, context):
        return context.screen is not None

    def execute(self, context):
        to_screen = bpy.data.screens.find(self.name)
        if to_screen >= 0:
            # context.screen
            from_screen = bpy.data.screens.find(context.screen.name)
            delta = to_screen - from_screen
            if not delta:
                return {'CANCELLED'}
            sign = abs(delta) / delta
            delta = abs(delta)
            for i in range(delta):
               bpy.ops.screen.screen_set('INVOKE_DEFAULT', delta=sign)
        return {'FINISHED'}


def register():
    bpy.utils.register_class(SCREEN_OT_set_by_name)

def unregister():
    bpy.utils.unregister_class(SCREEN_OT_set_by_name)


if __name__ == "__main__":
    register()

    # test call
    bpy.ops.screen.set_by_name(name="Default")

enter image description here Keymap F1 to change to "Default" screen.

|improve this answer|||||
$\endgroup$
  • $\begingroup$ Thank you batFINGER, but I'm not very good with scripts and I'm not sure what to do with this code.I tried to paste it in the text editor but when I hit "Run Script" it says "Python script fail, look in the console for now..." $\endgroup$ – Chris Sep 17 '16 at 11:33
  • $\begingroup$ Look in the console then, and post what the error message was. If you are on Windows OS just use Window > Toggle System Console. $\endgroup$ – JakeD Sep 17 '16 at 11:35
  • $\begingroup$ Sorry it was a cut n paste error, missing import bpy. Edited answer. $\endgroup$ – batFINGER Sep 17 '16 at 11:57
  • $\begingroup$ Thank you very much. That worked perfectly. There is only one small thing, if I press "F1, F2, F1", the screen layouts switch perfectly, but when I press consecutively "F1, F1", I get the error: Traceback (most recent call last): File"\Text.001", line 22, in execute ZeroDivisionError: division by zero location: <unknown loccation>:-1 Can this error message be removed? $\endgroup$ – Chris Sep 17 '16 at 12:36
  • $\begingroup$ Fixed. Was sure I put that check in in the first place... Copy / Paste run again. $\endgroup$ – batFINGER Sep 17 '16 at 12:56

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.