|
[code] static void TableInsertTable(void)
{
AcDbTable *pTable = NULL;
pTable = new AcDbTable();
// 2 rows - title and headers
pTable->insertRows(0,10.0);
// 3 columns
pTable->insertColumns(0,10.0,2);
pTable->setTextString(0,0,"TITLE");
// merge the first row for the title
pTable->mergeCells(0,0,0,pTable->numColumns() - 1);
// headers titles
pTable->setTextString(1,0,"Preview");
pTable->setTextString(1,1,"Name");
pTable->setTextString(1,2,"Number");
int row = 2;
AcDbBlockTablePointer pBlockTable(acdbCurDwg(), AcDb::kForRead);
if (pBlockTable.openStatus() != Acad::eOk) return;
AcDbBlockTableIterator *pBTIterator = NULL;
Acad::ErrorStatus es = pBlockTable->newIterator(pBTIterator, true, true);
if (es != Acad::eOk || !pBTIterator) {
acutPrintf("\npBlockTable->newIterator(pBTIterator, true, true)=%s",acadErrorStatusText(es));
return;
}
for (; !pBTIterator->done(); pBTIterator->step()) {
AcDbObjectId BTRId;
es = pBTIterator->getRecordId(BTRId);
if (es != Acad::eOk) {
acutPrintf("\npBTIterator->getRecordId(BTRId)=%s",acadErrorStatusText(es));
delete pBTIterator;
return;
}
AcDbBlockTableRecordPointer pBlockTableRecord(BTRId, AcDb::kForRead);
if (pBlockTableRecord.openStatus() != Acad::eOk) return;
if (pBlockTableRecord->isAnonymous() || // no anonymous blocks
pBlockTableRecord->isFromExternalReference() || // no xref's
pBlockTableRecord->isFromOverlayReference() || // no overlaid xref's
pBlockTableRecord->isLayout()) { // no block layouts *MODEL_SPACE, *PAPER_SPACE...
continue;
}
const char *bName;
es = pBlockTableRecord->getName(bName);
if (es != Acad::eOk) {
acutPrintf("\npBlockTableRecord->getName(bName)=%s",acadErrorStatusText(es));
delete pBTIterator;
return;
}
char text [256]="";;
AcDbObjectIdArray ids;
if (pBlockTableRecord->getBlockReferenceIds(ids) == Acad::eOk) {
int cnt;
cnt = ids.length();
sprintf(text,"%d",cnt);
}
if ((pTable->insertRows(pTable->numRows(),pTable->rowHeight(1)) == Acad::eOk) &&
(pTable->generateLayout() == Acad::eOk)) {
pTable->setBlockTableRecordId(row,0,pBlockTableRecord->objectId(),true);
pTable->setAlignment(row,0,AcDb::kMiddleCenter);
pTable->setTextString(row,1,bName);
pTable->setAlignment(row,1,AcDb::kMiddleCenter);
pTable->setTextHeight(row,1,1.65);
pTable->setTextString(row,2,text);
pTable->setAlignment(row,2,AcDb::kMiddleCenter);
pTable->setTextHeight(row,2,1.65);
} else {
acutPrintf("\nIt is not a TABLE or it can not be opened: %s",
acadErrorStatusText(es));
}
row = (row + 1);
}
delete pBTIterator;
//-----------------------------------------------------------
// You *MUST* close BlockTable before open
// any BlockTableRecord for Write
//-----------------------------------------------------------
pBlockTable->close();
AcDbObjectId curSpaceId = acdbCurDwg()->currentSpaceId();
AcDbBlockTableRecord *pBlkRec = NULL;
if (acdbOpenObject(pBlkRec, curSpaceId, AcDb::kForWrite) == Acad::eOk) {
pBlkRec->appendAcDbEntity(pTable);
pBlkRec->close();
pTable->close();
}
}[/code] |
|