- UID
- 98132
- 积分
- 0
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2003-11-27
- 最后登录
- 1970-1-1
|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
由于要将DWG文件中N多的文字进行翻译, 想到了先将所有的文字全部导出到一文本文件中(已实现,代码如下)
//导出DWG文件中的文字串
void CTransTextDlg::OnBtExportText()
{
// TOD Add your control notification handler code here
AcDbDatabase* pDb;
AcDbBlockTable *pBlockTable;
pDb = acdbHostApplicationServices()->workingDatabase();
pDb->getSymbolTable(pBlockTable, AcDb::kForRead);
AcDbBlockTableRecord *pBlockTableRecord;
pBlockTable->getAt(ACDB_MODEL_SPACE, pBlockTableRecord, AcDb::kForRead);
pBlockTable->close();
AcDbBlockTableRecordIterator *pBlockIterator;
pBlockTableRecord->newIterator(pBlockIterator);
//打开文件用于输出
CString szFilter=_T("Data Files (*.dat;*.txt)|*.dat; *.txt|All Files (*.*)|*.*||");
CString szDefExt(_T(".DAT"));
CAcUiFileDialog dlg(FALSE, szDefExt, NULL,
OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, szFilter);
dlg.DoModal();
CString strFileName;
strFileName = dlg.GetFileName();
ofstream out(strFileName);
if(!out)
{
MessageBox("指定导出文件无法打开!");
return;
}
//设置计数器
LONG lCounts = 0;
for (; !pBlockIterator->done(); pBlockIterator->step())
{
AcDbEntity *pEntity;
pBlockIterator->getEntity(pEntity, AcDb::kForRead);
const char *pCname = pEntity->isA()->name();
if(!strcmp(pCname, "AcDbText")) //是单行文字类
{
//获取文字内容
lCounts++;
const char *pText = ((AcDbText*)pEntity)->textString();
out<objectId()<<",\t"< }
else if(!strcmp(pCname, "AcDbMText")) //是多行文字类
{
lCounts++;
const char *pMText = ((AcDbMText*)pEntity)->contents();
out<objectId()<<",\t"< if(pMText)
pMText = NULL;
}
pEntity->close();
}
out.close();
delete pBlockIterator;
pBlockTableRecord->close();
}
翻译后欲重新导入原DWG文件中, 如下:
void CTransTextDlg::OnBtSubsTexts()
{
// TOD Add your control notification handler code here
//打开文件用于输出
AcDbDatabase* pDb;
AcDbBlockTable *pBlockTable;
pDb = acdbHostApplicationServices()->workingDatabase();
pDb->getBlockTable(pBlockTable, AcDb::kForRead);
AcDbBlockTableRecord *pBlockTableRecord;
pBlockTable->getAt(ACDB_MODEL_SPACE, pBlockTableRecord, AcDb::kForRead);
pBlockTable->close();
AcDbBlockTableRecordIterator *pBlockIterator;
pBlockTableRecord->newIterator(pBlockIterator);
CString szFilter=_T("Data Files (*.dat;*.txt)|*.dat; *.txt|All Files (*.*)|*.*||");
CString szDefExt(_T(".DAT"));
CAcUiFileDialog dlg(TRUE, szDefExt, NULL,
OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, szFilter);
dlg.DoModal();
CString strFileName;
strFileName = dlg.GetFileName();
ifstream in(strFileName);
if(!in)
{
MessageBox("指定导入文件无法打开!");
return;
}
//设置计数器
LONG lCounts = 0;
LONG lID;
for (; !pBlockIterator->done(); pBlockIterator->step())
{
AcDbEntity *pEntity;
Acad::ErrorStatus es;
es = pBlockIterator->getEntity(pEntity, AcDb::kForRead);
switch(es)
{
case Acad::eOk:
acutPrintf("Acad::eOk\n");
break;
case Acad::ePermanentlyErased:
acutPrintf("Acad::ePermanentlyErased\n");
break;
case Acad::eAtMaxReaders:
acutPrintf("Acad::eAtMaxReaders\n");
break;
case Acad::eWasOpenForNotify:
acutPrintf("Acad::eWasOpenForNotify\n");
break;
case Acad::eWasNotifying:
acutPrintf("Acad::eWasNotifying\n");
break;
case Acad::eWasOpenForUnd
acutPrintf("Acad::eWasOpenForUndo\n");
break;
case Acad::eWasOpenForWrite:
acutPrintf("Acad::eWasOpenForWrite\n");
break;
case Acad::eWasOpenForRead:
acutPrintf("Acad::eWasOpenForRead\n");
break;
default:
acutPrintf("Unknown error type.\n");
break;
}
const char *pCname = pEntity->isA()->name();
if(!strcmp(pCname, "AcDbText")) //是单行文字类
{
//获取文字内容
acutPrintf("Step -- %ld\n", 4+lCounts);
lCounts++;
char inStr[256];
in>>lID>>inStr;
((AcDbText*)pEntity)->setTextString(inStr);
}
else if(!strcmp(pCname, "AcDbMText")) //是多行文字类
{
lCounts++;
char inStr[1024];
in>>lID>>inStr;
((AcDbMText*)pEntity)->setContents(inStr);
}
pEntity->close();
}
in.close();
delete pBlockIterator;
pBlockTableRecord->close();
}
可却有错! 请教了!!!
EMAIL: yuleyue@yahoo.com |
|