Visual Basic Customization

Reply
Contributor
mleslie00
Posts: 12
Registered: ‎08-22-2012
Message 1 of 1 (135 Views)

For Each ent in an AcadBlock fails unpredictably

135 Views, 0 Replies
12-17-2012 11:40 AM

 

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.


Option Explicit

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
                Exit For
            End If
        End If
    Next
   
End Sub

 

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.

 

Thanks,

 

Mike Leslie

 

 

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community