AutoCAD 2016 GetAcadDocument throws exception

AutoCAD 2016 GetAcadDocument throws exception

Anonymous
Not applicable
1,365 Views
8 Replies
Message 1 of 9

AutoCAD 2016 GetAcadDocument throws exception

Anonymous
Not applicable

The following code is used without any problems in AutoCAD 2015 but gives now an exception error on the GetAcadDocument function:

 

Public ReadOnly Property ThisDrawing As AcadDocument

 Get

 

  Dim tAcadDoc As ApplicationServices.Document

  Dim tAcadDocCOM As AcadDocument

 

  tAcadDoc = ApplicationServices.Application.DocumentManager.MdiActiveDocument

  tAcadDocCOM = CType(ApplicationServices.DocumentExtension.GetAcadDocument(tAcadDoc), AcadDocument)

  Return tAcadDocCOM

 

 End Get

End Property

 

I'm using the ObjectARX2015 library and .NetFramework v4.5

 

TIA for your help.

 

Regards Leo

0 Likes
1,366 Views
8 Replies
Replies (8)
Message 2 of 9

Virupaksha_aithal
Autodesk Support
Autodesk Support

Hi,

 

Can you please provide more details on this behavior like when it is happening? Also, make sure you verify whether you are getting MdiActiveDocument as null. There is always a chance that you get MdiActiveDocument null (because of non dwg window)



Virupaksha Aithal KM
Developer Technical Services
Autodesk Developer Network

0 Likes
Message 3 of 9

Anonymous
Not applicable

Hi,

 

For example, a drawing is active and I execute the command RH_Bhatch, as defined below. It goes wrong on the bold statement.

 

<CommandMethod("RH_Bhatch")> _

Sub RH_Bhatch()

  ThisDrawing.SendCommand("Hatch" & vbCr)

End Sub

 

Function ThisDrawing() As AcadDocument

  Dim tAcadDoc As ApplicationServices.Document

  Dim tAcadDocCOM As AcadDocument

 

  tAcadDoc = ApplicationServices.Application.DocumentManager.MdiActiveDocument

  

  tAcadDocCOM = CType(ApplicationServices.DocumentExtension.GetAcadDocument(tAcadDoc), AcadDocument)

 

  Return tAcadDocCOM

 

End Function

 

 

0 Likes
Message 4 of 9

Virupaksha_aithal
Autodesk Support
Autodesk Support

Hi,

 

I am unable to reproduce the issue with code provide by you. At my end AutoCAD 2016 is able to start the hatch command.



Virupaksha Aithal KM
Developer Technical Services
Autodesk Developer Network

0 Likes
Message 5 of 9

Anonymous
Not applicable

Hi,

 

I'm using references to the ObjectARX2015. But I see there is a ObjectARX2016. Can this be the problem?

 

Regards Leo

0 Likes
Message 6 of 9

Virupaksha_aithal
Autodesk Support
Autodesk Support

Hi,

 

referring from ObjectARX 2015 should not create any issues. Please make sure you refer your interops from ObjectARX SDK folder (Autodesk.AutoCAD.Interop.Common.dll & Autodesk.AutoCAD.Interop.dll).



Virupaksha Aithal KM
Developer Technical Services
Autodesk Developer Network

0 Likes
Message 7 of 9

Anonymous
Not applicable

Hi,

 

This are the references I'm using:

 

RHDHV01.JPG

 

And this is the error:

 

RHDHV02.JPG

0 Likes
Message 8 of 9

norman.yuan
Mentor
Mentor

Using older version of COP API (AutoCAD COM Interop) with newer version of AutoCAD, in your case, using 2015 COOM interop with AutoCAD 2016, should be OK in most cases.

 

My guess with your issue is because of the AutoCAD interop assembly being embeded in the project. Since VS2012, when a COM reference is added into VS project, VS set the "Embed Interop Type" to "True". This will causes conflict because AutoCAD2016 uses its own Com Interop coming with AutoCAD installation, while your code tries to use the embeded one, which is in different version.

 

So, make sure for the reference to AutoCAD Interop in Visual Studio, "Embed Interop Type" is set to "False" and "Copy Local" is also set to "False".

Norman Yuan

Drive CAD With Code

EESignature

0 Likes
Message 9 of 9

Anonymous
Not applicable

When I do that for the Autodesk.AutoCAD.Interop.Common, I still get the same error.

 

When I do it also for Autodesk.AutoCAD.Interop I get the following error:

 

RHDHV03.JPG

 

 

 

0 Likes