Is there a way to get all objects in Model Space?

Iā€™m looking to check for objects actually used in the model space. I have googled for an answer come across the following code:

            bt = t.GetObject(db.BlockTableId, OpenMode.ForWrite)
            btr = t.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite)

but the second line does not appear to work and I cannot determine why. Is there another way to determine if an object exists in model space?

Is it a requirement to do it in Python? If not, you can do it like this with nodes:

Document.Current ā†’ Document.ModelSpace ā†’ Block.Objects

2 Likes