# How to traverse all entities in an OdDbBlockTableRecord?

 1. [FAQ](/ja/faq)
2. »
3. [.dwg support](/faq/dwg-support)

To iterate over all of the entities in a block (for example, model space), you can use code like this:

```plaintext
OdDbObjectId blockId = pDb->getModelSpaceId();
OdDbBlockTableRecordPtr pBlockRecord = blockId.safeOpenObject(OdDb::kForWrite);

OdDbObjectIteratorPtr pIter = pBlockRecord->newIterator();
for (; !pIter->done(); pIter->step())
{
    OdDbObjectId objectId = pIter->objectId();
    OdDbEntityPtr pEntity = objectId.safeOpenObject(OdDb::kForWrite);
    //work with pEntity
}
```

If you only need to get information from entities without modifying them, you should use OdDb::kForRead when opening the block and its entities.

You can learn more about structure of an OdDbDatabase and records in our documentation:

[https://docs.opendesign.com/td/db\_datasheet\_collection.html](https://docs.opendesign.com/td/db_datasheet_collection.html)

[https://docs.opendesign.com/td/db\_datasheet\_iterate.html](https://docs.opendesign.com/td/db_datasheet_iterate.html)
