乐筑天下

搜索
欢迎各位开发者和用户入驻本平台 尊重版权,从我做起,拒绝盗版,拒绝倒卖 签到、发布资源、邀请好友注册,可以获得银币 请注意保管好自己的密码,避免账户资金被盗
查看: 30|回复: 1

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

[复制链接]

7

主题

19

帖子

3

银币

初来乍到

Rank: 1

铜币
47
发表于 2010-2-2 23:39:00 | 显示全部楼层 |阅读模式
这是老南方高人的高作,有点像photoshop里面得选择功能,但不知道为啥不好用了。请高手指教
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 SubOption 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
回复

使用道具 举报

7

主题

19

帖子

3

银币

初来乍到

Rank: 1

铜币
47
发表于 2010-2-6 19:25:00 | 显示全部楼层
没人回复?
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

QQ|关于我们|小黑屋|乐筑天下 繁体中文

GMT+8, 2025-7-1 18:53 , Processed in 1.031749 second(s), 67 queries .

© 2020-2025 乐筑天下

联系客服 关注微信 帮助中心 下载APP 返回顶部 返回列表