The documentation led me to try this:
AcDbDatabase* db = acdbHostApplicationServices()->workingDatabase();
AcDbBlockTable* blockTable = nullptr;
if (db->getBlockTable(blockTable, AcDb::kForRead) == Acad::eOk)
{
AcDbBlockTableRecord* modelSpace = nullptr;
if (blockTable->getAt(ACDB_MODEL_SPACE, modelSpace, AcDb::kForRead) == Acad::eOk)
{
AcDbBlockTableRecordIterator* iter_f = nullptr;
AcDbBlockTableRecordIterator* iter_r = nullptr;
modelSpace->newIterator(iter_f, true);
modelSpace->newIterator(iter_r, false);
AcDbEntity* ent1 = nullptr;
AcDbEntity* ent2 = nullptr;
iter_f->start();
iter_r->start();
iter_f->getEntity(ent1, AcDb::kForRead);
iter_r->getEntity(ent2, AcDb::kForRead);
if (ent1 == ent2)
{
int i = 0;
}
}
}
Both iterators return the same entity. Have I misunderstood something? Or is there a better way to get the last entity created?
OK...this is apparently what makes the difference:
iter_f->start(true);
iter_r->start(false);
I'm not sure what (if anything) the flag on newIterator is doing...
According to the docs the flag in newIterator(..,flag) makes a difference.
I suppose that the iterator would be placed at the end if you don't call iter->start(flag) at all.
I would recommend to pass false to both functions if you want to iterate backwards.
Also remember that AcDbBlockTableRecordIterator::step(bool forward, bool skipDeleted) needs forward=false then.
Can't find what you're looking for? Ask the community or share your knowledge.