- UID
- 179018
- 积分
- 0
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2004-9-28
- 最后登录
- 1970-1-1
|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
char chPathName[MAX_PATH];
::GetModuleFileName(GetModuleHandl ("HzGyk.arx"),chPathName,255);
CString strPathName=chPathName;
int nPos=strPathName.ReverseFind('\\');
CString strPath=strPathName.Left(nPos+1);
CString strFile=strPath+"Template\\"+"gyk3.dwg";
AcDbObjectId id;
AcDbObjectIdArray list;
AcDbDatabase extDatabase( Adesk::kFalse );
Acad::ErrorStatus es=extDatabase.readDwgFile(strFile);
if(es!=Acad::eOk)
{
acutPrintf( "Error reading DWG!" );
return;
}
AcDbBlockTable* pBT;
if (Acad::eOk != extDatabase.getSymbolTable( pBT, AcDb::kForRead ))
{
acutPrintf( "Error getting BlockTable of DWG" );
return;
}
AcDbBlockTableRecord* pBTR;
es = pBT->getAt( ACDB_MODEL_SPACE, pBTR, AcDb::kForRead );
pBT->close();
if (Acad::eOk != es)
{
acutPrintf( "Error getting model space of DWG" );
return;
}
AcDbBlockTableRecordIterator* pIT;
if (Acad::eOk != pBTR->newIterator( pIT ))
{
acutPrintf( "Error iterating model space of DWG" );
pBTR->close();
return;
}
for ( ; !pIT->done(); pIT->step())
{
if (Acad::eOk == pIT->getEntityId( id ))
{
list.append( id );
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()) {
acutPrintf( "No entities found in model space of DWG" );
return;
}
AcDbDatabase *pTempDb;
es= extDatabase.wblock( pTempDb, list, AcGePoint3d::kOrigin );
if(es!=Acad::eOk)
{
acutPrintf( "wblock failed!" );
return;
}
es=acdbHostApplicationServices()->workingDatabase()->insert( AcGeMatrix3d::kIdentity, pTempDb );
if(es!=Acad::eOk)
{
acutPrintf( "insert failed!" );
return;
}
delete pTempDb;
//遍历模型空间,找到所有实体,建立一个内部块,然后再建立一个块引用.
AcDbBlockTableRecord *pgykBTR=new AcDbBlockTableRecord();
pgykBTR->setName("gyk3");
if(pgykBTR==NULL)
{
acutPrintf("Create gyk Block table make error!");
return;
}
es=acdbHostApplicationServices()->workingDatabase()->getSymbolTable(pBT,AcDb::kForWrite);
if(es!=Acad::eOk)
{
acutPrintf("Can't open symbol table!");
return;
}
AcDbObjectId blockId;
es=pBT->add(blockId,pgykBTR);
if(es!=Acad::eOk)
{
acutPrintf("Can't add block table record into the block table!");
return;
}
es=pBT->getAt(ACDB_MODEL_SPACE,pBTR,AcDb::kForWrite);
if(es!=Acad::eOk)
{
acutPrintf("Can't get symbol table record!");
return;
}
es=pBT->close();
if(es!=Acad::eOk)
{
acutPrintf("Can't close the block table!");
return;
}
es= pBTR->newIterator( pIT );
if(es!=Acad::eOk)
{
acutPrintf( "Error iterating model space of DWG" );
return;
}
/*es=pBTR->close();
if(es!=Acad::eOk)
{
acutPrintf("Can't close the block table record!");
return;
}*/
for(pIT->start(true);!pIT->done();pIT->step())
{
AcDbEntity* pEnt;
es=pIT->getEntity(pEnt,AcDb::kForRead,false);
if(es!=Acad::eOk)
{
acutPrintf("Can't get entity in the model space!");
return;
}
AcDbObjectId entId;
es=pgykBTR->appendAcDbEntity(entId,pEnt);
if(es!=Acad::eOk)
{
acutPrintf("Can't append entity to block table!");
return;
}
es=pEnt->erase();
if(es!=Acad::eOk)
{
acutPrintf("Can't erase the entity in the model space!");
return;
}
}
delete pIT;
pBTR->close();
delete pgykBTR;
AcDbBlockReference *pgykRef=new AcDbBlockReference();
if(pgykRef==NULL)
{
acutPrintf("memory error!");
return;
}
es=pgykRef->setBlockTableRecord(blockId);
if(es!=Acad::eOk)
{
acutPrintf("set block reference's block make error!");
return;
}
es=pgykRef->setPosition(AcGePoint3d(0,0,0));
if(es!=Acad::eOk)
{
acutPrintf("set block reference's position make error!");
return;
}
es=pgykRef->setRotation(0.0);
if(es!=Acad::eOk)
{
acutPrintf("set block reference's rotation make error!");
return;
}
es=pgykRef->setScaleFactors(AcGeScale3d(420,297,1.0));
if(es!=Acad::eOk)
{
acutPrintf("set block reference's scale factors make error!");
return;
}
es=acdbHostApplicationServices()->workingDatabase()->getSymbolTable(pBT,AcDb::kForRead);
if(es!=Acad::eOk)
{
acutPrintf("Can't get block table!");
return;
}
es=pBT->getAt(ACDB_MODEL_SPACE,pBTR,AcDb::kForWrite);
if(es!=Acad::eOk)
{
acutPrintf("Can't get model block table!");
return;
}
es=pBT->close();
if(es!=Acad::eOk)
{
acutPrintf("Can't close block table!");
return;
}
es=pBTR->appendAcDbEntity(blockId,pgykRef);
if(es!=Acad::eOk)
{
acutPrintf("Can't append entity to model space!");
return;
}
pBTR->close();
delete pgykRef;
各位大哥,大姐,帮俺看看吧,我调了一晚上,都没发现那里有错误.小弟在这里先谢了. |
|