不打开CAD 读取.dwg文件内部的实体元素的信息
<P>在不打开CAD软件的情况下,通过程序读取.dwg文件内部的实体元素的信息,这个想法能否实现,若能实现用什么技术可以实现,希望版主和对这方面了解的同仁给与解答。</P> 有的,ODT技术就是做这个的 朋友,我和你的问题一样,搞出来了没? <p>如下代码可以实现</p><p>void<br/>clone3()<br/>{<br/> AcDbObjectId id;<br/> AcDbObjectIdArray list;<br/> AcDbDatabase extDatabase( Adesk::kFalse );<br/> char dwgName;</p><p> if (RTNORM != getFile( "Enter DWG name", "Select Drawing", "dwg",<br/> dwgName ))<br/> {<br/> return;<br/> }<br/> if (Acad::eOk != extDatabase.readDwgFile( dwgName ))<br/> {<br/> acedAlert( "Error reading DWG!" );<br/> return;<br/> }<br/> extDatabase.<br/> AcDbBlockTable* pBT;<br/> if (Acad::eOk != extDatabase.getSymbolTable( pBT, AcDb::kForRead ))<br/> {<br/> acedAlert( "Error getting BlockTable of DWG" );<br/> return;<br/> }<br/> AcDbBlockTableRecord* pBTR;<br/> Acad::ErrorStatus es = pBT->getAt( ACDB_MODEL_SPACE, pBTR, AcDb::kForRead );<br/> pBT->close();<br/> if (Acad::eOk != es) {<br/> acedAlert( "Error getting model space of DWG" );<br/> return;<br/> }</p><p> AcDbBlockTableRecordIterator* pIT;<br/> if (Acad::eOk != pBTR->newIterator( pIT )) {<br/> acedAlert( "Error iterating model space of DWG" );<br/> pBTR->close();<br/> return;<br/> }</p><p> for ( ; !pIT->done(); pIT->step()) {<br/> if (Acad::eOk == pIT->getEntityId( id )) {<br/> list.append( id );</p><p> // There is a bug in ARX that causes extension dictionaries<br/> // to appear to be soft owners of their contents. This causes<br/> // the contents to be skipped during wblock. To fix this we<br/> // must explicitly tell the extension dictionary to be a hard<br/> // owner of it's entries.<br/> //<br/> AcDbEntity *pEnt;<br/> if ( Acad::eOk == pIT->getEntity(pEnt, AcDb::kForRead)) {<br/> AcDbObjectId obj;<br/> if ((obj = pEnt->extensionDictionary())<br/> != AcDbObjectId::kNull)<br/> {<br/> AcDbDictionary *pDict = NULL;<br/> acdbOpenObject(pDict, obj, AcDb::kForWrite);<br/> if (pDict) {<br/> pDict->setTreatElementsAsHard(Adesk::kTrue);<br/> pDict->close();<br/> }<br/> }<br/> pEnt->close();<br/> }<br/> }<br/> }</p><p> delete pIT;<br/> pBTR->close();</p><p> if (list.isEmpty()) {<br/> acedAlert( "No entities found in model space of DWG" );<br/> return;<br/> }</p><p> AcDbDatabase *pTempDb;</p><p> if (Acad::eOk != extDatabase.wblock( pTempDb, list, AcGePoint3d::kOrigin ))<br/> {<br/> acedAlert( "wblock failed!" );<br/> return;<br/> }<br/> if (Acad::eOk != acdbHostApplicationServices()->workingDatabase()<br/> ->insert( AcGeMatrix3d::kIdentity, pTempDb ))<br/> acedAlert( "insert failed!" );</p><p> delete pTempDb;<br/>}<br/></p>
页:
[1]