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