• Industries
  • Products
  • Buy
  • Services & Support
  • Communities
  • Discussion Groups

    Visual Basic Customization

    Reply
    jan
    New Member
    Posts: 2
    Registered: ‎10-05-2012
    Accepted Solution

    Getobject method with AutoCAD 2013 ?

    731 Views, 9 Replies
    10-05-2012 01:12 PM

    At some point in my code I used to call AutoCAD 2012 this way:

    AcadApp = GetObject(, "AutoCAD.Application.18")

     

    This procedure does for some reason not work in AutpCAD 2013

    AcadApp = GetObject(, "AutoCAD.Application.19") produces an error

     

    If if dim AcadApp as object I get a <COM Type> object (which I cannot use or convert to AcadApplication)

     

    If I dim AcadApp A AcadApplication i get this exception:

    {"Unable to cast COM object of type 'System.__ComObject' to interface type 'Autodesk.AutoCAD.Interop.AcadApplication'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{2959C1CC-8577-4EDB-ADDC-6EBBAB147926}' failed due to the following error: En sådan grænseflade understøttes ikke (Exception from HRESULT: 0x80004002 (E_NOINTERFACE))."} System.Exception

     

    What changed from 2012 to 2013?

     

    Jan Grenov

    CAD/BIM Manager

    Please use plain text.
    *Expert Elite*
    Posts: 6,474
    Registered: ‎06-29-2007

    Re: Getobject method with AutoCAD 2013 ?

    10-05-2012 10:18 PM in reply to: jan

    Hi,

     

    >> What changed from 2012 to 2013?

    The library you have to use the refrences for 19. As minimum for the corrent type "AcadApplication" you need the "AutoCAD 2013 Type Library". Take care for all references you use that they point to a *19*-file.

     

     

    - alfred -

    -------------------------------------------------------------------------
    Alfred NESWADBA
    Ingenieur Studio HOLLAUS ... www.hollaus.at
    -------------------------------------------------------------------------
    Please use plain text.
    jan
    New Member
    Posts: 2
    Registered: ‎10-05-2012

    Re: Getobject method with AutoCAD 2013 ?

    10-06-2012 09:13 AM in reply to: jan

    Oops .... Forgot about the references to the COM libraries. Stupid me. Thanks

     

    Jan Grenov

    Please use plain text.
    New Member
    kimacket7704
    Posts: 2
    Registered: ‎07-08-2010

    Re: Getobject method with AutoCAD 2013 ?

    03-07-2013 12:15 AM in reply to: alfred.neswadba

    Referencing these AutoCAD dlls, is not an option for me.

    I need to use latebinding, mainly because my program needs to support all versions of AutoCAD from 2002 and up.

     

    Is there any way to use something like the code below, for AutoCAD 2013 64bit

     

     

      Private Function GetAcadObject(byval SelectedVersion as string) As Object
            Dim ReadyTimeout As TimeSpan = TimeSpan.FromSeconds(60)
            Dim ReadyPollInterval As TimeSpan = TimeSpan.FromSeconds(0.25)
            Dim stopwatch__1 = Stopwatch.StartNew()
            Dim acadObj As Object
            While stopwatch__1.Elapsed < ReadyTimeout
                Try
                    acadObj = CreateObject("AutoCAD.Application." + SelectedVersion)
                    If Not acadObj Is Nothing Then
                        Return acadObj
                    End If
                Catch e As System.Runtime.InteropServices.COMException
                    If e.ErrorCode <> DirectCast(&H800401E3, Integer) Then ' MK_E_UNAVAILABLE 
                        If Not e.ErrorCode = DirectCast(&H8001010A, Integer) Then
                            Throw
                        End If
                    End If
                    If e.ErrorCode <> DirectCast(&H8001010A, Integer) Then 'RPC_E_SERVERCALL_RETRYLATER
                        If Not e.ErrorCode = DirectCast(&H800401E3, Integer) Then
                            Throw
                        End If
                    End If
                End Try
                Threading.Thread.Sleep(ReadyPollInterval)
            End While
            Throw New TimeoutException("Unable to acquire the AutoCAD Object")
        End Function

     

     

    Please use plain text.
    *Expert Elite*
    Posts: 6,474
    Registered: ‎06-29-2007

    Re: Getobject method with AutoCAD 2013 ?

    03-07-2013 12:24 AM in reply to: kimacket7704

    Hi,

     

    >> Is there any way to use something like the code below, for AutoCAD 2013 64bit

    If that is just a question then I would say YES. You can use latebindng also in that case.

    Or do you have any problems with your code, then which problem and at what line.

     

    - alfred -

    -------------------------------------------------------------------------
    Alfred NESWADBA
    Ingenieur Studio HOLLAUS ... www.hollaus.at
    -------------------------------------------------------------------------
    Please use plain text.
    Member
    Posts: 3
    Registered: ‎03-14-2013

    Re: Getobject method with AutoCAD 2013 ?

    03-14-2013 01:39 PM in reply to: jan

    I have a similar problem.
    I used "AutoCAD 2013 Type Library" in my vb6 project on a Windows 64-bit, but does not work.

    (works on the autocad 2013 32bit!!)
    error 429 the component can not create object.
    you have any idea?

    I leave you an example that I have constructed to understand the problem:

    Option Explicit
    Dim Acad As AcadApplication
    Dim Dwg As AcadDocument

    Private Sub Form_Load()

        On Error GoTo Errore
        Set Acad = GetObject(, "AutoCAD.Application.19")
        Set Dwg = Acad.ActiveDocument
        On Error GoTo 0
        Exit Sub
        
    Errore:
        MsgBox Err.Number & "  " & Err.Description
    End Sub

     

    thanks

    Please use plain text.
    *Expert Elite*
    Posts: 6,474
    Registered: ‎06-29-2007

    Re: Getobject method with AutoCAD 2013 ?

    03-14-2013 02:15 PM in reply to: Studioobx

    Hi,

     

    have you started AutoCAD before you run your code? If not then: GetObject does not start anything, it looks in the ROT for the first active/responding instance of an ActiveX-server. If GetObject does not find any it stops with the error you showed.

     

    If you want your code to start AutoCAD then you have to use CreateObject!

     

    - alfred -

    -------------------------------------------------------------------------
    Alfred NESWADBA
    Ingenieur Studio HOLLAUS ... www.hollaus.at
    -------------------------------------------------------------------------
    Please use plain text.
    New Member
    kimacket7704
    Posts: 2
    Registered: ‎07-08-2010

    Re: Getobject method with AutoCAD 2013 ?

    03-15-2013 01:45 AM in reply to: jan

    I've managed to get this working, with just using CreateObject("AutoCAD.Application.19").

    My settingfile was supplying AutoCAD.Application.19.0 which of course won't work...

    I believed that I changed this to 19 but it was not the case..

     

    Thanks for the help guys!

    Please use plain text.
    Member
    Posts: 3
    Registered: ‎03-14-2013

    Re: Getobject method with AutoCAD 2013 ?

    03-15-2013 05:45 AM in reply to: jan

    Alfred thanks for your answer,

    Yes i have started AutoCAD before run my code.

    The GetObject should catch the running AutoCAD and then execute commands.

    The same code works fine on Windows 32-bit, it will not work for autocad 2013 on 64bit.

    I do not know the instrument/function ROT.

    can you help me please?

    where can I find it?

     

    (sorry for my bad english!)
    thanks

     

    Please use plain text.
    *Expert Elite*
    Posts: 6,474
    Registered: ‎06-29-2007

    Re: Getobject method with AutoCAD 2013 ?

    03-15-2013 08:45 AM in reply to: Studioobx

    Hi,

     

    have you tried to start any program with VBA, e.g. MS-Excel and do the GetObject from that programm?

    Let's see if that works!

     

    - alfred -

    -------------------------------------------------------------------------
    Alfred NESWADBA
    Ingenieur Studio HOLLAUS ... www.hollaus.at
    -------------------------------------------------------------------------
    Please use plain text.