这是我现在拥有的代码。注意 由于块已入,该文件可能不存在
loger
- truct BlockInfo
- {
- CString name;
- AcArray preview;
- };
- typedef CArray[B] BlockInfoArray;
- Acad::ErrorStatus BlockWorker::getBlockInfoFromdDb( BlockInfoArray &blocks )
- {
- AcDbObjectId blkId, BtrId;
- CString blkName = getBlockName();
- Acad::ErrorStatus es = Acad::eOk;
- if(blkName.IsEmpty())
- return Acad::eInvalidBlockName;
- std::auto_ptr blkDb(new AcDbDatabase(Adesk::kFalse,Adesk::kTrue));
- if( (es = blkDb->readDwgFile(m_path,_SH_DENYWR)) != Acad::eOk)
- {
- acutPrintf(_T("\nError: Line %ld [%s]\nIn function %s"),
- __LINE__, acadErrorStatusText(es),_T(__FUNCTION__));
- return es;
- }
- AcDbBlockTablePointer pBlockTablePointer(blkDb->blockTableId(), AcDb::kForRead);
- if( (es = pBlockTablePointer.openStatus()) != Acad::eOk)
- {
- acutPrintf(_T("\nError: Line %ld [%s]\nIn function %s"),
- __LINE__, acadErrorStatusText(es),_T(__FUNCTION__));
- return es;
- }
- AcDbBlockTableIterator *pIter = NULL;
- if ( (es = pBlockTablePointer->newIterator(pIter)) != Acad::eOk)
- {
- acutPrintf(_T("\nError: Line %ld [%s]\nIn function %s"),
- __LINE__, acadErrorStatusText(es),_T(__FUNCTION__));
- return es;
- }
- for(pIter->start();!pIter->done(); pIter->step())
- {
- if(pIter->getRecordId(BtrId) == Acad::eOk)
- {
- AcDbBlockTableRecordPointer pBtr ( BtrId, AcDb::kForRead);
- if(pBtr.openStatus() == Acad::eOk)
- {
- if(pBtr->isAnonymous() || pBtr->isLayout() ||
- pBtr->isFromExternalReference() || pBtr->isFromOverlayReference())
- {
- continue;
- }
- TCHAR *name = 0;
- if(pBtr->getName(name) == Acad::eOk)
- {
- BlockInfo info;
- info.name = name;
- pBtr->getPreviewIcon(info.preview);
- blocks.Add(info);
- acutDelString(name);
- //if(pBtr->hasPreviewIcon() && info.preview.length() == 0)
- //acutPrintf(_T("\nBooooo Yuk"));
- }
- }
- }
- }
- delete pIter;
- return es;
- }
|