+ Reply to Thread
Results 1 to 4 of 4
  1. #1
    Junior Member
    Using
    AutoCAD 2012
    Join Date
    Aug 2011
    Posts
    15

    Unhappy ThisDrawing Property with AutoCAD 2013

    Registered forum members do not see this ad.

    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:

    Code:
     
    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:

    Code:
     
    Public ReadOnly Property ThisDrawing() As AcadDocument
            Get
                Return DocumentExtension.GetAcadDocument(Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument)
            End Get
    End Property
    Code:
     
    Public ReadOnly Property ThisDrawing() As AcadDocument
            Get
                Return CType(DocumentExtension.GetAcadDocument(Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument), AcadDocument)
            End Get
    End Property
    Code:
     
    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
    Code:
     
    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



  2. #2
    Senior Member
    Computer Details
    flowerrobot's Computer Details
    Operating System:
    Windowns 7
    Computer:
    Lenovo W520
    Discipline
    Mechanical
    flowerrobot's Discipline Details
    Occupation
    Cad Manger
    Discipline
    Mechanical
    Using
    Mechanical 2013
    Join Date
    Sep 2007
    Location
    Sydney
    Posts
    384

    Default

    I know VBA used AcadDocument

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

    Code:
    Private ThisDrawing As Document = Application.DocumentManager.MdiActiveDocument
    or
    Code:
    Public ReadOnly Property ThisDrawing() As Document
    Get
    Return Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
    End Get
    End Property

  3. #3
    Junior Member
    Using
    AutoCAD 2012
    Join Date
    Aug 2011
    Posts
    15

    Default

    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.

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

  4. #4
    Forum Newbie
    Using
    MEP 2012
    Join Date
    Nov 2011
    Posts
    1

    Default

    Registered forum members do not see this ad.

    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

Similar Threads

  1. ThisDrawing.Plot.BatchPlotProgress??
    By muck in forum AutoLISP, Visual LISP & DCL
    Replies: 2
    Last Post: 5th Mar 2012, 06:31 am
  2. ThisDrawing.Utility.GetEntity, How does this work in CAD VBA?
    By muck in forum AutoLISP, Visual LISP & DCL
    Replies: 2
    Last Post: 2nd Dec 2008, 05:29 pm
  3. ThisDrawing.Plot.PlotToDevice??
    By muck in forum AutoLISP, Visual LISP & DCL
    Replies: 0
    Last Post: 8th May 2008, 12:32 pm
  4. Using ThisDrawing.SendCommand to erase crossing
    By muck in forum AutoLISP, Visual LISP & DCL
    Replies: 6
    Last Post: 11th Apr 2007, 01:01 pm
  5. Visual Basic Question About Thisdrawing
    By skeeley in forum AutoLISP, Visual LISP & DCL
    Replies: 3
    Last Post: 21st Sep 2005, 04:27 pm

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts