Kraut1976 Posted July 19, 2012 Share Posted July 19, 2012 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 Quote Link to comment Share on other sites More sharing options...
flowerrobot Posted July 25, 2012 Share Posted July 25, 2012 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 Quote Link to comment Share on other sites More sharing options...
Kraut1976 Posted July 26, 2012 Author Share Posted July 26, 2012 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 Quote Link to comment Share on other sites More sharing options...
ColinB Posted March 3, 2013 Share Posted March 3, 2013 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 Quote Link to comment Share on other sites More sharing options...
Codeplayer Posted February 6, 2014 Share Posted February 6, 2014 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 Quote Link to comment Share on other sites More sharing options...
rjellery Posted March 20, 2014 Share Posted March 20, 2014 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\". Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.