Message 1 of 6
getBlockReferenceIds and layouts

Not applicable
06-17-2005
01:44 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
The subject line kinda sums it up, in my app I need to gather block
REFernces in the current layout only. Thought I had the answer, not.
Seems I can find them in either all layouts or none. Does anyone know
how to accomplish this? I posted my function below, hope the mail
program hasnt mangled beyond comprehension.
Thanks for any pointers
Perry
//////////////////////////////////////////////////////////////////////
// Get block reference ID's for the block 'TBREVISION'
// In the current layout only.
// Note, this gets block REF's not block DEF's!
//////////////////////////////////////////////////////////////////////
Acad::ErrorStatus CRevision::GetRevBlockIds(AcDbObjectIdArray& refEnts)
{
Acad::ErrorStatus es;
AcDbDatabase *pCurDb;
AcDbBlockTable *pBlkTable = NULL;
AcDbBlockTableRecord *pBlkTableRecord;
AcDbObjectId blkID;
const char *currentLayoutName =
acdbHostApplicationServices()->layoutManager()->findActiveLayout(Adesk::kTrue);
AcDbLayout *pcurrentLayout =
acdbHostApplicationServices()->layoutManager()->findLayoutNamed(currentLayoutName,Adesk::kFalse);
AcDbObjectId pLayoutBlkId = pcurrentLayout->getBlockTableRecordId();
pCurDb = acdbHostApplicationServices()->workingDatabase();
if ((es = pCurDb->getBlockTable(pBlkTable, AcDb::kForRead)) == Acad::eOk)
{
//See if the block DEF exists before looking for References, if it does...
if (pBlkTable->has("TBREVISION"))
{
//This code chunk finds refs in ALL layouts
pBlkTable->getAt("TBREVISION", blkID);
if ((es = acdbOpenObject((AcDbObject *&)pBlkTableRecord, blkID,
AcDb::kForRead)) == Acad::eOk)
{
es = pBlkTableRecord->getBlockReferenceIds(refEnts);
if (es != Acad::eOk)
{
acutPrintf("\nCRevision::GetRevBlockIds Couldnt get block refs");
return es;
}
}
else
acutPrintf("\nERROR: CRevision::GetRevBlockIds couldnt open block.");
//This code chunk is supposed to find refs in ONLY the current
layout, but finds none.
/*
if ((es = acdbOpenObject((AcDbObject *&)pBlkTableRecord,
pLayoutBlkId, AcDb::kForRead)) == Acad::eOk)
{
es = pBlkTableRecord->getBlockReferenceIds(refEnts);
if (es != Acad::eOk)
{
acutPrintf("\nCRevision::GetRevBlockIds Couldnt get block refs");
return es;
}
}
else
acutPrintf("\nERROR: CRevision::GetRevBlockIds couldnt open block.");
*/
pBlkTableRecord->close();
}
}
pBlkTable->close();
return es;
}
REFernces in the current layout only. Thought I had the answer, not.
Seems I can find them in either all layouts or none. Does anyone know
how to accomplish this? I posted my function below, hope the mail
program hasnt mangled beyond comprehension.
Thanks for any pointers
Perry
//////////////////////////////////////////////////////////////////////
// Get block reference ID's for the block 'TBREVISION'
// In the current layout only.
// Note, this gets block REF's not block DEF's!
//////////////////////////////////////////////////////////////////////
Acad::ErrorStatus CRevision::GetRevBlockIds(AcDbObjectIdArray& refEnts)
{
Acad::ErrorStatus es;
AcDbDatabase *pCurDb;
AcDbBlockTable *pBlkTable = NULL;
AcDbBlockTableRecord *pBlkTableRecord;
AcDbObjectId blkID;
const char *currentLayoutName =
acdbHostApplicationServices()->layoutManager()->findActiveLayout(Adesk::kTrue);
AcDbLayout *pcurrentLayout =
acdbHostApplicationServices()->layoutManager()->findLayoutNamed(currentLayoutName,Adesk::kFalse);
AcDbObjectId pLayoutBlkId = pcurrentLayout->getBlockTableRecordId();
pCurDb = acdbHostApplicationServices()->workingDatabase();
if ((es = pCurDb->getBlockTable(pBlkTable, AcDb::kForRead)) == Acad::eOk)
{
//See if the block DEF exists before looking for References, if it does...
if (pBlkTable->has("TBREVISION"))
{
//This code chunk finds refs in ALL layouts
pBlkTable->getAt("TBREVISION", blkID);
if ((es = acdbOpenObject((AcDbObject *&)pBlkTableRecord, blkID,
AcDb::kForRead)) == Acad::eOk)
{
es = pBlkTableRecord->getBlockReferenceIds(refEnts);
if (es != Acad::eOk)
{
acutPrintf("\nCRevision::GetRevBlockIds Couldnt get block refs");
return es;
}
}
else
acutPrintf("\nERROR: CRevision::GetRevBlockIds couldnt open block.");
//This code chunk is supposed to find refs in ONLY the current
layout, but finds none.
/*
if ((es = acdbOpenObject((AcDbObject *&)pBlkTableRecord,
pLayoutBlkId, AcDb::kForRead)) == Acad::eOk)
{
es = pBlkTableRecord->getBlockReferenceIds(refEnts);
if (es != Acad::eOk)
{
acutPrintf("\nCRevision::GetRevBlockIds Couldnt get block refs");
return es;
}
}
else
acutPrintf("\nERROR: CRevision::GetRevBlockIds couldnt open block.");
*/
pBlkTableRecord->close();
}
}
pBlkTable->close();
return es;
}