- 积分
- 316
- 明经币
- 个
- 注册时间
- 2005-4-22
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
AcDbDatabase* pDb = new AcDbDatabase(false, true); pDb->readDwgFile(File); AcDbBlockTable *pBlockTable; pDb->getSymbolTable(pBlockTable, AcDb::kForRead); AcDbBlockTableRecord *pBlockTableRecord; pBlockTable->getAt(ACDB_MODEL_SPACE, pBlockTableRecord, AcDb::kForWrite); pBlockTable->close(); AcDbBlockTableRecordIterator *pBlockIterator; pBlockTableRecord->newIterator(pBlockIterator); for (; !pBlockIterator->done(); pBlockIterator->step()) { AcDbEntity *pEntity; pBlockIterator->getEntity(pEntity, AcDb::kForWrite); const char *pCname = pEntity->isA()->name(); if(!strcmp(pCname, "AcDbText")) { const char *pText = ((AcDbText*)pEntity)->textString(); CString st(pText); st.Replace(m_SearchStr,m_ReplaceStr); if (((AcDbText*)pEntity)->setTextString(st) != Acad::eOk) { acutPrintf("\nSorry, that draing is probably already open."); return; } } else if(!strcmp(pCname, "AcDbMText")) { const char *pMText = ((AcDbMText*)pEntity)->contents(); CString st(pMText); st.Replace(m_SearchStr,m_ReplaceStr); ((AcDbMText*)pEntity)->setContents(st); if(pMText) pMText = NULL; } pEntity->close(); } delete pBlockIterator; pBlockTableRecord->close(); pDb->saveAs(File); delete pDb;
其他代码省略,我在运行后,一般DWG文件能够正常替换,但有个别文件不能够替换,AutoCAD报出致命错误:“内部错误 dbobji.cpp@5717:eNotOpenForWrite",调试过程中发现问题出在“((AcDbText*)pEntity)->setTextString(st)”,但为何有的文件又能够替成功呢,请大家指教,谢谢! |
|