关于插入dwg的问题求助
整体思路是这样:<br>想通过打开一个dwg文件,然后把这个文件作为一个块,插入到新的dwg文件中<br>
我用下面代码,执行后能够在block table record中查询到插入的记录,但就是无法在<br>
AutoCAD2004的界面中显示出来。<br>
<br>
char *fname;<br>
struct resbuf *rb;<br>
Acad::ErrorStatus error; <br>
<br>
rb = acutNewRb(RTSTR);<br>
acedGetFileD("Pick a drawing", NULL, "dwg", 0, rb);<br>
fname = (char*)acad_malloc(strlen(rb->resval.rstring) + 1);<br>
strcpy(fname, rb->resval.rstring);<br>
acutRelRb(rb);<br>
<br>
AcDbDatabase *pDb = new AcDbDatabase(Adesk::kFalse);<br>
pDb->readDwgFile(fname);<br>
<br>
AcDbObjectId blockId;<br>
char blockName = "MyBlock";<br>
<br>
AcDbDatabase *pThisDB;<br>
pThisDB = acdbHostApplicationServices()->workingDatabase();<br>
<br>
AcGePoint3d ptOrg(10,10,0);<br>
AcGeScale3d XrefScale(10,10,1);<br>
<br>
pThisDB->insert(blockId, blockName, pDb);<br>
<br>
AcDbBlockReference *pBlkRef = new AcDbBlockReference;<br>
error = pBlkRef->setBlockTableRecord(blockId);<br>
error = pBlkRef->setPosition(ptOrg);<br>
error = pBlkRef->setRotation(0);<br>
error = pBlkRef->setScaleFactors( XrefScale);<br>
<br>
AcDbBlockTable *pBlockTable;<br>
error = pDb->getSymbolTable(pBlockTable, AcDb::kForRead);<br>
<br>
AcDbBlockTableRecord *pBlockTableRecord;<br>
pBlockTable->getAt(ACDB_MODEL_SPACE, pBlockTableRecord, AcDb::kForWrite);<br>
pBlockTable->close();<br>
AcDbObjectId newEntId;<br>
error = pBlockTableRecord->appendAcDbEntity(newEntId, pBlkRef);<br>
pBlkRef->close();<br>
<br>
pBlockTableRecord->close();<br>
delete pDb;<br>
<br>
请大虾们指教错误出在哪里?<br>
另外有没有已经实现了的代码供我参考,发送到miraculous@sjtu.edu.cn<br>
不胜感激!<br> <P>谢谢,这样实现了插入,但好像并不是作为一个整体块插入的。因为点击插入后的图形后,可以选择单条直线,而不是作为一个整体块选中。</P>
<P>另外在下面代码前得加上 rb = acutNewRb(RTSTR);否则会有warning C4700: 使用的局部变量“rb”尚未初始化</P>
<P> acedGetFileD("Pick a drawing", NULL, "dwg", 0, rb); <BR> strcpy(fname, rb->resval.rstring);<BR> free(rb->resval.rstring);</P> <P>请<A name=67602><FONT color=#000066><B>pglyxq</B></FONT></A>再指教一下:</P>
<P>我在下列代码中加入了 pDb->wblock(pThisDb, blockId); 可仍然没有实现整个块的插入,请问哪个地方出了问题,谢谢</P>
<P> AcDbDatabase *pThisDb = acdbHostApplicationServices()->workingDatabase();</P>
<P> AcDbObjectId blockId;<BR> char blockName = "MyBlock";</P>
<P> acdbHostApplicationServices()->workingDatabase()<BR> ->insert(blockId, blockName, pDb);</P>
<P> pDb->wblock(pThisDb, blockId); <BR> <BR> acdbHostApplicationServices()->workingDatabase()<BR> ->insert(AcGeMatrix3d::kIdentity, pDb);</P> 我只会2002,呵呵
页:
[1]