ObjectARX
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Is reverse entity iteration supposed to work?

2 REPLIES 2
Reply
Message 1 of 3
Kyudos
173 Views, 2 Replies

Is reverse entity iteration supposed to work?

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?

2 REPLIES 2
Message 2 of 3
Kyudos
in reply to: Kyudos

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

Message 3 of 3
tbrammer
in reply to: Kyudos

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.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

AutoCAD Inside the Factory


Autodesk Design & Make Report