- 积分
- 524
- 明经币
- 个
- 注册时间
- 2005-1-17
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
本帖最后由 作者 于 2005-3-10 13:12:13 编辑
acDocManager->lockDocument( acDocManager->curDocument(), AcAp::kWrite, NULL, NULL,true) ; ////////////////////////////////// AcDbObjectId id; AcDbObjectIdArray list; AcDbDatabase extDatabase( Adesk::kFalse );
if (Acad::eOk != extDatabase.readDwgFile( "C:\\d.dwg")) //打开图库文件 // if (Acad::eOk != extDatabase.readDwgFile( dwgName ))
{ acedAlert( "Error reading DWG!" ); return; } AcDbBlockTable* pBT; if (Acad::eOk != extDatabase.getSymbolTable( pBT, AcDb::kForRead )) { acedAlert( "Error getting BlockTable of DWG" ); return; } AcDbBlockTableRecord* pBTR; Acad::ErrorStatus es = pBT->getAt( _T("bigblock"), pBTR, AcDb::kForRead );
//"bigblock"是要插入的块名 pBT->close(); if (Acad::eOk != es) { acedAlert( "Error getting the specific blockDef of DWG" ); return; }
AcDbBlockReferenceIdIterator *pItr; if (Acad::eOk != pBTR->newBlockReferenceIdIterator(pItr)) { acedAlert( "Error iterating" ); pBTR->close(); return; }
for (pItr->start(); !pItr->done(); pItr->step()) { AcDbObjectId blkRefId; if (Acad::eOk == pItr->getBlockReferenceId(blkRefId)) { list.append(blkRefId); break; } } delete pItr; 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;
// 如果不需要插入块参照,将模型空间中的最后一个对象删除即可 ads_name lastEnt; if (acdbEntLast(lastEnt) != RTNORM) { acedAlert("获得模型空间最后一个实体失败!"); return; } AcDbObjectId entId; es = acdbGetObjectId(entId, lastEnt); AcDbEntity *pEnt; es = acdbOpenAcDbEntity(pEnt, entId, AcDb::kForWrite); pEnt->erase(); pEnt->close(); ////////////////////////// //用窗口的时候
acDocManager->unlockDocument( acDocManager->curDocument());//
程序运行插入块时提示实体为空"No entities found in model space of DWG" ,应该是这里出错了,list.append(blkRefId); break;这两句没有执行,这是什么原因? |
|