找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 919|回复: 0

[求助]:选择首尾相连直线的问题

[复制链接]
发表于 2007-9-10 21:34:18 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

×
本人写了一段选择首尾相连直线的程序,但运行时有时能全部选中,有时不能,跟开始选择哪条直线有关,程序的逻辑我实在找不出什么错误,还请高手调试指点
Sub selline3()
On Error Resume Next
Dim selects As AcadSelectionSet
Dim i As Integer
Dim j As Integer
Dim k As Long
Dim startpoint As Variant
Dim endpoint As Variant
Dim entline As AcadEntity
Dim tolerance As Double
Dim enttoadd(0) As AcadEntity
Dim templine As AcadLine
Dim dir1 As Variant
Dim dir2 As Variant
Dim gpCode(1) As Integer
Dim dataValue(1) As Variant
Dim isdup As Boolean
Dim joinedline() As myline
Dim toaddline As myline
Dim groupCode As Variant, dataCode As Variant
    gpCode(0) = 0
    dataValue(0) = "AcDbLine"
    groupCode = gpCode
    dataCode = dataValue
ThisDrawing.SelectionSets.Item("r").Delete
If Err Then
Err.Clear
Set selects = ThisDrawing.SelectionSets.Add("r")
End If
selects.SelectOnScreen
If selects.Count = 0 Then
selects.Delete
Exit Sub
End If
tolerance = 0.01
For j = 1 To 2
For k = 0 To ThisDrawing.ModelSpace.Count - 1
Set entline = ThisDrawing.ModelSpace(k)
    If (entline.ObjectName = "AcDbLine") Then
     startpoint = entline.startpoint
     endpoint = entline.endpoint
        For i = 0 To selects.Count - 1
            Set templine = selects(i)
                dir1 = templine.startpoint
                dir2 = templine.endpoint
                If (Abs(dir1(0) - startpoint(0)) <= tolerance And Abs(dir1(1) - startpoint(1)) <= tolerance _
                    And Abs(dir1(2) - startpoint(2)) <= tolerance) Or (Abs(dir1(0) - endpoint(0)) <= tolerance _
                    And Abs(dir1(1) - endpoint(1)) <= tolerance _
                    And Abs(dir1(2) - endpoint(2)) <= tolerance) Then
                    Set enttoadd(0) = entline
                    selects.AddItems enttoadd
                    entline.Highlight True
                End If
                If (Abs(dir2(0) - startpoint(0)) <= tolerance And Abs(dir2(1) - startpoint(1)) <= tolerance _
                    And Abs(dir2(2) - startpoint(2)) <= tolerance) Or (Abs(dir2(0) - endpoint(0)) <= tolerance _
                    And Abs(dir2(1) - endpoint(1)) <= tolerance _
                    And Abs(dir2(2) - endpoint(2)) <= tolerance) Then
                    Set enttoadd(0) = entline
                    selects.AddItems enttoadd
                    entline.Highlight True
                End If
        Next
    End If
Next k
Next j
MsgBox selects.Count
selects.Delete
End Sub
在这里先行致谢了!
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|申请友链|Archiver|手机版|小黑屋|辽公网安备|晓东CAD家园 ( 辽ICP备15016793号 )

GMT+8, 2024-11-16 13:19 , Processed in 0.175630 second(s), 32 queries , Gzip On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

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