jiandan321 发表于 2007-3-5 09:33:00

批量修改等高线的问题

<p>使用acSelectionSetCrossing命令后,框选内会有多余的线条选中,本人只希望选择和参考线相交的等高线进行高程赋值,望高手帮忙解决!</p><p>&nbsp;</p><p>原代码如下:</p><p>&nbsp;</p><p>&nbsp;</p><p>Public Sub AddEelaviont()</p><p>&nbsp;&nbsp; On Error Resume Next<br/>&nbsp;&nbsp; <br/>&nbsp;&nbsp; Dim LineObj As AcadLine '定义等高线方向线<br/>&nbsp;&nbsp; Dim Ss As AcadSelectionSet<br/>&nbsp;&nbsp; Dim StartPoint As Variant<br/>&nbsp;&nbsp; Dim EndPoint As Variant<br/>&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; ' 在没有提示参考点的情况下获取第一个点<br/>&nbsp;&nbsp; StartPoint = ThisDrawing.Utility.GetPoint(, vbCrLf &amp; "输入直线起点: ")<br/>&nbsp;&nbsp;&nbsp; ' 利用上边起点作为参考点获取第二个点<br/>&nbsp;&nbsp; EndPoint = ThisDrawing.Utility.GetPoint(StartPoint, vbCrLf &amp; "输入直线终点: ")<br/>&nbsp;&nbsp; Set LineObj = ThisDrawing.ModelSpace.AddLine(StartPoint, EndPoint) '画出参考线<br/>&nbsp;&nbsp; <br/>&nbsp;&nbsp; Dim RemoveObjects As AcadEntity<br/>&nbsp;&nbsp; Set RemoveObjects = LineObj<br/>&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp; ThisDrawing.SelectionSets("Test").Delete<br/>&nbsp;&nbsp; Set Ss = ThisDrawing.SelectionSets.Add("Test")<br/>&nbsp;&nbsp; Ss.Select acSelectionSetCrossing, StartPoint, EndPoint '如果StartPoint和EndPoint框<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; '内有多余的线就会出现问题了。<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; '要修改的只是和参考线相交线的高程。<br/>&nbsp;&nbsp; If Ss.Count = 0 Then '错误判断<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MsgBox "未选择到对象!", vbCritical<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Ss.Delete<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Exit Sub<br/>&nbsp;&nbsp;&nbsp; End If</p><p>Ss.RemoveItems RemoveObjects<br/>Dim I As Integer<br/>Dim Pl As AcadPolyline<br/>Dim IntPoints As Variant<br/>Dim II As Integer<br/>Dim JJ As Integer '定义相交线数组位置<br/>Dim str As String<br/>Dim No() As Integer '选择实体的顺序数组<br/>Dim Pts() As Double '到线端点的距离数组</p><p><br/>Dim sPt As Variant<br/>sPt = StartPoint '线的起点<br/>JJ = 0<br/>For I = 1 To Ss.Count - 1<br/>&nbsp;&nbsp;&nbsp; Ss.Item(I).Elevation = 0<br/>&nbsp;&nbsp;&nbsp; Ss.Item(I).Update<br/>&nbsp;&nbsp;&nbsp; IntPoints = Ss.Item(I).IntersectWith(LineObj, acExtendNone) '这里有问题了<br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; ReDim Preserve No(JJ)<br/>&nbsp;&nbsp;&nbsp; ReDim Preserve Pts(JJ)<br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; If UBound(IntPoints) &lt;&gt; -1 Then<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Pts(JJ) = GetDist(sPt(0), sPt(1), IntPoints(0), IntPoints(1)) '计算距离<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; No(JJ) = JJ<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; JJ = JJ + 1<br/>&nbsp;&nbsp;&nbsp; Else<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Ss.RemoveItems I<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Ss.Item(I).Update<br/>&nbsp;&nbsp;&nbsp; End If<br/>&nbsp;&nbsp;&nbsp; <br/>Next I</p><p>'按距起点的距离进行排序</p><p>Dim J As Integer<br/>Dim Temp As Double<br/>Dim Itemp As Integer<br/>Dim Exchange As Boolean<br/>Dim Ncount As Integer<br/>Ncount = JJ</p><p>For I = 0 To Ncount - 1 '交换排序-&gt;冒泡排序<br/>&nbsp;&nbsp; Exchange = False<br/>&nbsp;&nbsp; For J = Ncount - 2 To I Step -1<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If Pts(J + 1) &lt; Pts(J) Then<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Temp = Pts(J + 1)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Pts(J + 1) = Pts(J)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Pts(J) = Temp<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Itemp = No(J + 1)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; No(J + 1) = No(J)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; No(J) = Itemp<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Exchange = True<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End If<br/>&nbsp;&nbsp;&nbsp; Next<br/>&nbsp; If Not Exchange Then<br/>&nbsp;&nbsp;&nbsp;&nbsp; J = I + 1<br/>&nbsp; End If<br/>Next</p><p>Dim StartH As Double<br/>Dim StepH As Double<br/>StartH = ThisDrawing.Utility.GetReal("输入起点高程值:")<br/>StepH = ThisDrawing.Utility.GetReal("输入高程增值:")<br/>For II = 0 To Ncount - 1<br/>Ss.Item(II).Elevation = StartH + II * StepH<br/>Next<br/>'Delete LineObj<br/>MsgBox "总共处理了" &amp; Ncount &amp; "条线"<br/>End Sub</p><p>Public Function GetDist(X1, Y1, X2, Y2)<br/>GetDist = Sqr((X1 - X2) ^ 2 + (Y1 - Y2) ^ 2)<br/>End Function<br/></p>

laoliu09 发表于 2007-3-5 22:56:00

<p class="syntax">RetVal = object.IntersectWith(IntersectObject, ExtendOption) </p><p class="element">ExtendOption</p><p class="element-desc">AcExtendOption 常数; 为输入项<br/>该选项指定两个对象中是否没有、单个或两个对象延伸来得到交点。</p><table class="Simple"><tbody><tr valign="top"><td><p class="constant">acExtendNone</p></td><td><p class="constant-desc">两个对象均不延伸。</p></td></tr><tr valign="top"><td><p class="constant">acExtendThisEntity</p></td><td><p class="constant-desc">延伸基本对象。</p></td></tr><tr valign="top"><td><p class="constant">acExtendOtherEntity</p></td><td><p class="constant-desc">延伸作为参数传递的对象。</p></td></tr><tr valign="top"><td><p class="constant">acExtendBoth</p></td><td><p class="constant-desc">延伸两个对象。</p></td></tr></tbody></table><p class="element">RetVal</p><p class="element-desc">Variant[变体] (双精度数组)<br/>点数组为图形中对象与其它对象相交的点数组。 </p><p class="element-desc">用这个判断吧!你是想编切剖面工具吧?</p>

jiandan321 发表于 2007-3-6 09:24:00

<p>首先谢谢天涯海角关注,本人的确是想编写一个切剖面工具,实际上我已经使用你介绍的判断,但选择集的时候,得到交点会有错!本人判断是选择集的时候这句代码Ss.Select acSelectionSetCrossing, StartPoint, EndPoint,有问题,会把多余的线选中!</p>

laoliu09 发表于 2007-3-6 19:57:00

多余的线?选择集里凡是跟你的参考线相交的等高线都可以判断出来的啊!不明白你的意思!还有,想编切剖面工具的,想必是搞水利方面的人了,最有可能是水工的,呵呵!一起努力!

jiandan321 发表于 2007-3-7 08:47:00

呵呵,我是搞地质的,纯矿产。我从网上找到切剖面后续程序,只是自己想按照工作需求进行修改完善,没有想到刚开始就遇到问题。在线请教QQ:24004936

gzbccy 发表于 2010-12-15 15:11:22

呵呵,前来学习
页: [1]
查看完整版本: 批量修改等高线的问题