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