the sample code is like this
// - ZHPCDC.TEST command (do not rename)
static void ZHPCDCTEST(void)
{
// Add your code for command ZHPCDC.TEST here
Acad::ErrorStatus es;
CString strTargetFileFullPath = TEXT("D:\\test.dwg");
//create the new file
AcDbDatabase *pNewDb = new AcDbDatabase(true, false);
es = pNewDb->saveAs(strTargetFileFullPath);
delete pNewDb;
// get the targetDb, sourceDb and tempDb
AcDbDatabase *pTargetDb = new AcDbDatabase(false);
pTargetDb->readDwgFile(strTargetFileFullPath);
AcDbDatabase *pSourceDb = acdbHostApplicationServices()->workingDatabase();
AcDbDatabase *pTempDb = new AcDbDatabase(true, true);
es = pSourceDb->wblock(pTempDb);
// get the entities that need clone
AcDbObjectIdArray idsNeedClone;
AcDbBlockTable *pBlkTbl = NULL;
pTempDb->getBlockTable(pBlkTbl, AcDb::kForRead);
AcDbBlockTableRecord *pBlkTblRcd = NULL;
pBlkTbl->getAt(ACDB_MODEL_SPACE, pBlkTblRcd, AcDb::kForWrite);
pBlkTbl->close();
AcDbBlockTableRecordIterator *it = NULL;
pBlkTblRcd->newIterator(it);
for (it->start(); !it->done(); it->step())
{
AcDbObjectId id;
if (Acad::eOk != it->getEntityId(id)) continue;
idsNeedClone.append(id);
}
delete it;
pBlkTblRcd->close();
// clone from tempDb to targetDb
pTempDb->wblock(pTargetDb, idsNeedClone, AcGePoint3d::kOrigin, AcDb::kDrcReplace);
//redraw the entities in targetDb and saveas
CDwgDatabaseUtil::RedrawAllEntitys(pTargetDb);
es = pTargetDb->closeInput(true);
es = acdbSaveAs2004(pTargetDb, strTargetFileFullPath);
delete pTargetDb;
delete pTempDb;
}
and the function
CDwgDatabaseUtil::RedrawAllEntitys(pTargetDb);
is like this
void CDwgDatabaseUtil::RedrawAllEntitys(AcDbDatabase *pDb)
{
// 获得块表
AcDbBlockTable *pBlkTbl = NULL;
pDb->getBlockTable(pBlkTbl, AcDb::kForRead);
// 获得模型空间的块表记录
AcDbBlockTableRecord *pBlkTblRcd = NULL;
pBlkTbl->getAt(ACDB_MODEL_SPACE, pBlkTblRcd, AcDb::kForRead);
pBlkTbl->close();
// 创建遍历器,依次访问模型空间的每一个实体
AcDbBlockTableRecordIterator *it = NULL;
pBlkTblRcd->newIterator(it);
for (it->start(); !it->done(); it->step())
{
AcDbEntity *pEnt = NULL;
if (Acad::eOk == it->getEntity(pEnt, AcDb::kForWrite))
{
pEnt->recordGraphicsModified(true);
pEnt->close();
}
}
delete it;
pBlkTblRcd->close();
}
and here is the video to express my problem
and I tried to call the recomputeDimBlock method like this. But the result is the same...
void CDwgDatabaseUtil::RedrawAllEntitys1(AcDbDatabase *pDb)
{
// 获取块表
AcDbBlockTable *pBlkTbl = NULL;
pDb->getBlockTable(pBlkTbl, AcDb::kForRead);
// 创建遍历器,依次访问块表中的每条块表记录
AcDbBlockTableIterator *it = NULL;
pBlkTbl->newIterator(it);
for (it->start(); !it->done(); it->step())
{
//获取某条块表记录
AcDbBlockTableRecord *pBlkTblRcd = NULL;
it->getRecord(pBlkTblRcd, AcDb::kForRead);
// 创建遍历器,依次访问块表记录中的每一个实体
AcDbBlockTableRecordIterator *rcdIt = NULL;
pBlkTblRcd->newIterator(rcdIt);
for (rcdIt->start(); !rcdIt->done(); rcdIt->step())
{
AcDbEntity *pEnt = NULL;
if (Acad::eOk == rcdIt->getEntity(pEnt, AcDb::kForWrite))
{
if (pEnt->isKindOf(AcDbDimension::desc()))
{
AcDbDimension *pDim = AcDbDimension::cast(pEnt);
pDim->recomputeDimBlock(true);
}
//pEnt->recordGraphicsModified(true);
pEnt->close();
}
}
delete rcdIt;
pBlkTblRcd->close();
}
delete it;
pBlkTbl->close();
}
So what is problem in my code?