[讨论]我想把模型空间的直线替换成自己的~~代码注释很清楚,望高手走过时顺便指点一
[讨论]我想把模型空间的直线替换成自己的~~代码注释很清楚,望高手走过时顺便指点一下啊<p><font face="Verdana"> //获得当前数据库的快表<br/> AcDbBlockTable *pBlockTbl;<br/> acdbHostApplicationServices()->workingDatabase()->getBlockTable(pBlockTbl,AcDb::kForRead );<br/> //获得模型空间的块表记录<br/> AcDbBlockTableRecord *pBlockTblRcd;<br/> pBlockTbl->getAt (ACDB_MODEL_SPACE,pBlockTblRcd,AcDb::kForWrite);//原本是read格式<br/> pBlockTbl->close();//已经关闭啦<br/> //创建快表记录遍历器<br/> AcDbBlockTableRecordIterator *pltr;<br/> pBlockTblRcd->newIterator (pltr);<br/> AcDbEntity *pEnt;//遍历的临时实体指针。<br/> unsigned int No_Line;//多少条直线<br/> No_Line=0;</font></p><p><font face="Verdana"> //第一次 遍历只为获得直线的数目即 No_Line<br/> for (pltr->start ();!pltr->done();pltr->step())<br/> {<br/> pltr->getEntity (pEnt,AcDb::kForWrite );<br/> AcDbLine *pLine=AcDbLine::cast(pEnt);//淘出直线<br/> if (pLine!=NULL)<br/> {<br/> No_Line=No_Line+1;//遇到直线就加1.<br/> pLine->close();//这里忘关<br/> <br/> }<br/> pEnt->close();<br/> }<br/> }<br/> //及时删除遍历<br/> delete pltr;<br/> <br/> //有点生疏的动态数组<br/> /* AcDbLine **pLines;<br/> pLines=new AcDbLine*;*/<br/> typedef AcDbLine* AcDbLinePointer;</font></p>
<p><font face="Verdana"> AcDbLinePointer *pLines=new AcDbLinePointer;//小梁</font></p><font face="Verdana">
<p><br/> ////将直线的信息 放到新建的动态数组<br/> unsigned int No_Line_Tmp;<br/> No_Line_Tmp=0;<br/> AcDbObjectId pLines_ID;//临时保存实体用的ID</p>
<p> //第二次 遍历为了将直线的信息放入到动态数组<br/> AcDbBlockTableRecordIterator *pltr1;<br/> pBlockTblRcd->newIterator (pltr1);<br/> for (pltr1->start ();!pltr1->done ();pltr1->step())</p>
<p> {<br/> pltr1->getEntity(pEnt,AcDb::kForWrite );//这里是写的模式<br/> AcDbLine *pLine=AcDbLine::cast(pEnt);//淘出直线<br/> if (pLine!=NULL)<br/> {<br/> //新建一条直线<br/> pLines->startPoint() =pLine->startPoint ();<br/> pLines->endPoint() =pLine->endPoint ();<br/> //删除老线,换成新线。<br/> pLine->erase ();<br/> //及时关闭pLine<br/> pLine->close();<br/> //pBlockTblRcd->appendAcDbEntity(pLines_ID,pLines); //遍历时不要添加 否则死循环。<br/> No_Line_Tmp=No_Line_Tmp+1;//序号加一。<br/> /* pLines->close ();<br/> */<br/> <br/> }<br/> pEnt->close();</p>
<p> }</p>
<p><br/> </p>
<p> delete pltr1;//删除遍历器<br/> pBlockTblRcd->close();<br/> delete[] pLines;//删除动态数组。</font></p> <p>这里有问题:</p>
<p>pLines->startPoint() =pLine->startPoint ();<br/> pLines->endPoint() =pLine->endPoint ();<br/>另外不明白你这样做,有什么意义</p> <p><font face="Verdana"> //第一次 遍历只为获得直线的数目即 No_Line<br/> for (pltr->start ();!pltr->done();pltr->step())<br/> {<br/> pltr->getEntity (pEnt,AcDb::kForWrite );<br/> AcDbLine *pLine=AcDbLine::cast(pEnt);//淘出直线<br/> if (pLine!=NULL)<br/> {<br/> No_Line=No_Line+1;//遇到直线就加1.<br/> pLine->close();//这里忘关<br/> <br/> }</font></p>
<p>这里,cast(pent),之前必须确定这个pent就是acdbline,否则会出问题if ( !pent->isKindOf(acdbLine::desc() ) ) {ent->close(); continue;}</p>
<p> </p>
<p>在确定了line的数量后,把它们放进acdbvoidpointerarray,你记得放进去的是acdbline类型的指针就可以了,其余的就简单了~~</p> <p>本来想用这一句设置起点 终点的,发现错了。</p>
<p>还得用new AcDbLine(x,y)这种格式。</p>
<p>谢谢</p> 谢谢您的指点!!
页:
[1]