PDA

View Full Version : Run-time error '-2147319765 (8002802b)'



cll
2008-04-11, 09:28 AM
I have used this code for a long time to insert a logo as an external reference in a drawing titleblock og (if none) manually:



Public Sub InsLogo()
On Error GoTo Err_Control

Dim BlockObj As Object
Dim BlockObj1 As Object
Dim BlockObjName As String
Dim BlockObjName1 As String
Dim L1BlockObjAttributes
Dim colLayOuts As AcadLayouts
Dim objLayoutName As String
Dim objLayOut As AcadLayout
Dim UserName As String
Dim InsRef As AcadExternalReference
Dim PathName As String
Dim InsertPoint(0 To 2) As Double
Dim Scf As Double

PathName = "\\Data\Afdelinger\Teknik\Dokumentation\Mechanical\GEN\DWG\FORMAT\logo.dwg"

For Each BlockObj In ThisDrawing.ModelSpace
On Error Resume Next
BlockObjName = BlockObj.Name
Select Case BlockObjName
Case "PMC"
GoTo Ramme
Case "Pmc"
GoTo Ramme
End Select
Next

GoTo IngenTitel

Ramme:
For Each BlockObj1 In ThisDrawing.ModelSpace
On Error Resume Next
BlockObjName1 = BlockObj1.Name
Select Case BlockObjName1
Case "A4-V"
Scf = BlockObj1.XScaleFactor
InsertPoint(0) = 209 * Scf: InsertPoint(1) = 21.77 * Scf: InsertPoint(2) = 0
Set InsRef = ThisDrawing.ModelSpace.AttachExternalReference(PathName, _
"Logo", InsertPoint, Scf, Scf, Scf, 0, False)
GoTo Slut
Case "A4-H"
Scf = BlockObj1.XScaleFactor
InsertPoint(0) = 120 * Scf: InsertPoint(1) = 27.77 * Scf: InsertPoint(2) = 0
Set InsRef = ThisDrawing.ModelSpace.AttachExternalReference(PathName, _
"Logo", InsertPoint, Scf, Scf, Scf, 0, False)
GoTo Slut
Case "A3"
Scf = BlockObj1.XScaleFactor
InsertPoint(0) = 326 * Scf: InsertPoint(1) = 23.07 * Scf: InsertPoint(2) = 0
Set InsRef = ThisDrawing.ModelSpace.AttachExternalReference(PathName, _
"Logo", InsertPoint, Scf, Scf, Scf, 0, False)
GoTo Slut
Case "A2"
Scf = BlockObj1.XScaleFactor
InsertPoint(0) = 484 * Scf: InsertPoint(1) = 21.27 * Scf: InsertPoint(2) = 0
Set InsRef = ThisDrawing.ModelSpace.AttachExternalReference(PathName, _
"Logo", InsertPoint, Scf, Scf, Scf, 0, False)
GoTo Slut
Case "A1"
Scf = BlockObj1.XScaleFactor
InsertPoint(0) = 751 * Scf: InsertPoint(1) = 21.57 * Scf: InsertPoint(2) = 0
Set InsRef = ThisDrawing.ModelSpace.AttachExternalReference(PathName, _
"Logo", InsertPoint, Scf, Scf, Scf, 0, False)
GoTo Slut
Case "A0"
Scf = BlockObj1.XScaleFactor
InsertPoint(0) = 1089 * Scf: InsertPoint(1) = 26.27 * Scf: InsertPoint(2) = 0
Set InsRef = ThisDrawing.ModelSpace.AttachExternalReference(PathName, _
"Logo", InsertPoint, Scf, Scf, Scf, 0, False)
GoTo Slut

End Select
Next

GoTo IngenRamme

IngenTitel:
MsgBox "Der er ikke en standard titelblok"
GoTo Manuel

IngenRamme:
MsgBox "Der er ikke nogen standard tegningsramme"
GoTo Manuel

Manuel:
Dim Msg, Style, Title, Response, MyString
Msg = "Vil du indsætte Logo manuelt?" ' Define message.
Style = vbYesNo + vbQuestion + vbDefaultButton1 ' Define buttons.
Title = "Indsæt Logo..." ' Define title.
Response = MsgBox(Msg, Style, Title)
If Response = vbYes Then ' User chose Yes.
MyString = "Yes" ' Perform some action.
SendKeys "_xattach" & "{ENTER}"
Else ' User chose No.
MyString = "No" ' Perform some action.
GoTo Slut
End If
Slut:

RunMacro "magellan_2dmotion"

Exit_Here:
Exit Sub
Err_Control:
Select Case Err.Number
'Add your Case selections here
'Case Is = 1000
'Handle error
'Err.Clear
'Resume Exit_Here
Case Else
MsgBox Err.Number & ", " & Err.Description, , "InsLogo"
Err.Clear
Resume Exit_Here
End Select
End Sub


without problems.
Suddenly (two days ago) I get the:

Run-time error '-2147319765 (8002802b)'
Automation error
Element not found.

The highlighted line is:

For Each BlockObj In ThisDrawing.ModelSpace

The code has been running for years on my machine (several versions of AutoCad) and are still running on 5 other similar machines, so I don't think it has to do with the code.

I have uninstalled the latest windows-updates (from two-days ago) and an update for a SpacePilot (also recently), but with no effect to the problem.

I have searched this forum and google, but have not found a solution.

If any of you have had similar problem or a solution or a suggestion I'll be glad to hear about it.

Best Regards

Claus

Use:
AutoCad Mechanical 2008
Windows XP Professionel

Ed Jobe
2008-04-11, 02:03 PM
I don't think that's the line that's actually causing the error. That's just where it stops after the error causes the automation error and the loop stops. Set a breakpoint at the beginning and run the code again. When it breaks, step through the code and see what element is not found.

cll
2008-04-12, 07:04 PM
...that's exactely where it stops, when stepping through the code manually, F8

Best regards
Claus

cll
2008-04-14, 09:09 AM
I have 2 other codes with exactely the same behavior. Halts on similar line on my machine, runs on other similar machines.

The codes runs from the same dvb-file (server), and I have checked the reference files to be exactely the same versions on the other machines as on mine. AutoCad installation has been made from same deployment.

Weird???

Ed Jobe
2008-04-14, 02:52 PM
Before you hit F8, create a breakpoint on that line, F9.

Another clue, do AcadLine objects have a Name prop?

cll
2008-04-14, 03:34 PM
I'm not quite sure what you mean, but I have:
- opened a drawing with a titleblock PMC and a frame A4-H
- loaded the code
- put a breakpoint, F9, on the line: For Each BlockObj In ThisDrawing.ModelSpace
- run the code with F8 or Run and gets the error.

AcadLine objects don't have a Name property.

Best regards
Claus

Ed Jobe
2008-04-14, 04:37 PM
- run the code with F8 or Run and gets the error.

I'm not sure exactly what you are doing, but you should at least get the execution to move one line, to the On Error statement. It may help to turn on the Debug toolbar. View>Toolbars>Debug. As soon as you hit the Run button, execution should break at the breakpoint. Then click the StepInto button and execution should move to the next line. Keep doing that until you get an error. I suspect it will occur on the .Name line.

You've defined BlockObj for late binding as Object. That means you can stuff anything in there. Just because its named "BlockObj" doesn't mean it contains only blocks. If it happend to be a line, a line object doesn't have that property, so a call to a Name method of the AcadLine class will result in an error.

Take a look a this thread (http://forums.augi.com/showthread.php?t=56833) where I recently addressed a similar issue. Your On Error Resume Next statement is masking the true error and landing on the For...Each statement. Put in some good error handling as shown in that thread. That thread also mentions using If...Typeof to iterate ms.

Jeff_M
2008-04-14, 08:39 PM
Just throwing in my $0.02....
In the VBAIDE, under the Tools menu, Options, General tab, Error Trapping section. It sounds like you may have "Break on all errors" selected, try changing it to "Break on Unhandled errors".

HTH,
Jeff

Ed Jobe
2008-04-14, 08:59 PM
Just throwing in my $0.02....
That could be work $0.10. ;)

cll
2008-04-15, 07:39 AM
I think we are leaving the main issue: What could cause this code stop running on MY computer, giving the error described. Maybe its not the most elegant code, but it has been running for years and is still running on five other computers.



I'm not sure exactly what you are doing, but you should at least get the execution to move one line, to the On Error statement. It may help to turn on the Debug toolbar. View>Toolbars>Debug. As soon as you hit the Run button, execution should break at the breakpoint. Then click the StepInto button and execution should move to the next line. Keep doing that until you get an error. I suspect it will occur on the .Name line.


What is the difference between a) running code to a breakpoint continuing with F8, and b) running the code from top manually with F8? As said before I get the error an the For Each BlockObj In ThisDrawing.ModelSpace line - code don't go any further (except to the ErrControl).



You've defined BlockObj for late binding as Object. That means you can stuff anything in there. Just because its named "BlockObj" doesn't mean it contains only blocks. If it happend to be a line, a line object doesn't have that property, so a call to a Name method of the AcadLine class will result in an error.


Right: Thats why the On Error Resume Next statement. The For Each ... Next will (normally) continue until the Case is found (PMC or pmc). Beside that in a test drawing with only two blocks with Names (PMC and A4-H) code stops on For Each BlockObj In ThisDrawing.ModelSpace.
Removing all error handling gives not change.



Just throwing in my $0.02....
In the VBAIDE, under the Tools menu, Options, General tab, Error Trapping section. It sounds like you may have "Break on all errors" selected, try changing it to "Break on Unhandled errors".


No, Break on Unhandled errors is and has been selected.

I'll look into the mentioned thread.

Best regards
Claus

Ed Jobe
2008-04-15, 02:40 PM
I think we are leaving the main issue: What could cause this code stop running on MY computer, giving the error described. Maybe its not the most elegant code, but it has been running for years and is still running on five other computers.
You may have something different in your drawing or on your computer. Code that is "not the most elegant" may be overlooking this.



What is the difference between a) running code to a breakpoint continuing with F8, and b) running the code from top manually with F8? As said before I get the error an the For Each BlockObj In ThisDrawing.ModelSpace line - code don't go any further (except to the ErrControl).The way you have been doing it, you hit the error, Resume Next does what its supposed to. It completely ignores the error, passes over it without letting you know what it is and then stops at the top of the loop because some other logic failed. You have to step into the loop one instruction at a time until you find the true error. Did you follow the steps I gave you? How did it turn out?




Right: Thats why the On Error Resume Next statement. The For Each ... Next will (normally) continue until the Case is found (PMC or pmc). Beside that in a test drawing with only two blocks with Names (PMC and A4-H) code stops on For Each BlockObj In ThisDrawing.ModelSpace.
Removing all error handling gives not change.As I mentioned before, Resume Next is a poor way to handle errors. It should only be used when you are sure that there is only one possible error condition that it will handle. I advised replacing it with a better structure, not removing it entirely. Keep in mind that it stays in effect until you insert another On Error statement. Thus it can mask errors anywhere else in the routine, not just the next line. Its the sledge hammer approach to error handling. Since we, nor anybody else has "your" pc, we may not be able to help you find the error. Other than the things I already mentioned, the code is straight forward. You just have to go through the proper debugging. If you add the code I showed you in the other thread, it will do most of the debugging for you.

cll
2008-04-15, 03:31 PM
Thanks for taking time with my problem.

But I never get into the loop because of the error in For Each BlockObj In ThisDrawing.ModelSpace.
As On Error Resume Next deals with errors after its statement, how can it give problems in this case.

Could it be worth to reinstall AutoCad?

Ed Jobe
2008-04-15, 03:33 PM
I think we are leaving the main issue: What could cause this code stop running on MY computer, giving the error described. Maybe its not the most elegant code, but it has been running for years and is still running on five other computers.The issue is you have an error on YOUR pc and we're not there. So you have to do some debugging. Other than the code issues I've pointed out, I can't just say "Go fix 'A' and you're back in buisness".




What is the difference between a) running code to a breakpoint continuing with F8, and b) running the code from top manually with F8? As said before I get the error an the For Each BlockObj In ThisDrawing.ModelSpace line - code don't go any further (except to the ErrControl).Did you try the steps I gave you? How did it turn out? What you are after is to be able to watch each line execute and examine the status of variables for clues as to where the problem lies. What you are doing is jumping into the code, it runs past the Resume Next statement and hits the error. Now Resume Next does what its supposed to, which is totally ignore the error and go on to the next line. Somewhere beyond this, your code's logic fails because the previous steps it depended on failed and then stops at the beginning of the loop, unable to continue. You have to find out why. Step into the code at the first line. Execute one line at a time. Open the Locals window. Examine the value of variables, especially BlockObj. Obviously, the program logic is not proceeding as the original programmer assumed.




Right: Thats why the On Error Resume Next statement. The For Each ... Next will (normally) continue until the Case is found (PMC or pmc). Beside that in a test drawing with only two blocks with Names (PMC and A4-H) code stops on For Each BlockObj In ThisDrawing.ModelSpace.
Removing all error handling gives not change. You are assuming it will continue. Remember, Resume Next continues in force until execution encounters another On Error statement that directs error flow otherwise. Thus, all errors will be masked. This is the sledge hammer approach to error handling. This isn't really error "handling" but error "ignoring". I didn't advise removing all error handling, but to replace it with the code I offered you. It can do the debugging for you. Its logic is to provide error handling within a Select..Case structure. Here, you "handle" the errors you can predict and the ones you can't, you display an error message with the error number and description. The dialog title bar even provides you with the procedure where the error occured. Then when you put your code into production and get an error you didn't predict, you just add the error number to the Select..Case structure and "handle" it.

Another way to handle errors is to reduce the possiblity of errors. In the other thread I mentioned, they were working with blocks also. Rather than iterating every single object in ms, I created a selection set of a single block name, greatly reducing the complexity of what I had to search through.

cll
2008-04-17, 03:26 PM
I have made a repair of my AutoCad installation...
And voila, my (good) old code is back on the track and working.

The very in depth explanations from you, Ed, has been very instructive and will be usefull in my further vba works. Thank you so much.

Best regards
Claus

Ed Jobe
2008-04-17, 03:53 PM
That's good to hear, and at the same time disappointing. Now we won't know what the problem really was.

Glad to hear you felt I was helpful. I wasn't sure if it was going to push you away.

lindsayneil401974
2011-04-15, 12:06 AM
Hi, I'm not that computer savvy so I joined to see if I can have the same error fixed. It happens to me in a program called Cashflow Manager. It occurs when I try to set a date range, say 1/4/10 -30/6/10, to print a financial report. As soon as I click on the date panel, the error comes up and I either click OK or 'x' the message and the whole program closes. Have tried reinstalling, which didn't help. Also I don't have Visual Basic or Autocad. Can you help pleeease?
Kind Regards, Lindsay

Ed Jobe
2011-04-15, 04:24 PM
Welcome to augi.

Since I don't have Cashflow Manager, I can't debug it. You'll have to follow the same steps I outlined above. You might also try checking for missing references. To do that, in the vbaide, go to the Tools>References menu and look for "[MISSING]".

lindsayneil401974
2011-04-16, 10:09 AM
Thanks Ed for that. I noticed I was running Visual Build Pro version 6, and after much Googling, I found a tip to download VB Pro 7, which actually got rid of the error! So all's well. Cheers.

john.childs552337
2011-09-22, 11:52 PM
Real easy to spot where I get this exact same error. It's the second line of code after the Sub name. I'm running Excel 2007.

Sub LI to Excel Conversion
Sheets ("Sheet1").select