Is reverse entity iteration supposed to work?

Is reverse entity iteration supposed to work?

Kyudos
Advisor Advisor
757 Views
2 Replies
Message 1 of 3

Is reverse entity iteration supposed to work?

Kyudos
Advisor
Advisor

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?

0 Likes
758 Views
2 Replies
Replies (2)
Message 2 of 3

Kyudos
Advisor
Advisor

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...

0 Likes
Message 3 of 3

tbrammer
Advisor
Advisor

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.


Thomas Brammer ● Software Developer ● imos AGLinkedIn
If an answer solves your problem please [ACCEPT SOLUTION]. Otherwise explain why not.

0 Likes