Python of Data Block Selection

You know how when you hover your mouse over various buttons and settings, the tooltip tells you the python function for it? I’m trying to find out what the Python is for selecting a datablock from the drop-down list - specifically, the list of screen layouts.

In other words, when you click the button to the left of the screen layout name at the top of the screen, and select “UV Editing” or something from the list, what function has just been executed (I presume with the “UV Editing” name or its index number as the parameter)?

My goal is to then use this to bind hotkeys for the specific screen layouts.

Thanks.

Don’t know the operator being run but…

bpy.context.window.screen = bpy.data.screens[‘Compositing’]

Awesome. Know how you’d bind a key to that?

Whelp, given that I just spent that last 3 days and nights straight figuring it out, here’s the answer:

  • Paste the following script into the Text Editor window, which you may find in the “Game Logic” or “Scripting” screen layouts in the drop-down menu at the top of the screen. This will be the last time you’ll have to click on the fraggin’ thing with your mouse.
import bpy
class SetScreenLayout(bpy.types.Operator):
    """Switches to the screen layout of the given name."""
    bl_idname="screen.set_layout"
    bl_label="Switch to Screen Layout"
    layoutNamme=bpy.props.StringProperty()
    def execute(self,context):
        bpy.context.window.screen=bpy.data.screens[self.layoutNamme]
        return{'FINISHED'}
bpy.utils.register_class(SetScreenLayout)
  • At the bottom, name it “SetScreenLayout.py” or anything else ending in “.py”.
  • Click the “Run Script” button on the bottom bar to apply it to this session. (You may have to scroll to the right of the bottom bar to find it.)
  • Check “Register” to the right of it, to have the operator available after restarting Blender.
  • Go to File->Preferences, Input tab, and under an appropriate subcategory such as “Screen -> Screen (Global)”, click “Add New” for as many screen layouts as you want shortcuts for. I used Ctrl-Alt-F1 through F4 as those seem not to be taken.
  • For each one, input “screen.set_layout” in the text field on the left and hit enter.
  • To the right of “layoutNamme” that appears below, input the name of the screen layout you want the key combo to switch to, from the pull-down list at the top (“Default”, “UV Editing”, “Animation”, “Compositing”, “Game Logic”, “Scripting”, or your own custom-made layouts).
  • Profit.

I undoubtedly spent more time getting the fraggin’ hotkeys to work than the combined time they will save me for the rest of my Blender career, but I’m German and don’t know how to surrender. Thanks, Uncle Entity, for the tip on the context object to set.

The operator


bpy.ops.screen.screen_set(delta=1)

changes to the next or previous (delta=-1) screen and is already bound to ctrl - left / right arrow.

Yep, and now with this script, bpy.ops.screen.set_layout(“Layout Name”) changes to a specific one.