TCHAR s[100]; AcGePoint3d ptemp; CStdioFile f; CFileException e; double val; TCHAR *pFileName = _T("D:\\尺寸值.txt"); if (!f.Open(pFileName, CFile::modeCreate | CFile::modeWrite, &e)) { acutPrintf(_T("\n创建导出文件失败!")); return; } AcDbLayerTable *pLayerTbl; acdbHostApplicationServices()->workingDatabase() ->getSymbolTable(pLayerTbl, AcDb::kForRead); acedGetString(NULL,_T("请输入要查找的图层名称:"),s); if (!pLayerTbl->has(s)) { acutPrintf(_T("\n当前图形中未包含你要查找的图层!")); pLayerTbl->close(); return; } AcDbObjectId layerId; // 图层的ID pLayerTbl->getAt(s, layerId); pLayerTbl->close(); // 获得当前数据库的块表 AcDbBlockTable *pBlkTbl; acdbHostApplicationServices()->workingDatabase() ->getBlockTable(pBlkTbl, AcDb::kForRead); // 获得模型空间的块表记录 AcDbBlockTableRecord *pBlkTblRcd; pBlkTbl->getAt(ACDB_MODEL_SPACE, pBlkTblRcd, AcDb::kForRead); pBlkTbl->close(); // 创建块表记录遍历器 AcDbBlockTableRecordIterator *pItr; // 块表记录遍历器 pBlkTblRcd->newIterator(pItr); AcDbEntity *pEnt; // 遍历的临时实体指针 for (pItr->start(); !pItr->done(); pItr->step()) { // 利用遍历器获得每一个实体 pItr->getEntity(pEnt, AcDb::kForWrite); // 是否在图层上 if (pEnt->layerId() == layerId) { AcDbAlignedDimension *adimension = AcDbAlignedDimension::cast(pEnt);//对齐标注 AcDbRotatedDimension *rodimension =AcDbRotatedDimension::cast(pEnt);//转角标注 AcDbRadialDimension *rdimension =AcDbRadialDimension::cast(pEnt);//半径标注 AcDbDiametricDimension *ddimension =AcDbDiametricDimension::cast(pEnt);//直径标注 AcDbOrdinateDimension *odimension =AcDbOrdinateDimension::cast(pEnt);//坐标标注 AcDb2LineAngularDimension *ldimension=AcDb2LineAngularDimension::cast(pEnt);//角度标注 if (adimension != NULL) { acutPrintf(_T("\n对齐标注文字是: %.0f"),adimension->measurement( val )); CString duiqi; CString str1; str1.Format(_T("%d"), adimension->measurement( val)); duiqi="对齐标注文字是:"; duiqi+= str1; f.WriteString(duiqi); f.WriteString(_T("\n")); } if (rodimension != NULL) { acutPrintf(_T("\n转角标注文字是: %.0f"),rodimension->measurement(val)); CString zhuanjiao; CString str2; str2.Format(_T("%.0f"), rodimension->measurement(val)); zhuanjiao="转角标注文字是:"; zhuanjiao+= str2; f.WriteString(zhuanjiao); f.WriteString(_T("\n")); } if (rdimension != NULL) { acutPrintf(_T("\n半径标注文字是: %.0f"),rdimension->measurement(val)); CString banjing; CString str3; str3.Format(_T("%.0f"),rdimension->measurement(val)); banjing="半径标注文字是:"; banjing+= str3; f.WriteString(banjing); f.WriteString(_T("\n")); } if (ddimension!= NULL) { acutPrintf(_T("\n直径标注文字是: %.0f"),ddimension->measurement(val)); CString zhijing; CString str4; str4.Format(_T("%.0f"),ddimension->measurement(val)); zhijing="直径标注文字是:"; zhijing+= str4; f.WriteString(zhijing); f.WriteString(_T("\n")); } if (odimension!= NULL) { acutPrintf(_T("\n坐标标注文字是: %.0f"),odimension->measurement(val)); CString zuobiao; CString str5; str5.Format(_T("%.0f"),odimension->measurement(val)); zuobiao="坐标标注文字是:"; zuobiao+= str5; f.WriteString(zuobiao); f.WriteString(_T("\n")); } if (ldimension != NULL) { acutPrintf(_T("\n角度标注文字是: %.0f"),ldimension->measurement(val)); CString jiaodu; CString str6; str6.Format(_T("%.0f"),ldimension->measurement(val)); jiaodu="角度标注文字是:"; jiaodu+= str6; f.WriteString(jiaodu); f.WriteString(_T("\n")); } } // 关闭实体 pEnt->close(); } delete pItr; // 删除遍历器! pBlkTblRcd->close(); 高手帮忙看看这个程序啊,我调了好长时间了,就是达不到我要的结果,我想输出尺寸标注值! |