bsirhell 发表于 2006-8-12 08:30:00

选择集中的点转成数组后出现的问题?

<P>选择集中的点转成数组后出现的问题?源程序如下:</P>
<P>Sub mm()<BR>&nbsp; On Error Resume Next<BR>&nbsp;&nbsp; Dim sset As AcadSelectionSet<BR>&nbsp;&nbsp;&nbsp; Dim objcir As AcadCircle<BR>&nbsp;&nbsp;&nbsp; Dim radius As Double<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; Dim filtertype(0) As Integer<BR>&nbsp;&nbsp;&nbsp; Dim filterdata(0) As Variant<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; If Not IsNull(ThisDrawing.SelectionSets.Item("Circles")) Then<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Set sset = ThisDrawing.SelectionSets.Item("Circles")<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sset.Delete<BR>&nbsp;&nbsp;&nbsp; End If<BR>&nbsp;&nbsp;&nbsp; Set sset = ThisDrawing.SelectionSets.Add("Circles")<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; filtertype(0) = 0 '设置选择过滤器<BR>&nbsp;&nbsp;&nbsp; filterdata(0) = "circle"<BR>&nbsp; <BR>&nbsp;&nbsp;&nbsp; sset.SelectOnScreen filtertype, filterdata<BR>&nbsp;&nbsp;&nbsp;&nbsp; Dim ptarr()<BR>&nbsp;&nbsp;&nbsp; Dim count As Integer<BR>&nbsp;&nbsp;&nbsp; count = sset.count<BR>&nbsp;&nbsp;&nbsp; ReDim ptarr(count - 1)<BR>&nbsp;&nbsp;&nbsp;&nbsp; For Each objcir In sset<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp;&nbsp; Dim ptcen As Variant<BR>&nbsp;&nbsp;&nbsp;&nbsp; ptcen = objcir.Center<BR>&nbsp;&nbsp;&nbsp;&nbsp; Dim i As Integer<BR>&nbsp;&nbsp;&nbsp;&nbsp; For i = 0 To count - 1<BR>&nbsp;&nbsp;&nbsp;&nbsp; Dim cir1 As AcadCircle<BR>&nbsp;&nbsp;&nbsp;&nbsp; Set cir1 = sset.Item(i)<BR>&nbsp;&nbsp;&nbsp;&nbsp; cir1.Center = ptarr(i)<BR>&nbsp;&nbsp;&nbsp;&nbsp; Next i<BR>&nbsp;&nbsp;&nbsp;&nbsp; Next<BR>&nbsp;&nbsp;&nbsp; Dim pt1 As Variant<BR>&nbsp;&nbsp;&nbsp; pt1 = ptarr(0)<BR>&nbsp;&nbsp;&nbsp; MsgBox pt1(0)<BR>&nbsp;&nbsp;&nbsp; MsgBox pt1(1)<BR>&nbsp;&nbsp;&nbsp;&nbsp; <BR>End Sub</P>
<P>运行后无任何反应!</P>

fjfhgdwfn 发表于 2006-8-12 09:24:00

<P>ReDim ptarr(count - 1,2)<BR>dim ii,i as Integer&nbsp;&nbsp;&nbsp;&nbsp;</P>
<P>ii=0</P>
<P>i=0&nbsp;</P>
<P>For Each objcir In sset<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp;&nbsp; Dim ptcen As Variant<BR>&nbsp;&nbsp;&nbsp;&nbsp;' ptcen = objcir.Center</P>
<P>&nbsp; Set ptcen = objcir.Center<BR>&nbsp;&nbsp;&nbsp;&nbsp; For i = 0 To&nbsp;2</P>
<P>ptarr(ii,i)=ptcen(i)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Next i</P>
<P>ii=ii+1<BR>&nbsp;&nbsp;&nbsp;&nbsp; Next<BR>改成这样试试</P>

bsirhell 发表于 2006-8-12 17:37:00

<P>先谢谢!</P>
<P>还是不行</P>
<P>Dim x As Double<BR>&nbsp;Dim y As Double<BR>&nbsp;x = ptarr(0, 0)<BR>&nbsp;y = ptarr(0, 1)<BR>&nbsp;&nbsp;&nbsp; MsgBox x<BR>&nbsp;&nbsp;&nbsp; MsgBox y</P>
<P>任何时候显示为0,0</P>
<P>&nbsp;</P>

雪山飞狐_lzh 发表于 2006-8-12 18:28:00

ReDim ptarr(sset.count - 1)
For i= 0 to sset.count-1   
   ptarr(i)=sset(i).Center
Next
msgbox ptarr(0)(0) & "," & ptarr(0)(1) & "," & ptarr(0)(2)
页: [1]
查看完整版本: 选择集中的点转成数组后出现的问题?