lovelyzhao 发表于 2005-12-1 21:30:00

请教遍历的问题

<P>问题:构造选择集,获取选择集里的特征点并充放在数组中,然后在比较特征点在数组中的位置。以下是代码,但结果总是不正确,虽然调试是通了。</P>
<P>请各位帮忙,谢谢!</P>

<P>void zhao_rank()<BR>{<BR>&nbsp;// TODO: Implement the command<BR>&nbsp;int i,cod_number;<BR>&nbsp;int j;<BR>&nbsp;long ilast;<BR>&nbsp;ads_name ent;<BR>&nbsp;float coordinate;</P>
<P>&nbsp;acedSSLength(ssname,&amp;ilast);</P>
<P>&nbsp;AcDbEntity *pEntity;<BR>&nbsp;AcDbObjectId objId;<BR>&nbsp;//*********以下程序是将选择集中实体坐标储存在二维数组***********//&nbsp;<BR>&nbsp;for(i=1;i&lt;ilast+1;i++)<BR>&nbsp;{<BR>&nbsp;&nbsp;acedSSName(ssname,ilast-i,ent);<BR>&nbsp;&nbsp;acdbGetObjectId(objId,ent);<BR>&nbsp;&nbsp;acdbOpenObject(pEntity,objId,AcDb::kForRead);//打开点实体<BR>&nbsp;&nbsp;<BR>&nbsp;&nbsp;if(pEntity-&gt;isKindOf(AcDbCircle::desc()))<BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;// 显示圆的圆心<BR>&nbsp;&nbsp;&nbsp;AcDbCircle *pCircle = AcDbCircle::cast(pEntity); <BR>&nbsp;&nbsp;&nbsp;AcGePoint3d ptCenter; <BR>&nbsp;&nbsp;&nbsp;ptCenter = pCircle-&gt;center(); <BR>&nbsp;<BR>&nbsp;&nbsp;&nbsp;coordinate=ptCenter;<BR>&nbsp;&nbsp;&nbsp;coordinate=ptCenter;<BR>&nbsp;&nbsp;&nbsp;coordinate=ptCenter;<BR>&nbsp;&nbsp;}<BR>&nbsp;&nbsp;if(pEntity-&gt;isKindOf(AcDbPoint::desc()))<BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;// 显示点的坐标<BR>&nbsp;&nbsp;&nbsp;AcDbPoint *pPoint = AcDbPoint::cast(pEntity); <BR>&nbsp;&nbsp;&nbsp;AcGePoint3d ptPoint; <BR>&nbsp;&nbsp;&nbsp;ptPoint = pPoint-&gt;position(); <BR>&nbsp;<BR>&nbsp;&nbsp;&nbsp;coordinate=ptPoint;<BR>&nbsp;&nbsp;&nbsp;coordinate=ptPoint;<BR>&nbsp;&nbsp;&nbsp;coordinate=ptPoint;<BR>&nbsp;&nbsp;}<BR>&nbsp;&nbsp;pEntity-&gt;close(); <BR>&nbsp;}</P>

<P>&nbsp;//*********以下程序是为实体标号***********//&nbsp;<BR>for(i=1;i&lt;ilast+1;i++)<BR>{<BR>&nbsp;cod_number=1;<BR>&nbsp;acedSSName(ssname,ilast-i,ent);<BR>&nbsp;acdbGetObjectId(objId,ent);<BR>&nbsp;acdbOpenObject(pEntity,objId,AcDb::kForRead);//打开点实体<BR>&nbsp;if(pEntity-&gt;isKindOf(AcDbCircle::desc()))<BR>&nbsp;{<BR>&nbsp;&nbsp;AcDbCircle *pCircle = AcDbCircle::cast(pEntity); <BR>&nbsp;&nbsp;AcGePoint3d ptCenter; <BR>&nbsp;&nbsp;ptCenter = pCircle-&gt;center(); <BR>&nbsp;&nbsp;for(j=1;j&lt;ilast+1;j++)<BR>&nbsp;&nbsp;if(ptCenter&lt;coordinate||(ptCenter==coordinate&amp;&amp;ptCenter&lt;coordinate))<BR>&nbsp;&nbsp;&nbsp;cod_number=cod_number+1;<BR>&nbsp;&nbsp;acutPrintf("\n %d",cod_number);<BR>&nbsp;}<BR>&nbsp;if(pEntity-&gt;isKindOf(AcDbPoint::desc()))<BR>&nbsp;{<BR>&nbsp;&nbsp;AcDbPoint *pPoint = AcDbPoint::cast(pEntity); <BR>&nbsp;&nbsp;AcGePoint3d ptPoint; <BR>&nbsp;&nbsp;ptPoint = pPoint-&gt;position(); <BR>&nbsp;&nbsp;for(j=1;j&lt;ilast+1;j++)<BR>&nbsp;&nbsp;&nbsp;if(ptPoint&lt;coordinate||(ptPoint==coordinate&amp;&amp;ptPoint&lt;coordinate))<BR>&nbsp;&nbsp;&nbsp;&nbsp;cod_number=cod_number+1;<BR>&nbsp;&nbsp;&nbsp;acutPrintf("\n %d",cod_number);<BR>&nbsp;}<BR>&nbsp;</P>
<P>}<BR>&nbsp;acedSSFree(ssname);<BR>}</P>

NinthOcean 发表于 2005-12-5 08:52:00

<P>用AcDbObjectIdArray</P>
页: [1]
查看完整版本: 请教遍历的问题