尝试编了个删除多段线上重复节点的程序,但是最后将新的节点数组NewVert()值赋给多段线的coordinates值,有时可以成功,有时又会报致命错误“Unhandled Access Violation Reading Ox0004 Exception at 6468dfd6h",请教各位大侠这是怎么回事? Public Sub DeleteReVertex() '删除多段线相邻的重复节点 Dim Plsl As AcadSelectionSet Set Plsl = SelectUt.CreateSelectionSet("plsl") Dim pl As AcadLWPolyline Dim VerCoords As Variant Dim IntVertCount As Integer Dim i As Integer Dim j As Integer Dim IntNewVertCount As Integer Dim NewVert() As Double Call SelectUt.SelectByFilter(Plsl, acSelectionSetAll, 0, "lwpolyline", 8, "TRY") For Each pl In Plsl IntNewVertCount = 0 VerCoords = pl.Coordinates IntVertCount = (UBound(VerCoords) + 1) / 2 For i = 0 To IntVertCount - 2 '计算新pl的新节点数 If VerCoords(2 * i) <> VerCoords(2 * i + 2) And VerCoords(2 * i + 1) <> VerCoords(2 * i + 3) Then 'NewVert(j) = VerCoords(2 * i) 'NewVert(j + 1) = VerCoords(2 * i + 1) IntNewVertCount = IntNewVertCount + 1 End If Next i IntNewVertCount = IntNewVertCount + 1 If IntVertCount <> IntNewVertCount Then '如果有重复点 ReDim NewVert(0 To 2 * IntNewVertCount - 1) NewVert(2 * IntNewVertCount - 1) = VerCoords(2 * IntVertCount - 1) NewVert(2 * IntNewVertCount - 2) = VerCoords(2 * IntVertCount - 2) j = 0 For i = 0 To IntVertCount - 2 If VerCoords(2 * i) <> VerCoords(2 * i + 2) And VerCoords(2 * i + 1) <> VerCoords(2 * i + 3) Then NewVert(j) = VerCoords(2 * i) NewVert(j + 1) = VerCoords(2 * i + 1) j = j + 2 End If Next i End If pl.Coordinates = NewVert 就是这最后一步出错 Next End Sub |