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
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
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?
Uncomment the On Error .... Delete the Err.Clear statement, it's not needed. Do that and it works as prescribed.
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
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!
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!
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
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