Miracle 发表于 2005-11-9 20:37:00

关于插入dwg的问题求助

整体思路是这样:<br>
想通过打开一个dwg文件,然后把这个文件作为一个块,插入到新的dwg文件中<br>
我用下面代码,执行后能够在block table record中查询到插入的记录,但就是无法在<br>
AutoCAD2004的界面中显示出来。<br>
&nbsp;<br>
&nbsp;&nbsp;&nbsp; char *fname;<br>
&nbsp;&nbsp;&nbsp; struct resbuf *rb;<br>
&nbsp;&nbsp;&nbsp; Acad::ErrorStatus error; <br>
<br>
&nbsp;&nbsp;&nbsp; rb = acutNewRb(RTSTR);<br>
&nbsp;&nbsp;&nbsp; acedGetFileD("Pick a drawing", NULL, "dwg", 0, rb);<br>
&nbsp;&nbsp;&nbsp; fname = (char*)acad_malloc(strlen(rb-&gt;resval.rstring) + 1);<br>
&nbsp;&nbsp;&nbsp; strcpy(fname, rb-&gt;resval.rstring);<br>
&nbsp;&nbsp;&nbsp; acutRelRb(rb);<br>
<br>
&nbsp;&nbsp;&nbsp; AcDbDatabase *pDb = new AcDbDatabase(Adesk::kFalse);<br>
&nbsp;&nbsp;&nbsp; pDb-&gt;readDwgFile(fname);<br>
<br>
&nbsp;&nbsp;&nbsp; AcDbObjectId blockId;<br>
&nbsp;&nbsp;&nbsp; char blockName = "MyBlock";<br>
<br>
&nbsp;&nbsp;&nbsp; AcDbDatabase *pThisDB;<br>
&nbsp;&nbsp;&nbsp; pThisDB = acdbHostApplicationServices()-&gt;workingDatabase();<br>
<br>
&nbsp;&nbsp;&nbsp; AcGePoint3d ptOrg(10,10,0);<br>
&nbsp;&nbsp;&nbsp; AcGeScale3d XrefScale(10,10,1);<br>
<br>
&nbsp;&nbsp;&nbsp; pThisDB-&gt;insert(blockId, blockName, pDb);<br>
<br>
&nbsp;&nbsp;&nbsp; AcDbBlockReference *pBlkRef = new AcDbBlockReference;<br>
&nbsp;&nbsp;&nbsp; error = pBlkRef-&gt;setBlockTableRecord(blockId);<br>
&nbsp;&nbsp;&nbsp; error = pBlkRef-&gt;setPosition(ptOrg);<br>
&nbsp;&nbsp;&nbsp; error = pBlkRef-&gt;setRotation(0);<br>
&nbsp;&nbsp;&nbsp; error = pBlkRef-&gt;setScaleFactors( XrefScale);<br>
<br>
&nbsp;&nbsp;&nbsp; AcDbBlockTable *pBlockTable;<br>
&nbsp;&nbsp;&nbsp; error = pDb-&gt;getSymbolTable(pBlockTable, AcDb::kForRead);<br>
<br>
&nbsp;&nbsp;&nbsp; AcDbBlockTableRecord *pBlockTableRecord;<br>
&nbsp;&nbsp;&nbsp; pBlockTable-&gt;getAt(ACDB_MODEL_SPACE, pBlockTableRecord, AcDb::kForWrite);<br>
&nbsp;&nbsp;&nbsp; pBlockTable-&gt;close();<br>
&nbsp;&nbsp;&nbsp; AcDbObjectId newEntId;<br>
&nbsp;&nbsp;&nbsp; error = pBlockTableRecord-&gt;appendAcDbEntity(newEntId, pBlkRef);<br>
&nbsp;&nbsp;&nbsp; pBlkRef-&gt;close();<br>
<br>
&nbsp;&nbsp;&nbsp; pBlockTableRecord-&gt;close();<br>
&nbsp;&nbsp;&nbsp; delete pDb;<br>
<br>
请大虾们指教错误出在哪里?<br>
另外有没有已经实现了的代码供我参考,发送到miraculous@sjtu.edu.cn<br>
不胜感激!<br>

pglyxq 发表于 2005-11-10 01:12:00

Miracle 发表于 2005-11-10 22:11:00

<P>谢谢,这样实现了插入,但好像并不是作为一个整体块插入的。因为点击插入后的图形后,可以选择单条直线,而不是作为一个整体块选中。</P>
<P>另外在下面代码前得加上&nbsp;rb = acutNewRb(RTSTR);否则会有warning C4700: 使用的局部变量“rb”尚未初始化</P>
<P>&nbsp;&nbsp;&nbsp; acedGetFileD("Pick a drawing", NULL, "dwg", 0, rb); <BR>&nbsp;&nbsp;&nbsp; strcpy(fname, rb-&gt;resval.rstring);<BR>&nbsp;&nbsp;&nbsp; free(rb-&gt;resval.rstring);</P>

pglyxq 发表于 2005-11-11 00:32:00

Miracle 发表于 2005-11-11 16:31:00

<P>请<A name=67602><FONT color=#000066><B>pglyxq</B></FONT></A>再指教一下:</P>
<P>我在下列代码中加入了&nbsp;pDb-&gt;wblock(pThisDb, blockId); 可仍然没有实现整个块的插入,请问哪个地方出了问题,谢谢</P>
<P>&nbsp;AcDbDatabase *pThisDb = acdbHostApplicationServices()-&gt;workingDatabase();</P>
<P>&nbsp;AcDbObjectId blockId;<BR>&nbsp;char blockName = "MyBlock";</P>
<P>&nbsp;acdbHostApplicationServices()-&gt;workingDatabase()<BR>&nbsp;&nbsp;&nbsp; -&gt;insert(blockId, blockName, pDb);</P>
<P>&nbsp;pDb-&gt;wblock(pThisDb, blockId); <BR>&nbsp;<BR>&nbsp;acdbHostApplicationServices()-&gt;workingDatabase()<BR>&nbsp;&nbsp;&nbsp; -&gt;insert(AcGeMatrix3d::kIdentity, pDb);</P>

bai_cai101 发表于 2005-11-20 16:15:00

我只会2002,呵呵
页: [1]
查看完整版本: 关于插入dwg的问题求助