明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1612|回复: 3

如何创建选择集,选择闭合的多段线?

[复制链接]
发表于 2008-6-17 14:56:00 | 显示全部楼层 |阅读模式
rt,谢谢!
发表于 2008-6-18 09:59:00 | 显示全部楼层

LZ,代码如下,请试运行,运行过程ClosedLwpSelSet

Option Explicit

'创建选择闭合多段线的选择集
Public Sub ClosedLwpSelSet()
  Dim pClosedLwpSelSet As AcadSelectionSet
  Set pClosedLwpSelSet = CreateSelectionSet
 
  Dim n As Integer
  n = ThisDrawing.ModelSpace.Count - 1
  Dim m As Integer   '记录闭合多段线
  m = 0

  Dim pLwpObj() As AcadLWPolyline
  '得到图形中有多少个闭合的多段线
  Dim I As Integer
  For I = 0 To n
    If TypeOf ThisDrawing.ModelSpace.Item(I) Is AcadLWPolyline Then  '是多段线
      If ThisDrawing.ModelSpace.Item(I).Closed = True Then           '多段线是闭合的
        ReDim Preserve pLwpObj(m) As AcadLWPolyline                  '重新定义数组
        Set pLwpObj(m) = ThisDrawing.ModelSpace.Item(I)
        m = m + 1
      End If
    End If
  Next I

  pClosedLwpSelSet.AddItems pLwpObj               '生成闭合多段线的选择集
 
End Sub

'创建选择集的函数
Public Function CreateSelectionSet(Optional ssName As String = "ss") As AcadSelectionSet

    Dim ss As AcadSelectionSet
    On Error Resume Next
    Set ss = ThisDrawing.SelectionSets(ssName)
    If Err Then Set ss = ThisDrawing.SelectionSets.Add(ssName)
    ss.Clear
    Set CreateSelectionSet = ss

End Function

 楼主| 发表于 2008-6-18 23:52:00 | 显示全部楼层

谢谢你了!

我在版上看到有人说用70组码=1选择封闭多段线,我已经用这种方法选择了!

代码如下:

    Dim sset As AcadSelectionSet
    Dim fType(0 To 1) As Integer
    Dim fData(0 To 1) As Variant
    fType(0) = 0: fData(0) = "*Polyline"
    fType(2) = 70: fData(2) = 1
   
    If Not IsNull(ThisDrawing.SelectionSets.Item("pl")) Then
       Set sset = ThisDrawing.SelectionSets.Item("pl")
       sset.Delete
    End If
    Set sset = ThisDrawing.SelectionSets.Add("pl")
    sset.SelectOnScreen fType, fData

发表于 2008-6-19 08:21:00 | 显示全部楼层
呵呵,那这种方法就是最好的方法啦,学习了!谢谢分享!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-11-26 10:00 , Processed in 0.163772 second(s), 24 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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