选择集的怪问题
<P>欲将选择集中的同心圆半径小的那个去掉,结果却将所有的小圆都去掉了,图形中只剩下半径最大的圆了,以下是源程序,还请高手指教!</P><P> For Each element In SSet<BR> Dim i As Integer<BR> Dim j As Integer<BR> Dim obj1 As AcadCircle<BR> Dim obj2 As AcadCircle<BR> <BR> For i = 0 To SSet.Count - 1<BR> For j = 0 To SSet.Count - 1<BR> Set obj1 = SSet.Item(i)<BR> Set obj2 = SSet.Item(j)<BR> If obj1.Center = obj2.Center Then<BR> If obj1.Radius > obj2.Radius Then<BR> <BR> <BR> <BR> SSet.Item(j).Delete<BR> Update<BR> End If<BR> End If<BR> Next j<BR> Next i</P>
<P>本意是在选择集中删除,用ERASE方法也没用,</P> <P>Set obj1 = SSet.Item(i)<BR> Set obj2 = SSet.Item(j)</P>
<P> 有问题</P> 圆心的位置不是这样比较的吧。三个坐标都需要比较。 <P>For循环也错了,应该这样</P>
<P>For i = SSet.Count - 1 To 0 setp -1</P>
<P> For j = SSet.Count - 1 To 0 setp -1</P> <P>关键是循环的问题。当外层的i循环第一次循环时,j变量就从选择集第一个找起,比较半径,所有半径比item(i)的圆小的同心圆就全删光了。如果第一次外层循环的i变量对应的圆就使半径最大的,只要外层的第一次循环就只剩下半径最大的圆了。</P>
<P>如果你只要删除所有同心圆中半径最小的,那么就是在一个序列中查找最小值的问题,应该首先进行比较,找到最小的后,退出所有循环才能删除。而不是一边比较一边删除,那这个序列就给你破坏了。</P> <P>先谢谢!</P>
<P>能否给出解决问题的代码!</P> For Each element In SSet<BR> Dim i As Integer<BR> Dim j As Integer<BR> Dim obj1 As AcadCircle<BR> Dim obj2 As AcadCircle<BR> <BR>
<P>For i = SSet.Count - 1 To 0 setp -1</P>
<P> For j = SSet.Count - 1 To 0 setp -1 </P>
<P> Set obj1 = SSet.Item(i)<BR> Set obj2 = SSet.Item(j)<BR> dim pt1(0 to 2) as double <BR> dim pt2(0 to 2) as double </P>
<P>pt1=obj1.center</P>
<P>pt2=obj2.center</P>
<P>if pt1(0)=pt2(0):pt1(1)=pt(2)1:pt1(2)=pt2(2) then<BR> SSet.Item(j).Delete<BR> Update<BR> End If<BR> End If<BR> Next j<BR> Next i</P>
<P>问题依旧!</P>
<P>能否再将解答详细点!谢谢!</P> <P>'在下列程序前,首先生成只包括圆的sset选择集</P>
<P>Dim delArray(0) As AcadCircle<BR>Dim delSet As AcadSelectionSet<BR><BR>Set delSet = ThisDrawing.SelectionSets.Add("delset1")<BR><BR> Dim i As Integer<BR> Dim j As Integer<BR> Dim obj1 As AcadCircle<BR> Dim obj2 As AcadCircle</P>
<P> <BR> For i = 0 To sset.Count - 1</P>
<P> Set delArray(0) = sset.Item(i)</P>
<P> For j = 0 To sset.Count - 1<BR> Set obj2 = sset.Item(j)<BR> If delArray(0).Center(0) = obj2.Center(0) And delArray(0).Center(1) = obj2.Center(1) Then<BR> If delArray(0).Radius > obj2.Radius Then</P>
<P> Set delArray(0) = obj2</P>
<P> End If</P>
<P> End If</P>
<P> Next j</P>
<P> delSet.AddItems delArray<BR> Next i</P>
<P><BR>delSet.Erase<BR></P>
<P>使用上述程序,不知达到你的要求吗?</P> 非常感谢!
页:
[1]