GetEntity Fails

Discussion in 'AutoCAD' started by Allen Johnson, Dec 3, 2004.

  1. Seems that the first time this command button gets fired, I get an error at
    the line

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

    Method 'GetEntity' of object 'IAcadUtility' failed

    Any ideas what I'm doing wrong?

    ----------------------------------------------------------------------------
    ----------------
    Private Sub cmdAppend_Click()
    Dim entObj As AcadObject, txtpp As Variant

    Me.Hide
    'On Error Resume Next
    Err.Clear
    ThisDrawing.Utility.GetEntity entObj, txtpp, "Select text to insert:"
    If Err.Number <> 0 Then
    Label1.Caption = "Nothing selected..."
    Me.Show
    Exit Sub
    End If

    If entObj.ObjectName = "AcDbText" Then
    txtNotes.SelText = " " & Trim(entObj.TextString) & " "
    TextString = txtNotes.Text
    If chkDelAppendText.Value = True Then entObj.Delete
    Else
    ThisDrawing.Utility.Prompt "Not a text object..."
    Label1.Caption = "Not a text object..."
    End If

    Me.Show
    End Sub
     
    Allen Johnson, Dec 3, 2004
    #1
  2. Allen Johnson

    VBA Guest

    Private Sub cmdAppend_Click()
    Dim entObj As AcadObject, txtpp As Variant
    Dim TextString As String

    Me.Hide

    On Error Resume Next

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

    If Err.Number <> 0 Then
    Label1.Caption = "Nothing selected..."
    Me.Show
    Exit Sub
    End If

    If entObj.ObjectName = "AcDbText" Then
    txtNotes.SelText = " " & Trim(entObj.TextString) & " "
    TextString = txtNotes.Text
    If chkDelAppendText.Value = True Then entObj.Delete

    Else
    ThisDrawing.Utility.Prompt "Not a text object..."
    Label1.Caption = "Not a text object..."
    End If

    Me.Show
    End Sub
     
    VBA, Dec 3, 2004
    #2
  3. Are you saying to remove the remark comment on the On Error Resume Next?
    Also TextString is a Public variable of the form, so it isn't that it is not
    declared in the routine.
    By not using Option Explicit would fix that anyway, but that is getting off
    topic!

    Neither fixes the problem of why the GetEntity method errors out in the
    first place.
    Why do I get that error to begin with?
     
    Allen Johnson, Dec 3, 2004
    #3
  4. Allen Johnson

    VBA Guest

    Uncomment the On Error ....

    Delete the Err.Clear statement, it's not needed.

    Do that and it works as prescribed.
     
    VBA, Dec 3, 2004
    #4
  5. Not on my machine... That's why I posted.
     
    Allen Johnson, Dec 3, 2004
    #5
  6. Allen Johnson

    VBA Guest

    Then I'd say you have a problem with your install.

    Re-install AutoCAD.
     
    VBA, Dec 6, 2004
    #6
  7. You're funny.

     
    Allen Johnson, Dec 6, 2004
    #7
  8. Allen Johnson

    VBA Guest

    Well, maybe so - but I'll bet ya I'm right!

     
    VBA, Dec 6, 2004
    #8
  9. Allen,

    I have no trouble running your code, stripped down, so something is odd on
    your end. Are you running the VBA directly from a macro, or with a LISP
    wrapper? What version of AutoCAD?

    P.S. I would declare entObj as AcadEntity, not AcadObject. AcadObject
    includes non-graphical objects such as dictionaries.

    --
    R. Robert Bell


    Seems that the first time this command button gets fired, I get an error at
    the line

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

    Method 'GetEntity' of object 'IAcadUtility' failed

    Any ideas what I'm doing wrong?

    ----------------------------------------------------------------------------
    ----------------
    Private Sub cmdAppend_Click()
    Dim entObj As AcadObject, txtpp As Variant

    Me.Hide
    'On Error Resume Next
    Err.Clear
    ThisDrawing.Utility.GetEntity entObj, txtpp, "Select text to insert:"
    If Err.Number <> 0 Then
    Label1.Caption = "Nothing selected..."
    Me.Show
    Exit Sub
    End If

    If entObj.ObjectName = "AcDbText" Then
    txtNotes.SelText = " " & Trim(entObj.TextString) & " "
    TextString = txtNotes.Text
    If chkDelAppendText.Value = True Then entObj.Delete
    Else
    ThisDrawing.Utility.Prompt "Not a text object..."
    Label1.Caption = "Not a text object..."
    End If

    Me.Show
    End Sub
     
    R. Robert Bell, Dec 6, 2004
    #9
  10. Yeah, it seems to generate the error on my machine only (of course!)
    The entire routine is called from within lisp.
    But if I click the button a second time, the routine works.

    Guess I'll try VBA's suggestion of re-installing AutoCAD... then again,
    maybe I'll wait until R2006!
    Probably less of a hassle!
     
    Allen Johnson, Dec 6, 2004
    #10
  11. What happens when you load the form using -VBARun at the command prompt
    (skipping the LISP wrapper)?

    --
    R. Robert Bell


    Yeah, it seems to generate the error on my machine only (of course!)
    The entire routine is called from within lisp.
    But if I click the button a second time, the routine works.

    Guess I'll try VBA's suggestion of re-installing AutoCAD... then again,
    maybe I'll wait until R2006!
    Probably less of a hassle!
     
    R. Robert Bell, Dec 6, 2004
    #11
  12. Then that portion of the code seems to work. But it still errors out when
    calling the .GetDistance method (which is used in another routine on the
    form). TextObj and TextString are public variables.

    Private Sub cmdPickSplitDist_Click()
    Dim PickDistance As Double
    Me.Hide
    TextString = txtNotes.Text
    On Error Resume Next
    Err.Clear
    PickDistance = ThisDrawing.Utility.GetDistance(TextObj.InsertionPoint,
    "Maximum text length:")
    If Err.Number <> 0 Then
    Label1.Caption = "Try again..."
    Me.Show
    Exit Sub
    End If
    txtSplitDist.Text = Format(PickDistance, "0.00")
    Call cmdSplitText_Click
    Me.Show

    End Sub
     
    Allen Johnson, Dec 6, 2004
    #12
  13. Your original posted code does not show the global variable being assigned
    to the picked object. Heavy pre-post editing I assume, but that's all I can
    surmise given the posted code.

    --
    R. Robert Bell


    Then that portion of the code seems to work. But it still errors out when
    calling the .GetDistance method (which is used in another routine on the
    form). TextObj and TextString are public variables.

    Private Sub cmdPickSplitDist_Click()
    Dim PickDistance As Double
    Me.Hide
    TextString = txtNotes.Text
    On Error Resume Next
    Err.Clear
    PickDistance = ThisDrawing.Utility.GetDistance(TextObj.InsertionPoint,
    "Maximum text length:")
    If Err.Number <> 0 Then
    Label1.Caption = "Try again..."
    Me.Show
    Exit Sub
    End If
    txtSplitDist.Text = Format(PickDistance, "0.00")
    Call cmdSplitText_Click
    Me.Show

    End Sub
     
    R. Robert Bell, Dec 7, 2004
    #13
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.