Strategies for finding and learning bpy commands (beginner)?

Hey I’m after some advice. I’m new to coding and trying to learn python in blender, making progress, but one of things that I’ve found confusing is how to find the commands / code I’m after…
For example. I was looking for a way to list all the scenes in a blender file and thankfully stumbled across an exact code example https://docs.blender.org/api/current/bpy.data.html

# print all scene names in a list
print(bpy.data.scenes.keys())

But how/where would you normally figure that out? ie. that .keys() is the right command to use? I can’t see it listed in the API and when I hover over the ‘scenes’ with python tool tips on I only see bpy.data.scenes[Scene].name

Any good workflow advice for finding code you’re after (besides google)?

Personally I find it useful to play around with the code autocompletion in blender’s python console.

For example, type
bpy.
in the console and hit tab, and it will show a list of ways that could be completed (e.g. bpy.ops, bpy.data, etc). Choose one, and then again hit tab to show the list of options that has, and so on…

In my experience you won’t necessarily find the exact command, but I find experimenting in the console to be a good way to get a feel for which specific things I need to look up in the API or on google to find what I need.

Thanks, I started trying that after I posted this and it does help! Thought there may be some other go-to place where a lot of stuff is listed out.

Here’s how you’d get to that through the link you provided, it’s easier to provide pictures than try to type it out, just click where you see the pointer cursor:

blender_tut01
https://docs.blender.org/api/current/bpy.data.html

blender_tut02
https://docs.blender.org/api/current/bpy.types.BlendData.html#bpy.types.BlendData

blender_tut03
https://docs.blender.org/api/current/bpy.types.bpy_prop_collection.html#bpy.types.bpy_prop_collection

2 Likes

Thanks @obsurveyor That’s helpful to see how it connects.