I'm trying to find the available Properties Editor tabs of the active object. bpy.context.space_data.context (when accessed inside the Properties Editor) indicates which tab is being displayed and can be used to set the active tab. To do this with code you should know ahead of time which tabs (panels, menus, etc.) are available for the active object (i.e. armature vs a mesh type). For instance if you set bpy.context.space_data.context = "cheese" (while in the Properties Editor) with a mesh object active you get this error message:

TypeError: bpy_struct: item.attr = val: enum "cheese" not found in 

Are these values stored in the object context somewhere? Is there some other way I can access a list of available Property Editor tabs context for the active object, or will I have to map these out manually? space_properties.py doesn't seem to be much help here.


1 Answer 1


Dynamic enum property.

This is a dynamic enum property, ie it changes dependant on context.

We can get all possible members, from the properties rna data enum_items

>>> for i, a in enumerate(C.screen.areas):
...     i, a.type
(1, 'CONSOLE')

>>> s = C.screen.areas[0].spaces.active
>>> s.bl_rna.properties['context'].enum_items.keys()

or similarly from the type


whereas the error message, as shown in question, shows those members available for that context.

A dynamic enum property has a method that populates its items depending on context. I am unaware of how to tap into the method and get only context members.

Pinning an object to the panel also changes context tabs displayed.

Henceforth apping them out manually (with some assistance) is AFAIK going to have to do.

This is one of the rare cases where I would recommend using try / except clause. We could for instance write a script that creates sets for each data type. We know the union (above) and can find a common set and those unique to each type. For instance can grep the context members out of the exception message. Pretty ugly example below, mesh object selected in edit mode, improve using re expression perhaps.

>>> try:
...     s.context = "Foo"
... except TypeError as e:
...     m = str(e.args)
...     m[m.find("(", 1) + 1:-4].replace("\\'", "").replace(" ", "").split(",")

Worth mentioning that DATA will display mesh data for a mesh object, armature data for an armature object, curve data for a curve etc


You must log in to answer this question.

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