yg545france 发表于 2010-2-2 23:39:00

像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/>&nbsp; Dim sSet As AcadSelectionSet<br/>&nbsp; Dim intCnt As Integer<br/>&nbsp; Dim strInfo As String<br/>&nbsp; Dim objPL As AcadLWPolyline<br/>&nbsp; Dim objEnt As AcadObject<br/>&nbsp; Dim pnt As Variant<br/>&nbsp; Dim objPnt() As Double<br/>&nbsp; Dim i As Integer<br/>&nbsp; On Error Resume Next<br/>Redo:<br/>&nbsp; ThisDrawing.Application.ActiveDocument.Utility.GetEntity objPL, pnt, vbCr &amp; "选择闭合的轻量多段线:"<br/>&nbsp; If CheckKey(VK_ESCAPE) = True Then<br/>&nbsp;&nbsp;&nbsp;&nbsp; Exit Sub<br/>&nbsp; End If<br/>&nbsp; If objPL Is Nothing Then<br/>&nbsp;&nbsp;&nbsp;&nbsp; GoTo Redo<br/>&nbsp; End If<br/>&nbsp; If TypeName(objPL) &lt;&gt; "IAcadLWPolyline" Then<br/>&nbsp;&nbsp;&nbsp;&nbsp; GoTo Redo<br/>&nbsp; End If<br/>&nbsp; If objPL.Closed = False Then<br/>&nbsp;&nbsp;&nbsp;&nbsp; GoTo Redo<br/>&nbsp; End If<br/>Retry:<br/>&nbsp; strInfo = ThisDrawing.Application.ActiveDocument.Utility.GetString(1, vbCr &amp; vbCr &amp; "是否选择与边线相交的实体(Y/N)?")<br/>&nbsp; If CheckKey(VK_ESCAPE) = True Then<br/>&nbsp;&nbsp;&nbsp;&nbsp; Exit Sub<br/>&nbsp; End If<br/>&nbsp; If strInfo &lt;&gt; "Y" And strInfo &lt;&gt; "N" And strInfo &lt;&gt; "y" And strInfo &lt;&gt; "n" Then<br/>&nbsp;&nbsp;&nbsp;&nbsp; GoTo Retry<br/>&nbsp; End If<br/>&nbsp; ReDim objPnt((UBound(objPL.Coordinates) + 1) * 3 / 2 - 1)<br/>&nbsp; For i = 0 To ((UBound(objPL.Coordinates) + 1) / 2 - 1)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; objPnt(3 * i) = objPL.Coordinates(2 * i)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; objPnt(3 * i + 1) = objPL.Coordinates(2 * i + 1)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; objPnt(3 * i + 2) = 0<br/>&nbsp; Next i<br/>&nbsp; intCnt = ThisDrawing.SelectionSets.count<br/>&nbsp; While (intCnt &gt; 0)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Set sSet = ThisDrawing.SelectionSets.Item(intCnt - 1)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sSet.Delete<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; intCnt = intCnt - 1<br/>&nbsp; Wend<br/>&nbsp; Set sSet = ThisDrawing.Application.ActiveDocument.SelectionSets.Add("ENT")<br/>&nbsp; If strInfo = "Y" Or strInfo = "y" Then<br/>&nbsp;&nbsp;&nbsp;&nbsp; sSet.SelectByPolygon acSelectionSetCrossingPolygon, objPnt<br/>&nbsp;&nbsp;&nbsp;&nbsp; DelEntFromSSet objPL, sSet<br/>&nbsp; Else<br/>&nbsp;&nbsp;&nbsp; sSet.SelectByPolygon acSelectionSetWindowPolygon, objPnt<br/>&nbsp; End If<br/>&nbsp; If sSet.count &gt; 0 Then<br/>&nbsp;&nbsp;&nbsp; ThisDrawing.Application.ActiveDocument.SendCommand Chr(27) &amp; Chr(27) &amp; "SELECT" &amp; vbCr &amp; axSset2lspEnts(sSet) &amp; vbCr &amp; vbCr<br/>&nbsp; End If<br/>End Sub</div><p></p><p>Option Explicit<br/>Public objPicked As AcadObject<br/>Public Const VK_ESCAPE = &amp;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; ×&ordf;&raquo;&raquo;&para;à&cedil;&ouml;&Iacute;&frac14;&Ocirc;&ordf;&micro;&Auml;&ordm;&macr;&Ecirc;&yacute; 从vba界面拷贝过来的,汉字乱码了,不知道为啥。</p><p><br/>Public Function axSset2lspEnts(ByVal sSet As AcadSelectionSet) As String<br/>&nbsp; Dim enthandle As String<br/>&nbsp; Dim strEnts As String<br/>&nbsp; Dim i As Integer<br/>&nbsp; If sSet.Count = 0 Then Exit Function<br/>&nbsp; enthandle = sSet.Item(0).Handle<br/>&nbsp; strEnts = "(handent" &amp; Chr(34) &amp; enthandle &amp; Chr(34) &amp; ")"<br/>&nbsp; If sSet.Count &gt; 1 Then<br/>&nbsp;&nbsp;&nbsp;&nbsp; For i = 1 To sSet.Count - 1<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; enthandle = sSet.Item(i).Handle<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; strEnts = strEnts &amp; vbCr &amp; "(handent" &amp; Chr(34) &amp; enthandle &amp; Chr(34) &amp; ")"<br/>&nbsp;&nbsp;&nbsp;&nbsp; Next i<br/>&nbsp; End If<br/>&nbsp; axSset2lspEnts = strEnts<br/>End Function</p>

yg545france 发表于 2010-2-6 19:25:00

没人回复?
页: [1]
查看完整版本: 像Photoshop一样选择闭合轻量多段线内的实体