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