像Photoshop一样选择闭合轻量多段线内的实体
<p><strong>这是老南方高人的高作,有点像photoshop里面得选择功能,但不知道为啥不好用了。请高手指教</strong></p><p><strong>AutoCAD VBA函数---选择闭合轻量多段线内的实体</strong></p><div style="PADDING-RIGHT: 0px; MARGIN-TOP: 10px; FONT-SIZE: 9pt; OVERFLOW-X: hidden; WIDTH: 97%; WORD-BREAK: break-all; TEXT-INDENT: 24px; LINE-HEIGHT: normal; HEIGHT: 200px; WORD-WRAP: break-word;">Public Sub mSelectByPolyline() '选择闭合轻量多段线内的实体<br/> Dim sSet As AcadSelectionSet<br/> Dim intCnt As Integer<br/> Dim strInfo As String<br/> Dim objPL As AcadLWPolyline<br/> Dim objEnt As AcadObject<br/> Dim pnt As Variant<br/> Dim objPnt() As Double<br/> Dim i As Integer<br/> On Error Resume Next<br/>Redo:<br/> ThisDrawing.Application.ActiveDocument.Utility.GetEntity objPL, pnt, vbCr & "选择闭合的轻量多段线:"<br/> If CheckKey(VK_ESCAPE) = True Then<br/> Exit Sub<br/> End If<br/> If objPL Is Nothing Then<br/> GoTo Redo<br/> End If<br/> If TypeName(objPL) <> "IAcadLWPolyline" Then<br/> GoTo Redo<br/> End If<br/> If objPL.Closed = False Then<br/> GoTo Redo<br/> End If<br/>Retry:<br/> strInfo = ThisDrawing.Application.ActiveDocument.Utility.GetString(1, vbCr & vbCr & "是否选择与边线相交的实体(Y/N)?")<br/> If CheckKey(VK_ESCAPE) = True Then<br/> Exit Sub<br/> End If<br/> If strInfo <> "Y" And strInfo <> "N" And strInfo <> "y" And strInfo <> "n" Then<br/> GoTo Retry<br/> End If<br/> ReDim objPnt((UBound(objPL.Coordinates) + 1) * 3 / 2 - 1)<br/> For i = 0 To ((UBound(objPL.Coordinates) + 1) / 2 - 1)<br/> objPnt(3 * i) = objPL.Coordinates(2 * i)<br/> objPnt(3 * i + 1) = objPL.Coordinates(2 * i + 1)<br/> objPnt(3 * i + 2) = 0<br/> Next i<br/> intCnt = ThisDrawing.SelectionSets.count<br/> While (intCnt > 0)<br/> Set sSet = ThisDrawing.SelectionSets.Item(intCnt - 1)<br/> sSet.Delete<br/> intCnt = intCnt - 1<br/> Wend<br/> Set sSet = ThisDrawing.Application.ActiveDocument.SelectionSets.Add("ENT")<br/> If strInfo = "Y" Or strInfo = "y" Then<br/> sSet.SelectByPolygon acSelectionSetCrossingPolygon, objPnt<br/> DelEntFromSSet objPL, sSet<br/> Else<br/> sSet.SelectByPolygon acSelectionSetWindowPolygon, objPnt<br/> End If<br/> If sSet.count > 0 Then<br/> ThisDrawing.Application.ActiveDocument.SendCommand Chr(27) & Chr(27) & "SELECT" & vbCr & axSset2lspEnts(sSet) & vbCr & vbCr<br/> End If<br/>End Sub</div><p></p><p>Option Explicit<br/>Public objPicked As AcadObject<br/>Public Const VK_ESCAPE = &H1B<br/>Declare Function GetAsyncKeyState Lib "user32" _<br/>(ByVal vKey As Long) As Integer</p><p>Function checkkey(lngKey As Long) As Boolean<br/>If GetAsyncKeyState(lngKey) Then<br/>checkkey = True<br/>Else<br/>checkkey = False<br/>End If<br/>End Function</p><p></p><p>Public Sub DelEntFromSSet(ByVal ent As AcadEntity, ByVal sSet As AcadSelectionSet)<br/>Dim objCollection(0) As AcadEntity<br/>Set objCollection(0) = ent<br/>sSet.RemoveItems objCollection<br/>End Sub</p><p>'#39; ת»»¶à¸öͼԪµÄº¯Êý 从vba界面拷贝过来的,汉字乱码了,不知道为啥。</p><p><br/>Public Function axSset2lspEnts(ByVal sSet As AcadSelectionSet) As String<br/> Dim enthandle As String<br/> Dim strEnts As String<br/> Dim i As Integer<br/> If sSet.Count = 0 Then Exit Function<br/> enthandle = sSet.Item(0).Handle<br/> strEnts = "(handent" & Chr(34) & enthandle & Chr(34) & ")"<br/> If sSet.Count > 1 Then<br/> For i = 1 To sSet.Count - 1<br/> enthandle = sSet.Item(i).Handle<br/> strEnts = strEnts & vbCr & "(handent" & Chr(34) & enthandle & Chr(34) & ")"<br/> Next i<br/> End If<br/> axSset2lspEnts = strEnts<br/>End Function</p> 没人回复?
页:
[1]