lanhaiou 发表于 2006-10-11 16:49:00

大虾帮忙看看程序吧

<P>整个程序主要是为了从dwg文件中得到图块的包罗矩形的两个点.(不知道有没有其他的方法)</P>
<P>下面怎么老是得不到&nbsp;包络矩形的两个点呢?</P>
<P>只会得到**Error on get the extents point...</P>
<P>不知道是那里出问题了?大虾们帮忙看看吧</P>
<P>//插入图形<BR>&nbsp;<BR>&nbsp;Acad::ErrorStatus es;<BR>&nbsp;CString filename="E:\\autocad\\dwgfile\\qq.dwg";//已经存在的文件<BR>&nbsp;AcDbDatabase *pNewDb=new AcDbDatabase(Adesk::kFalse);<BR>&nbsp;es=pNewDb-&gt;readDwgFile(filename,_SH_DENYNO,false);<BR>&nbsp;if(es!=Acad::eOk)<BR>&nbsp;{<BR>&nbsp;&nbsp;acutPrintf("\nThe file %s cannot be opend",filename); <BR>&nbsp;&nbsp;return; <BR>&nbsp;}<BR>&nbsp;<BR>&nbsp;AcDbDatabase *pDb;<BR>&nbsp;pDb=acdbHostApplicationServices()-&gt;workingDatabase();<BR></P>
<P>&nbsp;CString pBlockName="testblock";<BR>&nbsp;AcDbObjectId blockID;<BR>&nbsp;<BR>&nbsp;if((es=pDb-&gt;insert(blockID, pBlockName,pNewDb,true))==Acad::eOk) <BR>&nbsp;{ acutPrintf("\ninsert ok\n"); <BR>&nbsp;&nbsp;delete pNewDb;} <BR>&nbsp;else <BR>&nbsp;{ AfxMessageBox("Insert failed"); <BR>&nbsp;&nbsp;delete pNewDb; <BR>&nbsp;&nbsp;return; } </P>
<P>&nbsp;<BR>&nbsp;AcGePoint3d pt(100.0,200.0,0.0);<BR>&nbsp;AcDbBlockReference *pBlkRef = new AcDbBlockReference; <BR>&nbsp;pBlkRef-&gt;setBlockTableRecord(blockID);//指向blockId; <BR>&nbsp;pBlkRef-&gt;setPosition(pt);//设定位置&nbsp;<BR><BR>&nbsp;AcDbBlockTable *pBlockTable; <BR>&nbsp;pDb-&gt;getBlockTable(pBlockTable, AcDb::kForRead); </P>
<P>&nbsp;AcDbBlockTableRecord *pBlockTableRecord; <BR>&nbsp;pBlockTable-&gt;getAt(ACDB_MODEL_SPACE, pBlockTableRecord, AcDb::kForWrite); <BR>&nbsp;pBlockTable-&gt;close(); <BR>&nbsp;AcDbObjectId newEntId; <BR>&nbsp;pBlockTableRecord-&gt;appendAcDbEntity(newEntId, pBlkRef); <BR>&nbsp;pBlockTableRecord-&gt;close(); <BR>&nbsp;pBlkRef-&gt;close();</P>
<P>///////取得包络矩形的两个顶点<BR><BR>&nbsp; AcDbEntity *pEnt;<BR>&nbsp; acdbOpenAcDbEntity(pEnt,newEntId,AcDb::kForRead);</P>
<P>&nbsp;AcDbExtents exts;<BR>&nbsp; if(pEnt-&gt;getGeomExtents(exts)!=Acad::eOk);<BR>&nbsp; {<BR>&nbsp;&nbsp; acutPrintf("\n**Error on get the extents point...");<BR>&nbsp;&nbsp; pEnt-&gt;close();<BR>&nbsp;&nbsp; return;<BR>&nbsp; }<BR>&nbsp; acutPrintf("\nThe maxPoint=%0.4f,%0.4f",exts.maxPoint(),exts.maxPoint());<BR>&nbsp; acutPrintf("\nThe minPoint=%0.4f,%0.4f",exts.minPoint(),exts.minPoint());<BR>&nbsp; pEnt-&gt;close();</P>

easypower 发表于 2006-10-11 18:51:00

你这种好象要通过事务处理才能实现

lanhaiou 发表于 2006-10-12 19:02:00

<P>哦,可是必须要事务处理吗?</P>
<P>不能把图块读到当前数据库中,再对图块操作吗?</P>

lanhaiou 发表于 2006-10-12 19:48:00

<P>好了,问题解决了。这样就得到了。谢谢<A name=35140><FONT color=#990000><B>easypower</B></FONT></A> 的答复</P>
<P>&nbsp;Acad::ErrorStatus es;<BR>&nbsp;CString filename="E:\\autocad\\dwgfile\\qq.dwg";//已经存在的文件<BR>&nbsp;AcDbDatabase *pNewDb=new AcDbDatabase(Adesk::kFalse);<BR>&nbsp;es=pNewDb-&gt;readDwgFile(filename,_SH_DENYNO,false);<BR>&nbsp;if(es!=Acad::eOk)<BR>&nbsp;{<BR>&nbsp;&nbsp;acutPrintf("\nThe file %s cannot be opend",filename); <BR>&nbsp;&nbsp;return; <BR>&nbsp;}<BR>&nbsp;<BR>&nbsp;AcDbDatabase *pDb;<BR>&nbsp;pDb=acdbHostApplicationServices()-&gt;workingDatabase();<BR></P>
<P>&nbsp;CString pBlockName="testblock";<BR>&nbsp;AcDbObjectId blockID;<BR>&nbsp;<BR>&nbsp;if((es=pDb-&gt;insert(blockID, pBlockName,pNewDb,true))==Acad::eOk) <BR>&nbsp;{ acutPrintf("\ninsert ok\n"); <BR>&nbsp;&nbsp;delete pNewDb;} <BR>&nbsp;else <BR>&nbsp;{ AfxMessageBox("Insert failed"); <BR>&nbsp;&nbsp;delete pNewDb; <BR>&nbsp;&nbsp;return; } </P>
<P>&nbsp;//<BR>&nbsp;AcDbExtents exts;<BR>&nbsp;//<BR>&nbsp;AcDbBlockReference *pBlkRef = new AcDbBlockReference; <BR>&nbsp;pBlkRef-&gt;setBlockTableRecord(blockID);//指向blockId; </P>
<P>&nbsp;//<BR>&nbsp;pBlkRef-&gt;getGeomExtents(exts);<BR>&nbsp; acutPrintf("\nThe maxPoint=%0.4f,%0.4f",exts.maxPoint(),exts.maxPoint());<BR>&nbsp; acutPrintf("\nThe minPoint=%0.4f,%0.4f",exts.minPoint(),exts.minPoint());<BR>&nbsp;//<BR>&nbsp;pBlkRef-&gt;close();</P>
<P>&nbsp;</P>
<P>不过,如果程序这样写</P>
<P>if(pBlkRef-&gt;getGeomExtents(exts)!=Acad::eOk)</P>
<P>{</P>
<P>acutPrintf("\nerror\n"); </P>
<P>}</P>
<P>if中的语句会是“假”,得到error,不知道为什么啊?</P>
页: [1]
查看完整版本: 大虾帮忙看看程序吧