[讨论]我想把模型空间的直线替换成自己的~~代码注释很清楚,望高手走过时顺便指点一下啊[br] //获得当前数据库的快表 AcDbBlockTable *pBlockTbl; acdbHostApplicationServices()->workingDatabase()->getBlockTable(pBlockTbl,AcDb::kForRead ); //获得模型空间的块表记录 AcDbBlockTableRecord *pBlockTblRcd; pBlockTbl->getAt (ACDB_MODEL_SPACE,pBlockTblRcd,AcDb::kForWrite);//原本是read格式 pBlockTbl->close();//已经关闭啦 //创建快表记录遍历器 AcDbBlockTableRecordIterator *pltr; pBlockTblRcd->newIterator (pltr); AcDbEntity *pEnt;//遍历的临时实体指针。 unsigned int No_Line;//多少条直线 No_Line=0;
//第一次 遍历只为获得直线的数目即 No_Line for (pltr->start ();!pltr->done();pltr->step()) { pltr->getEntity (pEnt,AcDb::kForWrite ); AcDbLine *pLine=AcDbLine::cast(pEnt);//淘出直线 if (pLine!=NULL) { No_Line=No_Line+1;//遇到直线就加1. pLine->close();//这里忘关 } pEnt->close(); } } //及时删除遍历 delete pltr; //有点生疏的动态数组 /* AcDbLine **pLines; pLines=new AcDbLine*[No_Line];*/ typedef AcDbLine* AcDbLinePointer;
AcDbLinePointer *pLines=new AcDbLinePointer[No_Line];//小梁
////将直线的信息 放到新建的动态数组 unsigned int No_Line_Tmp; No_Line_Tmp=0; AcDbObjectId pLines_ID;//临时保存实体用的ID
//第二次 遍历为了将直线的信息放入到动态数组 AcDbBlockTableRecordIterator *pltr1; pBlockTblRcd->newIterator (pltr1); for (pltr1->start ();!pltr1->done ();pltr1->step())
{ pltr1->getEntity(pEnt,AcDb::kForWrite );//这里是写的模式 AcDbLine *pLine=AcDbLine::cast(pEnt);//淘出直线 if (pLine!=NULL) { //新建一条直线 pLines[No_Line_Tmp]->startPoint() =pLine->startPoint (); pLines[No_Line_Tmp]->endPoint() =pLine->endPoint (); //删除老线,换成新线。 pLine->erase (); //及时关闭pLine pLine->close(); //pBlockTblRcd->appendAcDbEntity(pLines_ID,pLines[No_Line_Tmp]); //遍历时不要添加 否则死循环。 No_Line_Tmp=No_Line_Tmp+1;//序号加一。 /* pLines[No_Line_Tmp]->close (); */ } pEnt->close();
}
delete pltr1;//删除遍历器 pBlockTblRcd->close(); delete[] pLines;//删除动态数组。 |