guliande 发表于 2010-7-10 16:39:00

[讨论]我想把模型空间的直线替换成自己的~~代码注释很清楚,望高手走过时顺便指点一

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

rongyifei 发表于 2010-7-11 11:54:00

<p>这里有问题:</p>
<p>pLines-&gt;startPoint() =pLine-&gt;startPoint ();<br/>&nbsp;&nbsp;&nbsp;&nbsp;pLines-&gt;endPoint() =pLine-&gt;endPoint ();<br/>另外不明白你这样做,有什么意义</p>

luowy 发表于 2010-7-12 13:53:00

<p><font face="Verdana">&nbsp;&nbsp;//第一次 遍历只为获得直线的数目即 No_Line<br/>&nbsp;&nbsp;for (pltr-&gt;start ();!pltr-&gt;done();pltr-&gt;step())<br/>&nbsp;&nbsp;{<br/>&nbsp;&nbsp;&nbsp;pltr-&gt;getEntity (pEnt,AcDb::kForWrite&nbsp;&nbsp; );<br/>&nbsp;&nbsp;&nbsp;AcDbLine *pLine=AcDbLine::cast(pEnt);//淘出直线<br/>&nbsp;&nbsp;&nbsp;if (pLine!=NULL)<br/>&nbsp;&nbsp;&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;No_Line=No_Line+1;//遇到直线就加1.<br/>&nbsp;&nbsp;&nbsp;&nbsp;pLine-&gt;close();//这里忘关<br/>&nbsp;&nbsp;&nbsp;<br/>&nbsp;&nbsp;&nbsp;}</font></p>
<p>这里,cast(pent),之前必须确定这个pent就是acdbline,否则会出问题if ( !pent-&gt;isKindOf(acdbLine::desc() ) ) {ent-&gt;close(); continue;}</p>
<p>&nbsp;</p>
<p>在确定了line的数量后,把它们放进acdbvoidpointerarray,你记得放进去的是acdbline类型的指针就可以了,其余的就简单了~~</p>

guliande 发表于 2010-7-12 14:40:00

<p>本来想用这一句设置起点 终点的,发现错了。</p>
<p>还得用new AcDbLine(x,y)这种格式。</p>
<p>谢谢</p>

guliande 发表于 2010-7-12 14:40:00

谢谢您的指点!!
页: [1]
查看完整版本: [讨论]我想把模型空间的直线替换成自己的~~代码注释很清楚,望高手走过时顺便指点一