Some context members don't work

On Blender’s official and allegedly up-to-date python doc’s under the Button Context’s section there’s a mirriad of context members but many of them don’t show up in intellisense nor do they work once I type them completely and run them in the console. I just get an error saying that these properties don’t exist. Some of those properties in question are bpy.context.texture_slot, bpy.context.mesh and bpy.context.armature.

Now I know I can alternatively access these properties via bpy.context.data… and in various other ways but I’m still perplexed by the fact that they’re on the official page if they’re no longer supported. If these properties are for older Blender version’s why are they on the page whose url has the word ‘current’ in them? Or am I just using them wrong???

I’ve tested in Blender 4.1 and 4.3 and it’s the same disappointing result.

Per that same page.

1 Like

As you mentioned, those properties are typically available by some other way, and sometimes them being available through context is meer of a happy accident - Blender itself needed them for some other operation and API users can incidentally use them for their stuff too.

but many of them don’t show up in intellisense

They’ll show up if you use a typing module https://github.com/nutti/fake-bpy-module

1 Like

The docs are up to date. When you type stuff in Blender’s Python Console, you are in that context, so only members relevant for that context exist. Once you move your mouse over something else and use various functionality, the context changes. So you cannot really check it in the console, because in the console you only have the context that exists in the console. Context in Blender is like the light in your fridge in that way. :laughing:

You can register an operator that can be executed in different contexts and prints the context to System Console:

import bpy

class PrintContext(bpy.types.Operator):
    """Tooltip"""
    bl_idname = "wm.print_context"
    bl_label = "Print Context"

    def execute(self, context):
        print(bpy.context.copy())
        return {'FINISHED'}

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

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

if __name__ == "__main__":
    register()

You can then use search menu( F3 ) to execute it while your mouse is over different areas. The context does not depend only on where your mouse is though and it will change depending on very large number of factors. It stores the state of Blender and everything in it at any given time.

2 Likes

I realise the simple concept of a context where as to successfully execute a particular command you need to be in a certain context which depends on your mouse location amongst other things. But what I hoped wasn’t the case was that the very same principle applies to when wanting to expose in the console the very contents of those contexts just for simple purpose of exploration what commands and properties those members have to offer even though you can read about them in the docs, if that makes sense.

But I guess the powers that be tailored it like this for a justified reason. Thank you for the feedback, now it’s all clear to me.

That’s really helpful, thanks.