Larry;
Yes I tested your code and was getting the same results, is strange that you
could not use smart pointers, but no problem, here is your routine using
normal calls... HTH.
🙂
int GetBlockObjectCount(const CString& name)
{
AcDbBlockTable* pBlockTab = NULL;
AcDbDatabase* pCurDB = acDocManager->curDocument()->database();
pCurDB->getBlockTable(pBlockTab, AcDb::kForRead);
AcDbBlockTableRecord* pTabRec = NULL;
if(pBlockTab->getAt(name, pTabRec, AcDb::kForRead) != Acad::eOk)
{
pBlockTab->close();
return -1;
}
pBlockTab->close();
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
AcDbObjectIdArray idArray;
pTabRec->getBlockReferenceIds(idArray);
pTabRec->close();
if(idArray.length() == 0)
return -1;
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
int cnt = 0;
for(int index = 0; index < idArray.length(); index++)
{
AcDbObjectId id = idArray.at(index);
AcDbBlockReference *pRef = NULL;
AcDbBlockTableRecord *pBtr = NULL;
if ((acdbOpenObject(pRef, id, AcDb::kForRead) == Acad::eOk) &&
(acdbOpenObject(pBtr, pRef->blockId(), AcDb::kForRead) == Acad::eOk) &&
pBtr->isLayout())
{
cnt++;
pRef->close();
pBtr->close();
}
//if (pBlockRef == Acad::eOk && pBlockRef->isLayout())
// cnt++;
////if(pBlockRef->isErased() == Adesk::kTrue)
////{
//// pBlockRef->close();
//// continue;
////}
//AcDbObjectPointer
pRef(idArray[index],
AcDb::kForRead);
//if (pRef.openStatus() == Acad::eOk)
//{
// AcDbBlockTableRecordPointer pBtr(pRef->blockId(), AcDb::kForRead);
// if (pBtr.openStatus() == Acad::eOk && pBtr->isLayout())
// cnt++;
//}
// Do some stuff with the block reference here.
////pBlockRef->close();
}
return cnt; //idArray.length();
}