明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1701|回复: 1

像Photoshop一样选择闭合轻量多段线内的实体

[复制链接]
发表于 2010-2-2 23:39:00 | 显示全部楼层 |阅读模式

这是老南方高人的高作,有点像photoshop里面得选择功能,但不知道为啥不好用了。请高手指教

AutoCAD VBA函数---选择闭合轻量多段线内的实体

Public Sub mSelectByPolyline() '选择闭合轻量多段线内的实体
  Dim sSet As AcadSelectionSet
  Dim intCnt As Integer
  Dim strInfo As String
  Dim objPL As AcadLWPolyline
  Dim objEnt As AcadObject
  Dim pnt As Variant
  Dim objPnt() As Double
  Dim i As Integer
  On Error Resume Next
Redo:
  ThisDrawing.Application.ActiveDocument.Utility.GetEntity objPL, pnt, vbCr & "选择闭合的轻量多段线:"
  If CheckKey(VK_ESCAPE) = True Then
     Exit Sub
  End If
  If objPL Is Nothing Then
     GoTo Redo
  End If
  If TypeName(objPL) <> "IAcadLWPolyline" Then
     GoTo Redo
  End If
  If objPL.Closed = False Then
     GoTo Redo
  End If
Retry:
  strInfo = ThisDrawing.Application.ActiveDocument.Utility.GetString(1, vbCr & vbCr & "是否选择与边线相交的实体(Y/N)?")
  If CheckKey(VK_ESCAPE) = True Then
     Exit Sub
  End If
  If strInfo <> "Y" And strInfo <> "N" And strInfo <> "y" And strInfo <> "n" Then
     GoTo Retry
  End If
  ReDim objPnt((UBound(objPL.Coordinates) + 1) * 3 / 2 - 1)
  For i = 0 To ((UBound(objPL.Coordinates) + 1) / 2 - 1)
      objPnt(3 * i) = objPL.Coordinates(2 * i)
      objPnt(3 * i + 1) = objPL.Coordinates(2 * i + 1)
      objPnt(3 * i + 2) = 0
  Next i
  intCnt = ThisDrawing.SelectionSets.count
  While (intCnt > 0)
      Set sSet = ThisDrawing.SelectionSets.Item(intCnt - 1)
      sSet.Delete
      intCnt = intCnt - 1
  Wend
  Set sSet = ThisDrawing.Application.ActiveDocument.SelectionSets.Add("ENT")
  If strInfo = "Y" Or strInfo = "y" Then
     sSet.SelectByPolygon acSelectionSetCrossingPolygon, objPnt
     DelEntFromSSet objPL, sSet
  Else
    sSet.SelectByPolygon acSelectionSetWindowPolygon, objPnt
  End If
  If sSet.count > 0 Then
    ThisDrawing.Application.ActiveDocument.SendCommand Chr(27) & Chr(27) & "SELECT" & vbCr & axSset2lspEnts(sSet) & vbCr & vbCr
  End If
End Sub

Option Explicit
Public objPicked As AcadObject
Public Const VK_ESCAPE = &H1B
Declare Function GetAsyncKeyState Lib "user32" _
(ByVal vKey As Long) As Integer

Function checkkey(lngKey As Long) As Boolean
If GetAsyncKeyState(lngKey) Then
checkkey = True
Else
checkkey = False
End If
End Function

Public Sub DelEntFromSSet(ByVal ent As AcadEntity, ByVal sSet As AcadSelectionSet)
Dim objCollection(0) As AcadEntity
Set objCollection(0) = ent
sSet.RemoveItems objCollection
End Sub

'#39; ת»»¶à¸öͼԪµÄº¯Êý 从vba界面拷贝过来的,汉字乱码了,不知道为啥。


Public Function axSset2lspEnts(ByVal sSet As AcadSelectionSet) As String
  Dim enthandle As String
  Dim strEnts As String
  Dim i As Integer
  If sSet.Count = 0 Then Exit Function
  enthandle = sSet.Item(0).Handle
  strEnts = "(handent" & Chr(34) & enthandle & Chr(34) & ")"
  If sSet.Count > 1 Then
     For i = 1 To sSet.Count - 1
         enthandle = sSet.Item(i).Handle
         strEnts = strEnts & vbCr & "(handent" & Chr(34) & enthandle & Chr(34) & ")"
     Next i
  End If
  axSset2lspEnts = strEnts
End Function

 楼主| 发表于 2010-2-6 19:25:00 | 显示全部楼层
没人回复?
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

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

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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