Blendfile.py how to loop over all objects in one scene

Hello,
I want to read a blend file and loop over all objects in one scene.
So I can not do

with blendfile.open_blend(filepath) as blend:

     objs=blend.find_blocks_from_code(b'OB')

    for o in objs:
.....

because then I would loop over all objects in all scenes and I can not tell which object belongs to which scene.
However when I try something like this:

with blendfile.open_blend(filepath) as blend:
    scenes = [b for b in blend.blocks if b.code == b'SC']
    for scene in scenes:
        base = scene.get_pointer(b'basact')

I get a None value for the base variable.
Does somebody knows how I can access the base struct or how I can loop over all objects of one scene?

Run your python from inside a blender cli instance you open and do it like you would normally at bpy.context.scene.objects? I’m not sure what you’re trying to do when you could just fork a subprocess of blender for that blendfile and return data. You might want to provide a little more info on what you’re trying to do. There might be an easier way someone knows.

In fact, what I would do is go look at code from asset library addons to see how they work before attempting something like what you’re doing here. Opening a different blend file than the active one is not usually what people want to do in an addon, other than just linking/appending things from a library blend.

You have to search the collections first and then you can get the collection’s objects
As far as I know baseact is for blender files below 2.8 (before we had collections)
This code gives you all objects from the master collection (scene collection)

objs = []
master = scene.get_pointer(b'master_collection')
nextObj = collection[b'gobject',b'first']
while nextObj !=0:
    collectionObj = blend.find_block_from_offset(nextObj)
    obj = collectionObj.get_pointer(b'ob')
    objs.append(obj)
    nextObj = = collectionObj[b'next']

Just in case if someone came across this as me looking for a way to get all objects in the scene with blender_asset_tracer, here’s the related stack exchange question that can help - python - How to read out every camera object from blend file? (with blendfile.py) - Blender Stack Exchange