9
$\begingroup$

How can I detect and/or change the active tab in the current editor via Python?

Is this doable? I have been digging through bpy.context.region/screen and not yet found a way to list the active tab.

$\endgroup$
  • $\begingroup$ This isn't currently exposed to the API (but we can if its useful), can you explain why you would want to access this? $\endgroup$ – ideasman42 Feb 3 '14 at 10:47
  • 2
    $\begingroup$ @ideasman42 I'd like to expose it in the API so as to add hotkeys for switching tabs. This has been a commonly requested feature and something that I would like to play with in Python. This could also allow some more advanced functionality, like automatic tab switching for specific addons or tasks (not so sure on this one, but could be interesting to play with). $\endgroup$ – Jonathan Williamson Feb 3 '14 at 15:35
  • $\begingroup$ Hotkeys to switch tabs sounds good to me (no one can moan if it's an addon), but scripters could abuse it to make their addons show on activation or during certain actions - two of such addons and it could end in an annoying loop. Nonetheless, it should be exposed, since there are little security checks overall in Blender and official addons are controlled. $\endgroup$ – CoDEmanX Feb 4 '14 at 2:32
  • 1
    $\begingroup$ @CoDEmanX It's been a while since this question was raised, but has this been tried / implemented by the devs in the past two years? Or were the concerns regarding Guerilla Addons causing loops too big? $\endgroup$ – aliasguru Oct 13 '16 at 19:54
  • $\begingroup$ I'd also like to know about how this progressed, if at all. $\endgroup$ – Derek Watts Nov 5 '16 at 7:29
3
$\begingroup$

This isn't currently exposed to the API (but we can expose it if it's useful).

$\endgroup$
2
$\begingroup$

If you mean that you want to turn, let's say, your current editor to the UV Image Editor, you could use the following code:

bpy.context.area.type = 'IMAGE_EDITOR'

Here are the rest of the strings you put for different screens:

3D Object Editor - 'VIEW_3D'
Timeline editor - 'TIMELINE'
Graph Editor - 'GRAPH_EDITOR'
Dopesheet Editor - 'DOPESHEET_EDITOR'
NLA Editor - 'NLA_EDITOR'
UV Image Editor - 'IMAGE_EDITOR'
Sequence Editor - 'SEQUENCE_EDITOR'
Clip Editor - 'CLIP_EDITOR'
Text Editor - 'TEXT_EDITOR'
Node Editor - 'NODE_EDITOR'
Game Logic Editor - 'LOGIC_EDITOR'
Properties Panel - 'PROPERTIES_EDITOR'
Outliner - 'OUTLINER'
User Preferences Screen - 'USER_PREFERENCES'
Info Panel - 'INFO'
File Browser - 'FILE_BROWSER'
Python Console - 'CONSOLE'

(The colours above don't mean anything)

So if you want to switch to the file browser, you would do:

bpy.context.area.type = 'FILE_BROWSER'

:)

$\endgroup$
  • 5
    $\begingroup$ You can get a list with description with this one-liner: [(item.identifier, item.name, item.description) for item in bpy.types.Area.bl_rna.properties['type'].enum_items] $\endgroup$ – CoDEmanX Aug 26 '14 at 12:36

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.