linshibin 发表于 2009-5-6 17:34:00

[求助]重赋多段线的coordinates值时,CAD报错退出

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

xuyajun1979 发表于 2009-5-14 19:15:00

<p>将pline重画一下就行了</p><p></p>

linshibin 发表于 2009-5-18 19:36:00

<p>PLine中有扩展数据,重画有点麻烦</p>

linshibin 发表于 2009-5-18 19:37:00

<p>PLine中有扩展数据,重画有点麻烦</p>

雪山飞狐_lzh 发表于 2009-5-18 19:41:00

<p>那就GetXData,然后SetXData</p>

gdzhou 发表于 2009-5-20 17:11:00

我觉得是你的算法问题
页: [1]
查看完整版本: [求助]重赋多段线的coordinates值时,CAD报错退出