|
我要实现的功能是:在cad中已经打开了一个文件,然后我提取了这个数据库中我所需要的某些实体并存入ID,然后用acDocManager再新建一个文档,然后把刚才存起来的实体写入这个新建的模型空间,可是要么写入原来的文档中,要么就写不进去,请问要如何实现呢。已经调试发现现在得问题是运行到写入的时候CAD提示不能写入,请问是为什么。下面是试验代码,请各位帮帮忙吧,谢谢大家:
void main()
{
newSyncDoc();
AcApDocument* NewDoc; //
pDocIter = acDocManager->newAcApDocumentIterator(); //
for ( ; !pDocIter->done(); pDocIter->step()) //
{ //找到新建文档指针
NewDoc = pDocIter->document(); //
} //
delete pDocIter; //
acDocManager->setCurDocument(NewDoc); //设置当前文档
acDocManager->activateDocument(NewDoc,true); //激活当前文档,并且第2个参数要设为ture,否则不往下运行。
acDocManager->unlockDocument(NewDoc); //将新建文档解锁
AcDbDatabase* pNewDb=NewDoc->database(); //得到新建文档连接的数据库
AcDbBlockTable* pBlockTable;
pNewDb->getSymbolTable(pBlockTable,AcDb::kForRead);
AcDbBlockTableRecord* pBlockTableRecord;
pBlockTable->getAt(ACDB_MODEL_SPACE,pBlockTableRecord,AcDb::kForWrite);
pBlockTable->close();
AcGePoint3d ptCenter(0,0,0); //
AcGeVector3d vec(0,0,1); //
double rad=10000; //
AcDbCircle* pCircle=new AcDbCircle(ptCenter,vec,rad); //做了个圆写进去
AcDbObjectId id; //
pBlockTableRecord->appendAcDbEntity(id,pCircle); //到这里就出错了,CAD显示写入错误
pBlockTableRecord->close();
acDocManager->lockDocument(NewDoc); //将新建文档锁定
delete pNewDb;
}
void newSyncDocHelper(void *pData)
{
AcApDocument* pDoc = acDocManager->curDocument();
if (acDocManager->isApplicationContext())
{
acDocManager->appContextNewDocument((const TCHAR *)pData);
acDocManager->activateDocument(pDoc); //激活原先的文档,否则运行到newSyncDoc()语句后不往下运行
}
else
acutPrintf(_T("\nERROR: in Document context : %s\n"),pDoc->fileName());
}
void newSyncDoc()
{
static TCHAR pData[] = _T(/*NOXLATE*/"acad.dwt");
AcApDocument* pDoc = acDocManager->curDocument();
if (pDoc)
{
acDocManager->executeInApplicationContext(newSyncDocHelper, (void *)pData);
}
} |
|