Escape out of GetEntity

Discussion in 'AutoCAD' started by Allen Johnson, Jan 28, 2005.

  1. How do you escape out of the .GetEntity method if you don't want to select
    something (say you accidentally clicked the button that fired the command)?

    ThisDrawing.Utility.GetEntity entobj, txtpp, "Select text to insert:"

    After this line executes, the only way out is to select something. Keying
    Escape doesn't seem to break out of it.
     
    Allen Johnson, Jan 28, 2005
    #1
  2. Allen Johnson

    Jeff Mishler Guest

    This means that your code has an error handler that is forcing you to select
    something. Modify that error handler to exit when ESC is pressed, there is
    plenty of code in these groups that address this. One great example can be
    found in the thread started on June 23, 2004 entitled " Add ESC key to ERRor
    Check vba v02"
     
    Jeff Mishler, Jan 29, 2005
    #2
  3. Allen Johnson

    arcticad Guest

    This will let you exit getentity by pressing both esc and the enter key
    It will allow you to keep clicking untill you get a valid selection

    Option Explicit
    Const VK_ESCAPE = &H1B, VK_ENTER = &HD
    Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer


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


    sub main ()
    Dim ent As AcadEntity
    Set ent = GetEntity
    If ent Is Nothing Then
    Exit Sub
    End If
    end sub


    Function GetEntity() As AcadEntity
    Dim ent As AcadEntity
    Dim varBasePnt As Variant

    GetEnt:
    On Error Resume Next
    ThisDrawing.Utility.GetEntity ent, varBasePnt, vbNewLine & "Select Source Block>> "
    On Error GoTo 0

    Do While ent Is Nothing
    If CheckKey(VK_ESCAPE) = True Then
    Exit Function
    Else
    If CheckKey(VK_ENTER) = True Then
    Exit Function
    End If
    GoTo GetEnt
    End If
    Loop
    Set GetEntity = ent
    End Function
     
    arcticad, Jan 31, 2005
    #3
  4. Thanks!
     
    Allen Johnson, Jan 31, 2005
    #4
  5. Allen Johnson

    arcticad Guest

    Your Welcome :)
    If you have any questions Email me.
     
    arcticad, Jan 31, 2005
    #5
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.