明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1809|回复: 4

新手求助:如何建立两个选择集,求两组曲线的交点?(是不是一定要在同一个选择集中

[复制链接]
发表于 2008-2-29 12:20:00 | 显示全部楼层 |阅读模式
新手求助:如何建立两个选择集,求两组曲线的交点?(是不是一定要在同一个选择集中才能求出交点?)[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                           

由于我是很初级的学习者,所以找不出到的问题出在哪里,请大家帮帮忙,在此谢过了。

                                                                                              

 

 楼主| 发表于 2008-3-3 10:27:00 | 显示全部楼层
石沉大海般的无助,高手们能不能给个答复呢?急
发表于 2008-3-3 15:17:00 | 显示全部楼层
能写出这样的代码不是新手吧,反正我看不懂,不能帮你
发表于 2009-3-5 21:11:00 | 显示全部楼层

下面代码有问题: 

For intI = 1 To intnumofcom
            Set objCom(intI) = ssetCom.Item(intI - 1)      '将选择集中的对象依次写入构件对象数组
            Next intI
  For intJ = 1 To intnumofframe
            Set objframe(intJ) = ssetframe.Item(intJ - 1)  '将选择集中的对象依次写入肋骨对象数组
            Next intJ
可以这样改:

var = ssetCom.Item(intI - 1).IntersectWith(ssetframe.Item(intJ - 1) , acExtendNone) '求每个纵横构件和各条肋骨型线的交点

你是学船的,你也是吧,请多指教。

发表于 2009-3-14 21:49:00 | 显示全部楼层

最好能帖个图,将两组数据进行简化,数据最好是1,2,3,4(这是调程序的经验,位数多,带小数点不好调)帮助你理清思路。

两个选择集,通过两个数组循环进行比较,IntersectWith求出交点。

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-11-26 05:28 , Processed in 0.173066 second(s), 25 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表