Jump to content

ThisDrawing Property with AutoCAD 2013


Kraut1976

Recommended Posts

I am currently recompiling code to be compatible with AutoCAD 2013.

The original code was created using the "Magic Macro" to convert VBA code over to VB.NET code using COM Interface.

I have ran into an issue when trying to create a ThisDrawing property for the rest of the code to use.

In AutoCAD 2012 this way worked just fine:

 

 
Public ReadOnly Property ThisDrawing() As AcadDocument
Get
Return Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.AcadDocument
End Get
End Property

 

But in AutoCAD 2013 that way no longer works.

I get an 'Unable to cast COM object of type 'System.__ComObject' to interface type 'Autodesk.AutoCAD.Interop.AcadDocument' exception.

 

I have tried several different ways to accomplish this. Many with examples from the internet, but to no avail.

 

Some failed attempts:

 

 
Public ReadOnly Property ThisDrawing() As AcadDocument
       Get
           Return DocumentExtension.GetAcadDocument(Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument)
       End Get
End Property

 

 
Public ReadOnly Property ThisDrawing() As AcadDocument
       Get
           Return CType(DocumentExtension.GetAcadDocument(Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument), AcadDocument)
       End Get
End Property

 

 
Public ReadOnly Property ThisDrawing() As Object
       Get
           Dim DotNetDoc As Autodesk.AutoCAD.ApplicationServices.Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
           Dim oDoc As Object = DocumentExtension.GetAcadDocument(DotNetDoc)
           Return oDoc
       End Get
End Property

 

 
Public ReadOnly Property ThisDrawing() As AcadDocument
       Get
           Dim tAcadDoc As Autodesk.AutoCAD.ApplicationServices.Document
           Dim tAcadDocCOM As Autodesk.AutoCAD.Interop.AcadDocument
           tAcadDoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
           tAcadDocCOM = CType(Autodesk.AutoCAD.ApplicationServices.DocumentExtension.GetAcadDocument(tAcadDoc), Autodesk.AutoCAD.Interop.AcadDocument)
           Return tAcadDocCOM
       End Get
End Property

 

Has anyone else encountered this problem or already figured out how to accomplish this with AutoCAD 2013?

Thank you,

Kraut1976

Link to comment
Share on other sites

I know VBA used AcadDocument

 

But why do you have to use Acaddocument in dot net. Why not just use Document?

 

Private ThisDrawing As Document = Application.DocumentManager.MdiActiveDocument

or

Public ReadOnly Property ThisDrawing() As Document
Get
Return Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
End Get
End Property

Link to comment
Share on other sites

I have to use AcadDocument because the code was converted from VBA to VB.NET using Autodesk's "magic macro". The converter uses COM interface to facilitate the conversion.

I found what the problem was. It was a rookie mistake. LOL

I failed to change my references to use the new AutoCAD 2013 type libraries.

Once I referenced the correct libraries, and changed all references to AutoCAD.Interop and AutoCAD.Interop.Common over to the new AxDBLib assembly then everything fell into place and now the following code works correctly.

 

 
Public ReadOnly Property ThisDrawing() As AcadDocument
       Get
           Return DocumentExtension.GetAcadDocument(Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument)
       End Get
End Property

Link to comment
Share on other sites

  • 7 months later...

Hi Kraut1976,

 

I have read your post and wonder if you could provide more information on changing the references to AxDBLib. I have not been able to find any documentation on that library

 

Thanks

Colin

Link to comment
Share on other sites

  • 11 months later...

I was struggling wit this too. You have to add references from your autocad program folder (X:\Program files\Autodesk\Autocad 2014\). Find Autodesk.AutoCAD.Interop.dll and Autodesk.AutoCAD.Interop.Common.dll . After that, magically appeared for me, but see if you are missing from ObjectARX2014 or 2013 folder and if so then add the following: AcCoreMgd.dll ; AcDx.dll. Then you can use the following:

Public ReadOnly Property ThisDrawing As AcadDocument
       Get
           Return Application.DocumentManager.MdiActiveDocument.GetAcadDocument()
       End Get
   End Property

Link to comment
Share on other sites

  • 1 month later...

Thanks Codeplayer. All I had to do was swap the references of Autodesk.AutoCAD.Interop.dll and Autodesk.AutoCAD.Interop.Common.dll from the ones in ObjectARX2014 to "X:\Program files\Autodesk\Autocad 2014\".

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...