Active Member
Posts: 9
Registered: ‎10-07-2008
Message 1 of 5 (668 Views)

Read Layers in Active Document from external VB.Net App??

668 Views, 4 Replies
07-22-2012 11:04 AM

I have an external drawing processor and one of the functions is to read the layers in an AutoCAd drawing and if the name matches freeze/thaw it. With modifications over the years I have had it working with 2002 through 2008. Now I'm getting errors. When I tru to use the Interop, I get "Call Rejected by Callee" errors, when I use the

ApplicationServices method to get the application and active document, I getI" Method 'GetEnumerator' in type 'Autodesk.AutoCAD.DatabaseServices.LayerTable' from assembly 'Acdbmgd, Version=, Culture=neutral, PublicKeyToken=null' does not have an implementation." errors.


Basically for the interop method I use this code:

Imports Autodesk.AutoCAD.Interop
    Public Function GetAcadApp() As AcadApplication

        Dim progID As String = My.Settings.strAcadProgID
        Dim acApp As AcadApplication = Nothing
            acApp = DirectCast(Marshal.GetActiveObject(progID), AcadApplication)
        Catch ex As Exception
                Dim acType As Type = Type.GetTypeFromProgID(progID)
                acApp = DirectCast(Activator.CreateInstance(acType, True), AcadApplication)
            Catch ex2 As Exception
                MessageBox.Show("Cannot create object of type """ & progID & """")

            End Try
        End Try

        If acApp IsNot Nothing Then

        End If

        Return acApp
    End Function

acApp.Documents.Open("drawing path here", False)

for each layer in acApp.ActiveDocument.Layers
     If layer.Name Like "XYZ" then '''''HERE is where I get stopped by Call Rejected by Callee
               layer.Freeze = False
     end if
Next layer

 As for the other method, I use the sample code provided in the Autodesk wiki modified to be used outside of AutoCAD (I can post it if necessary)...


I just can't figure out why I'm being rejected. Any help would be greatly appreciated!



*Expert Elite*
Posts: 753
Registered: ‎02-13-2008
Message 2 of 5 (635 Views)

Re: Read Layers in Active Document from external VB.Net App??

07-24-2012 04:35 PM in reply to: pkirill

See This TTIF Post

Dave O.                                                                  Sig-Logos32.png
Valued Mentor
Posts: 370
Registered: ‎05-06-2012
Message 3 of 5 (601 Views)

Re: Read Layers in Active Document from external VB.Net App??

07-27-2012 11:35 AM in reply to: pkirill

It may be worth noting that the sample code from Kean's blog doesn't bother to revoke the IMessageFilter, so caveat emptor.

Active Member
Posts: 6
Registered: ‎06-20-2005
Message 4 of 5 (119 Views)

Re: Read Layers in Active Document from external VB.Net App??

08-05-2014 08:16 AM in reply to: pkirill



I can find a boat load of sample code for vb.net that works inside of AutoCAD, however, I’m creating an windows vb.net app that runs outside of AutoCAD and MS Access that I can select blocks inside of AutoCAD and populate tables inside of MS Access. I would greatly appreciate it if you can point me in the right direction where I can find documentation using Autodesk.AutoCAD.Interop and Common.

I’m having problems translating code from acmgd,accoremdg to the interop world.




*Expert Elite*
Posts: 1,045
Registered: ‎04-27-2009
Message 5 of 5 (111 Views)

Re: Read Layers in Active Document from external VB.Net App??

08-05-2014 09:21 AM in reply to: spesci

With stand-alone EXE app, you DO NOT/CANNOT use AutoCAD managed API assemblies (acdbmgd/acmgd/accoremgd.dll). You are purely dependent on AutoCAD COM API. So, do not "translate" .NET API code, use COM API.


Well, unless you do not mind to make things complicated - often unnecessarily - by writing .NET API code that runs inside AutoCAD and expose it as COM so that your external app can communicate with it. Form the simple task as you described (accessing AutoCAD block information in drawing), this is indeed unnecessary to expose your own API for external app, instead of using good old COM APIs.

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Are You Going To Be @ AU 2014? Feel free to drop by our AU topic post and share your plans, plug a class that you're teaching, or simply check out who else from the community might be in attendance. Ohh and don't forgot to stop by the Autodesk Help | Learn | Collaborate booths in the Exhibit Hall and meet our community team if you get a chance!