新手求助:如何建立两个选择集,求两组曲线的交点?(是不是一定要在同一个选择集中
新手求助:如何建立两个选择集,求两组曲线的交点?(是不是一定要在同一个选择集中才能求出交点?)<p>我是彻彻底底的新手,最近在写一个求两组曲线的交点的代码,可是不管怎样尝试都求不出结果,希望高手能给予指点,谢谢!</p><p>基本思路如下:</p><p>'创建两个选择集</p><p>'===============用于存放肋骨线的选择集=================</p><p> On Error Resume Next</p><p> Dim ssetframe As AcadSelectionSet</p><p> If Not IsNull(ThisDrawing.SelectionSets.Item("frame")) Then</p><p> Set ssetframe = ThisDrawing.SelectionSets.Item("frame")<br/> ssetframe.Delete<br/> <br/> End If<br/> <br/> Set ssetframe = ThisDrawing.SelectionSets.Add("frame")<br/> <br/>''===============用于存放纵横构件的选择集=================<br/> On Error Resume Next<br/> <br/> Dim ssetCom As AcadSelectionSet</p><p> If Not IsNull(ThisDrawing.SelectionSets.Item("com")) Then</p><p> Set ssetCom = ThisDrawing.SelectionSets.Item("com")<br/> ssetCom.Delete<br/> <br/> End If<br/> <br/> Set ssetCom = ThisDrawing.SelectionSets.Add("com")<br/> <br/> <br/> <br/>'2. 选择各条肋骨型线,目的是将各根肋骨保存到对象数组ObjFrame中</p><p> Do While (1) <br/> <br/> Dim kwordList As String<br/> kwordList = "Y N "<br/> ThisDrawing.Utility.InitializeUserInput 1, kwordList <br/> Dim keyword As String <br/> <br/> keyword = ThisDrawing.Utility.GetKeyword("是否选择肋骨[否(N)/是(Y)]:")</p><p> <br/> If keyword = "" Or keyword = "Y" Then '当用户按下Y或者空格或者Enter键<br/> <br/> Dim Ent As AcadObject<br/> ssetframe.SelectOnScreen '在图形界面中依次选择肋骨线并加入到选择集中<br/> For Each Ent In ssetframe<br/> Ent.Highlight True '高亮显示已经选中的肋骨线<br/> Next<br/> <br/> ElseIf keyword = "N" Then '当用户按下N键<br/> <br/> Dim objframe As AcadEntity<br/> <br/> intnumofframe = ssetframe.Count '计算出选择对象的个数<br/> </p><p> For intJ = 1 To intnumofframe<br/> Set objframe(intJ) = ssetframe.Item(intJ - 1) '将选择集中的对象依次写入肋骨对象数组<br/> Next intJ<br/> Exit Do '退出循环,结束肋骨线的选择<br/> End If<br/> Loop<br/> <br/> '-------------------------------------------------------------------------------------------------------------------------------------------------------------------</p><p>'3. 选取各个纵横构件<br/>'选择纵横构件的目的是将各个构件保存到对象数组ObjCom中,方法与选择肋骨线相似,不同的是选择时不必按顺序选取,而且可将甲板边线、舷艢顶线等当作构件来处理</p><p> Do While (1)<br/> <br/> ThisDrawing.Utility.InitializeUserInput 1, kwordList<br/></p><p> keyword = ThisDrawing.Utility.GetKeyword("是否选择纵横构件[否(N)/是(Y)]:")<br/> If keyword = "" Or keyword = "Y" Then '当用户按下Y或者空格或者Enter键 <br/> Dim entry As AcadObject<br/> ssetCom.SelectOnScreen '在图形界面中依次选择构件线并加入到选择集中<br/> For Each entry In ssetCom<br/> entry.Highlight True '高亮显示已经选中的构件<br/> Next<br/> <br/> ElseIf keyword = "N" Then '当用户按下N键<br/> <br/> Dim objCom As AcadEntity<br/> <br/> intnumofcom = ssetCom.Count <br/> For intI = 1 To intnumofcom<br/> Set objCom(intI) = ssetCom.Item(intI - 1) '将选择集中的对象依次写入构件对象数组<br/> Next intI<br/> Exit Do '退出循环,结束构件的选择<br/> End If<br/> Loop<br/><br/>'-------------------------------------------------------------------------------------------------------------------------------------------------------------------</p><p>'4. 构件在SEP图上展开</p><p>'说明:用IntersectWith方法求得各个交点</p><p>Dim fstart As Integer<br/>fstart = ThisDrawing.Utility.GetInteger("纵横构件的起始肋位号:")</p><p>Dim ObjCurve As Curve<br/>Set ObjCurve = newcurve '创建一个曲线实例</p><p>For intI = 1 To intnumofcom '处理每个构件<br/>For intJ = 1 To intnumofframe</p><p>Dim var As Variant</p><p>var = objCom(intI).IntersectWith(objframe(intJ), acExtendNone) '求每个纵横构件和各条肋骨型线的交点</p><p> If UBound(var) < 0 Then<br/> MsgBox "无交点"<br/> Else<br/> MsgBox "有交点"<br/> End If</p><p>'\\\\\\\\\\\\检测肋骨和纵横构件的交点<a>\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\</a></p><p>Dim strr As String </p><p>strr = "Intersection Point[" & k & "] is: " & var((intJ - 1) * 3) & "," & var((intJ - 1) * 3 + 1) & "," & var((intJ - 1) * 3 + 2) <br/>MsgBox strr, , "IntersectWith Example" <br/>strr = "" <br/>k = k + 1 </p><p>由于我是很初级的学习者,所以找不出到的问题出在哪里,请大家帮帮忙,在此谢过了。</p><p> </p><p> </p> 石沉大海般的无助,高手们能不能给个答复呢?急 能写出这样的代码不是新手吧,反正我看不懂,不能帮你 <p>下面代码有问题: </p><p>For intI = 1 To intnumofcom<br/> Set objCom(intI) = ssetCom.Item(intI - 1) '将选择集中的对象依次写入构件对象数组<br/> Next intI<br/> For intJ = 1 To intnumofframe<br/> Set objframe(intJ) = ssetframe.Item(intJ - 1) '将选择集中的对象依次写入肋骨对象数组<br/> Next intJ<br/>可以这样改:</p><p>var = ssetCom.Item(intI - 1).IntersectWith(ssetframe.Item(intJ - 1) , acExtendNone) '求每个纵横构件和各条肋骨型线的交点</p><p>你是学船的,你也是吧,请多指教。</p><p></p><p></p> <p>最好能帖个图,将两组数据进行简化,数据最好是1,2,3,4(这是调程序的经验,位数多,带小数点不好调)帮助你理清思路。</p><p>两个选择集,通过两个数组循环进行比较,IntersectWith求出交点。</p>
页:
[1]