- UID
- 3217
- 积分
- 0
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2002-3-21
- 最后登录
- 1970-1-1
|
楼主 |
发表于 2002-6-21 09:37:51
|
显示全部楼层
{
ads_printf("len:%d",ObjIdArr.length());
//ads_alert("in");
AcDbBlockTableRecord* blktab;
// char judge[2];
int len;
AcDbEntity* ent;
AcDbEntity* entclone;
AcDbBlockReference* blkref;
AcDbDatabase *pEntityDb;
AcDbBlockTable *pBlockTable;
AcDbBlockTableRecord *pBlockTableRecord;
len=ObjIdArr.length();
ads_printf("len:%d",len);
for(int qj=0; qj<len; qj++)
{
ads_printf("id:%ld",ObjIdArr[qj]);
}
CString name;
name=pszName;
int judge=0;
if(name=="")
return 2;
//acutPrintf("\nlen%d",len);
pEntityDb = acdbCurDwg();//ObjectARX2000的形式
// Get the model space Block Table Record
if(pEntityDb->getBlockTable(pBlockTable, AcDb::kForWrite)!=Acad::eOk)
return 2;
// ads_alert("end getBlockTable");
if(pBlockTable->has(pszName))
{
// ads_alert("has");
if(pBlockTable->getAt(pszName,blktab,AcDb::kForWrite)!=Acad::eOk)
{
pBlockTable->close();
return 2;
}
BlockId=blktab->objectId();
/* AcDbBlockReferenceIdIterator* bIter;
blktab->newBlockReferenceIdIterator(bIter);
for(int n=0; n<len; n++)
{
if(bIter->seek(ObjIdArr[n])==Acad::eOk)
{
blktab->close();
pBlockTable->close();
return 1;
}
}*/
AcDbObjectId idd;
AcDbBlockTableRecordIterator *pBTableRecordItr;
// ads_alert("pBlockTable");
if(pBlockTable->getAt(ACDB_MODEL_SPACE, pBlockTableRecord, AcDb::kForWrite)!=Acad::eOk)
{
blktab->close();
pBlockTable->close();
return 2;
}
// ads_alert(" end pBlockTable");
pBlockTableRecord->newIterator(pBTableRecordItr);
AcDbBlockReference* iddEnt;
// AcArray<AcDbEntity*> entitiesToMove;
for(pBTableRecordItr->start(); !pBTableRecordItr->done();
pBTableRecordItr->step())
{
if(pBTableRecordItr->getEntity((AcDbEntity*&)iddEnt,AcDb::kForRead)!=Acad::eOk)
{
pBlockTable->close();
pBlockTableRecord->close();
blktab->close();
return 2;
}
if(iddEnt->isKindOf(AcDbBlockReference::desc()) == Adesk::kTrue)
{
if(iddEnt->blockTableRecord()==BlockId)
{
idd=iddEnt->objectId();
for(int n=0; n<len; n++)
{
if(idd==ObjIdArr[n])
{
blktab->close();
iddEnt->close();
pBlockTableRecord->close();
pBlockTable->close();
return 1;
}
}
}//endif
}//endif
iddEnt->close();
}
pBlockTableRecord->close();//判断是否自身引用;end*/
AcDbBlockTableRecordIterator *pBlockTableRecordItr;
blktab->newIterator(pBlockTableRecordItr);
AcDbEntity* pEnt;
// AcArray<AcDbEntity*> entitiesToMove;
for(pBlockTableRecordItr->start(); !pBlockTableRecordItr->done();
pBlockTableRecordItr->step())
{
if(pBlockTableRecordItr->getEntity(pEnt,AcDb::kForWrite)!=Acad::eOk)
{
pBlockTable->close();
blktab->close();
return 2;
}
AcTransaction* pTrans=actrTransactionManager->startTransaction();
//actrTransactionManager->enableGraphicsFlush(Adesk::kTrue);
actrTransactionManager->addNewlyCreatedDBRObject(pEnt);
if(pEnt->erase(Adesk::kTrue)!=Acad::eOk)
{
pBlockTable->close();
blktab->close();
pEnt->close();
// acutPrintf("\nerase");
return 2;
}
actrTransactionManager->endTransaction();
pEnt->close();
}//删除原来实体;
delete pBlockTableRecordItr;
/* if(pBlockTableRecord->assumeOwnershipOf(entitiesToMove)!=Acad::eOk)
{
pBlockTableRecord->close();
return false;
}*/
// ads_alert("acdbOpenAcDbEntity");
for(int i=0;i<len;i++)
{
if(acdbOpenAcDbEntity(ent,ObjIdArr,AcDb::kForRead)!=Acad::eOk)
{
pBlockTable->close();
blktab->close();
// acutPrintf("/n1");
return 2;
}
//modified 2002-03-21
//begin
//将2dpolyline实体转换成polyline
if (ent->isKindOf(AcDb2dPolyline::desc()))
{
AcDbPolyline *pPline;
Poly2dToPoly(ent,pPline);
entclone = AcDbEntity::cast( pPline->clone() );
delete pPline;
ent->close();
}
else
{
entclone = AcDbEntity::cast( ent->clone() );
ent->close();
}
// entclone = AcDbEntity::cast( ent->clone() );
// ent->close();
//end
// ads_alert("appendAcDbEntity");
if(blktab->appendAcDbEntity(entclone)!=Acad::eOk)
{
pBlockTable->close();
blktab->close();
entclone->close();
//acutPrintf("/n2");
return 2;
}
// ads_alert("end appendAcDbEntity");
entclone->close();
}//加入新实体;
// ads_alert(" end ");
if(blktab->setOrigin(ptBase)!=Acad::eOk)
{
//acutPrintf("\norigin\n");
blktab->close();
pBlockTable->close();
return 2;
}
/* pBlockTable->close();
pBlockTableRecord->close();
return true;*/
judge=1;
}//end已存在此块;
else
{
// ads_alert("not has");
//ads_alert("不已存在此块");
blktab=new AcDbBlockTableRecord();//创建块表记录;
blktab->setName(pszName);
// ads_alert("open 1");
for(int i=0;i<len;i++)
{//ads_alert("open in");
if(acdbOpenAcDbEntity(ent,ObjIdArr,AcDb::kForRead)!=Acad::eOk)
{
pBlockTable->close();
blktab->close();
// acutPrintf("/n1");
return 2;
}
// ads_alert("end open in");
//modified 2002-03-21
//begin
/* if (ent->isKindOf(AcDb2dPolyline::desc()))
{
ads_alert("2dp");
AcDbPolyline *pPline;
Poly2dToPoly(ent,pPline);
ads_alert("2dp clone");
entclone = AcDbEntity::cast( pPline->clone() );
ads_alert("end 2dp clone");
pPline->close(); //delete
ent->close();
ads_alert("end clone");
}
else
{
entclone = AcDbEntity::cast( ent->clone() );
ent->close();
}*/
// ads_alert("2dp clone");
entclone = AcDbEntity::cast( ent->clone() );
ent->close();
// ads_alert(" end 2dp clone");
//end
//ads_alert("appendAcDbEntity1");
if(blktab->appendAcDbEntity(entclone)!=Acad::eOk)
{
ads_alert("!=Acad::eOk");
pBlockTable->close();
blktab->close();
entclone->close();
//acutPrintf("/n2");
return 2;
}
// ads_alert(" end appendAcDbEntity1");
entclone->close();
}
ads_alert("setOrigin");
if(blktab->setOrigin(ptBase)!=Acad::eOk)
{
return 2;
}
ads_alert(" end setOrigin");
if(pBlockTable->add(BlockId,blktab)!=Acad::eOk)
{
ads_alert("pBlockTable->add(BlockId,blktab)!=Acad::eOk");
blktab->close();
pBlockTable->close();
// acutPrintf("\n nono");
return 2;
}
pBlockTable->close();
ads_alert("pBlockTable ");
}//end else;
//acutPrintf("\nid%d",BlockId);
// pBlockTable->close();
ads_alert("end else;");
if(judge==1)
{
ads_alert("judge");
AcDbBlockTableRecordIterator* pBlkTblRcdItr;
if(pBlockTable->getAt(ACDB_MODEL_SPACE, pBlockTableRecord, AcDb::kForWrite)!=Acad::eOk)
{
blktab->close();
pBlockTable->close();
return 2;
}
pBlockTableRecord->newIterator(pBlkTblRcdItr);
AcDbEntity* pEntItr;
AcDbObjectId id;
for(pBlkTblRcdItr->start(); ! pBlkTblRcdItr->done(); pBlkTblRcdItr->step())
{
pBlkTblRcdItr->getEntityId(id);
AcTransaction* pTrans=actrTransactionManager->startTransaction();
if(pTrans->getObject((AcDbObject*&)pEntItr,id , AcDb::kForWrite)!=Acad::eOk )
{
blktab->close();
pBlockTable->close();
pBlockTableRecord->close();
return 2;
}
pEntItr->erase( Adesk::kTrue);
pEntItr->erase( Adesk::kFalse);
pEntItr->close();
actrTransactionManager->endTransaction();
}
pBlockTable->close();
pBlockTableRecord->close();
/* AcDbBlockReferenceIdIterator* pIterator;
AcDbObjectId id;
AcDbEntity* ident;
//ads_name entname;
blktab->newBlockReferenceIdIterator( pIterator);
blktab->close();
for(pIterator->start(); !pIterator->done(); pIterator->step())
{
//acdbGetAdsName( entname,ids[k]);
//acedRedraw(entname , 1);
pIterator->getBlockReferenceId (id);
AcTransaction* pTrans=actrTransactionManager->startTransaction();
if(pTrans->getObject((AcDbObject*&)ident,id , AcDb::kForWrite)!=Acad::eOk )
// if(acdbOpenAcDbEntity(ent,,AcDb::kForWrite)!=Acad::eOk)
{
//acutPrintf("\nopen");
return false;
}
ads_printf("\nt");
ident->erase( Adesk::kTrue);
ident->erase( Adesk::kFalse);
// ident->draw();
ident->close();
// actrTransactionManager->queueForGraphicsFlush();
// actrTransactionManager->flushGraphics();
actrTransactionManager->endTransaction();
} */
ads_alert("en d judge");
}
blktab->close();
// AcDbBlockReference* blkref;
blkref=new AcDbBlockReference();//创建块引用;
if(blkref->setBlockTableRecord(BlockId)!=Acad::eOk);
blkref->setPosition(ptBase);
//加入引用块;
pEntityDb =acdbCurDwg();//ObjectARX2000的形式
// Get the model space Block Table Record
if(pEntityDb->getBlockTable(pBlockTable, AcDb::kForRead)!=Acad::eOk)
{
blkref->close();
return 2;
}
if(pBlockTable->getAt(ACDB_MODEL_SPACE, pBlockTableRecord, AcDb::kForWrite)!=Acad::eOk)
{
blkref->close();
pBlockTable->close();
return 2;
}
pBlockTable->close();
if(pBlockTableRecord->appendAcDbEntity(BlockRefID,blkref)!=Acad::eOk)
{ pBlockTableRecord->close();
blkref->close();
return 2;
}
pBlockTableRecord->close();
blkref->close();
//删除实体;
ads_alert("删除实体");
for(int h=0;h<len;h++)
{
AcTransaction* pTrans=actrTransactionManager->startTransaction();
if(pTrans->getObject((AcDbObject*&)ent,ObjIdArr[h] , AcDb::kForWrite)!=Acad::eOk )
// if(acdbOpenAcDbEntity(ent,,AcDb::kForWrite)!=Acad::eOk)
{
//acutPrintf("\nopen");
return 2;
}
if(ent->erase(Adesk::kTrue)!=Acad::eOk)
{ ent->close();
// acutPrintf("\nerase");
return 2;
}
actrTransactionManager->endTransaction();
}//end erase;
// BlockRefID=NULL;
return 0;
} |
|