From briefly looking at the relevant code it seems the whole workspace order is handled somewhat convoluted. The order
field mentioned in Need python access to workspace tab order (workspace.order) indeed holds the order, but it’s not directly exposed to Python, nor does there seem to be another way.
The only (nasty) workaround I can think of is to use bpy.ops.screen.workspace_cycle(direction='NEXT')
to cycle through all the workspaces and check bpy.context.window.workspace.name
until it loops around. But that operator can not be called during UI drawing operations it seems (get a can't modify blend data in this state (drawing/rendering)
), so it might actually not be possible to use it. Plus, switching workspaces causes delays the first time, due to resources needing to be initialized.
The simplest fix would be to add an order
property to the C code:
diff --git a/source/blender/makesrna/intern/rna_workspace.c b/source/blender/makesrna/intern/rna_workspace.c
index d76ad254140..d97089691a6 100644
--- a/source/blender/makesrna/intern/rna_workspace.c
+++ b/source/blender/makesrna/intern/rna_workspace.c
@@ -429,6 +429,8 @@ static void rna_def_workspace(BlenderRNA *brna)
"(which has its own active asset library)");
RNA_def_property_update(prop, NC_ASSET | ND_ASSET_LIST_READING, NULL);
+ prop = RNA_def_property(srna, "order", PROP_INT, PROP_NONE);
+
RNA_api_workspace(srna);
}
which you can then use as
>>> bpy.data.workspaces[0].name
'Animation'
>>> bpy.data.workspaces[0].order
6
I’ll submit the patch for review and inclusion in the next release.