Read Layers in Active Document from external VB.Net App??
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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=18.2.0.0, 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
Try
acApp = DirectCast(Marshal.GetActiveObject(progID), AcadApplication)
Catch ex As Exception
Try
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
GetAcadApp
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
acApp.ActiveDocument.Regen(Common.AcRegenType.acAllViewports)
Next layerAs 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!
Thanks!