VBA
Discuss AutoCAD ActiveX and VBA (Visual Basic for Applications) questions here.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Getobject method with AutoCAD 2013 ?

9 REPLIES 9
SOLVED
Reply
Message 1 of 10
jan
Advocate
8380 Views, 9 Replies

Getobject method with AutoCAD 2013 ?

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

9 REPLIES 9
Message 2 of 10
Alfred.NESWADBA
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 ... blog.hollaus.at ... CDay 2024
------------------------------------------------------------------------------------
(not an Autodesk consultant)
Message 3 of 10
jan
Advocate
in reply to: jan

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

 

Jan Grenov

Message 4 of 10

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

 

 

Message 5 of 10

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 ... blog.hollaus.at ... CDay 2024
------------------------------------------------------------------------------------
(not an Autodesk consultant)
Message 6 of 10
Studioobx
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

Message 7 of 10
Alfred.NESWADBA
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 ... blog.hollaus.at ... CDay 2024
------------------------------------------------------------------------------------
(not an Autodesk consultant)
Message 8 of 10
kimacket7704
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!

Message 9 of 10
Studioobx
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

 

Message 10 of 10
Alfred.NESWADBA
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 ... blog.hollaus.at ... CDay 2024
------------------------------------------------------------------------------------
(not an Autodesk consultant)

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost