大虾帮忙看看程序吧
<P>整个程序主要是为了从dwg文件中得到图块的包罗矩形的两个点.(不知道有没有其他的方法)</P><P>下面怎么老是得不到 包络矩形的两个点呢?</P>
<P>只会得到**Error on get the extents point...</P>
<P>不知道是那里出问题了?大虾们帮忙看看吧</P>
<P>//插入图形<BR> <BR> Acad::ErrorStatus es;<BR> CString filename="E:\\autocad\\dwgfile\\qq.dwg";//已经存在的文件<BR> AcDbDatabase *pNewDb=new AcDbDatabase(Adesk::kFalse);<BR> es=pNewDb->readDwgFile(filename,_SH_DENYNO,false);<BR> if(es!=Acad::eOk)<BR> {<BR> acutPrintf("\nThe file %s cannot be opend",filename); <BR> return; <BR> }<BR> <BR> AcDbDatabase *pDb;<BR> pDb=acdbHostApplicationServices()->workingDatabase();<BR></P>
<P> CString pBlockName="testblock";<BR> AcDbObjectId blockID;<BR> <BR> if((es=pDb->insert(blockID, pBlockName,pNewDb,true))==Acad::eOk) <BR> { acutPrintf("\ninsert ok\n"); <BR> delete pNewDb;} <BR> else <BR> { AfxMessageBox("Insert failed"); <BR> delete pNewDb; <BR> return; } </P>
<P> <BR> AcGePoint3d pt(100.0,200.0,0.0);<BR> AcDbBlockReference *pBlkRef = new AcDbBlockReference; <BR> pBlkRef->setBlockTableRecord(blockID);//指向blockId; <BR> pBlkRef->setPosition(pt);//设定位置 <BR><BR> AcDbBlockTable *pBlockTable; <BR> pDb->getBlockTable(pBlockTable, AcDb::kForRead); </P>
<P> AcDbBlockTableRecord *pBlockTableRecord; <BR> pBlockTable->getAt(ACDB_MODEL_SPACE, pBlockTableRecord, AcDb::kForWrite); <BR> pBlockTable->close(); <BR> AcDbObjectId newEntId; <BR> pBlockTableRecord->appendAcDbEntity(newEntId, pBlkRef); <BR> pBlockTableRecord->close(); <BR> pBlkRef->close();</P>
<P>///////取得包络矩形的两个顶点<BR><BR> AcDbEntity *pEnt;<BR> acdbOpenAcDbEntity(pEnt,newEntId,AcDb::kForRead);</P>
<P> AcDbExtents exts;<BR> if(pEnt->getGeomExtents(exts)!=Acad::eOk);<BR> {<BR> acutPrintf("\n**Error on get the extents point...");<BR> pEnt->close();<BR> return;<BR> }<BR> acutPrintf("\nThe maxPoint=%0.4f,%0.4f",exts.maxPoint(),exts.maxPoint());<BR> acutPrintf("\nThe minPoint=%0.4f,%0.4f",exts.minPoint(),exts.minPoint());<BR> pEnt->close();</P> 你这种好象要通过事务处理才能实现 <P>哦,可是必须要事务处理吗?</P>
<P>不能把图块读到当前数据库中,再对图块操作吗?</P> <P>好了,问题解决了。这样就得到了。谢谢<A name=35140><FONT color=#990000><B>easypower</B></FONT></A> 的答复</P>
<P> Acad::ErrorStatus es;<BR> CString filename="E:\\autocad\\dwgfile\\qq.dwg";//已经存在的文件<BR> AcDbDatabase *pNewDb=new AcDbDatabase(Adesk::kFalse);<BR> es=pNewDb->readDwgFile(filename,_SH_DENYNO,false);<BR> if(es!=Acad::eOk)<BR> {<BR> acutPrintf("\nThe file %s cannot be opend",filename); <BR> return; <BR> }<BR> <BR> AcDbDatabase *pDb;<BR> pDb=acdbHostApplicationServices()->workingDatabase();<BR></P>
<P> CString pBlockName="testblock";<BR> AcDbObjectId blockID;<BR> <BR> if((es=pDb->insert(blockID, pBlockName,pNewDb,true))==Acad::eOk) <BR> { acutPrintf("\ninsert ok\n"); <BR> delete pNewDb;} <BR> else <BR> { AfxMessageBox("Insert failed"); <BR> delete pNewDb; <BR> return; } </P>
<P> //<BR> AcDbExtents exts;<BR> //<BR> AcDbBlockReference *pBlkRef = new AcDbBlockReference; <BR> pBlkRef->setBlockTableRecord(blockID);//指向blockId; </P>
<P> //<BR> pBlkRef->getGeomExtents(exts);<BR> acutPrintf("\nThe maxPoint=%0.4f,%0.4f",exts.maxPoint(),exts.maxPoint());<BR> acutPrintf("\nThe minPoint=%0.4f,%0.4f",exts.minPoint(),exts.minPoint());<BR> //<BR> pBlkRef->close();</P>
<P> </P>
<P>不过,如果程序这样写</P>
<P>if(pBlkRef->getGeomExtents(exts)!=Acad::eOk)</P>
<P>{</P>
<P>acutPrintf("\nerror\n"); </P>
<P>}</P>
<P>if中的语句会是“假”,得到error,不知道为什么啊?</P>
页:
[1]