I was surprised when a function I had written over a year ago quit working for me. It had been written and debugged in VB6 using the type library for AutoCAD 2007. I am now using the type library for 2010 32 bit.
If I try to enumerate the entities in an AcadBlock, using For Each, about half the time it fails with "Automation error Unspecified error" . Some of the time, even today, it succeeds and I cannot find a common reason why it works or does not work any given time.
You can see in the watch window that if it is going to fail, the count will be a positive number, but there will not be items listed at the bottom of the properties. When it succeeds, the Watch window shows Item 1, Item 2, etc in the list.
Below is the simplest code I could make that demonstrates the error.
Attached are shots of the watch window.
Public Sub Main()
Dim AcadApp As AcadApplication
Dim CurrentDrawing As AcadDocument
Dim blk As AcadBlock
Dim ent As AcadEntity
Dim lin As AcadLine
Dim LineDelta As Variant
Set AcadApp = GetObject(, "AutoCAD.Application.18")
Set CurrentDrawing = AcadApp.Documents("7139461.dwg")
Set blk = CurrentDrawing.Blocks(".250 Dia Hole")
For Each ent In blk
If ent.Layer = "Center" And TypeName(ent) = "IAcadLine" Then
LineDelta = ent.Delta
If Round(LineDelta(0), 7) = 0 And Round(LineDelta(1), 7) <> 0 Then
'found good vertical center line
Set lin = ent
I tried to find workarounds using blk.[_NewEnum] and similar but cannot because in the type library it is explicitly marked:
[id(0xfffffffc), propget, restricted, hidden]
HRESULT _NewEnum([out, retval] IUnknown** pVal);
unlike, say the VBA.Collection object.
Any ideas or clues as to when I can predict this will fail would be helpful, or should I report this to Autodesk as a bug? Do they still even care about the Automation interfaces? I also just installed the updates today to see if it affected this, but it did not.
Access a broad range of knowledge to help get the most out of your products and services.