Visual Basic Customization

Reply
Contributor jan
Contributor
jan
Posts: 13
Registered: ‎10-05-2012
Message 1 of 10 (2,613 Views)
Accepted Solution

Getobject method with AutoCAD 2013 ?

2613 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

*Expert Elite*
Alfred.NESWADBA
Posts: 8,880
Registered: ‎06-29-2007
Message 2 of 10 (2,599 Views)

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
-------------------------------------------------------------------------
Contributor jan
Contributor
jan
Posts: 13
Registered: ‎10-05-2012
Message 3 of 10 (2,592 Views)

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

New Member
kimacket7704
Posts: 2
Registered: ‎07-08-2010
Message 4 of 10 (2,306 Views)

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

 

 

*Expert Elite*
Alfred.NESWADBA
Posts: 8,880
Registered: ‎06-29-2007
Message 5 of 10 (2,301 Views)

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
-------------------------------------------------------------------------
Member
Studioobx
Posts: 3
Registered: ‎03-14-2013
Message 6 of 10 (2,244 Views)

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

*Expert Elite*
Alfred.NESWADBA
Posts: 8,880
Registered: ‎06-29-2007
Message 7 of 10 (2,241 Views)

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
-------------------------------------------------------------------------
New Member
kimacket7704
Posts: 2
Registered: ‎07-08-2010
Message 8 of 10 (2,227 Views)

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!

Member
Studioobx
Posts: 3
Registered: ‎03-14-2013
Message 9 of 10 (2,223 Views)

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

 

*Expert Elite*
Alfred.NESWADBA
Posts: 8,880
Registered: ‎06-29-2007
Message 10 of 10 (2,213 Views)

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

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community