.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Launching AutoCAD from a .NET application

2 REPLIES 2
Reply
Message 1 of 3
alex_b
799 Views, 2 Replies

Launching AutoCAD from a .NET application

Hello,

 

I'm trying to launch AutoCAD 2012 from an out-of-process .NET application, based on Kean Walmsley's code at http://through-the-interface.typepad.com/through_the_interface/2007/12/launching-autoc.html#comment-...

While this works OK for V2004 and V2008, it crashes A2012. The crash is erraticall, but usually occurs when launching a UI-based command (Layer manager, Open dialog, etc.)

It seems somehow to be related to UI-thread blocking. (the app launches AutoCAD, may communicate with it, and stays there waiting for it to exit).

Anybody experienced this?

 

Thanks,

 

alex

2 REPLIES 2
Message 2 of 3
ProfWolfMan
in reply to: alex_b

Hi Alex,

 

I do not know exact solution of your problem.

Meanwhile, you can have a look on the following code, which is used by myself since AutoCAD2008 wihtout any issues.

 

 Dim AcadApp As Object
        Try
            AcadApp = GetACAD()
            If IsNothing(AcadApp) Then
                MsgBox("Cannot get AutoCAD application.Open AutoCAD and try again.", MsgBoxStyle.Information)
                End
            End If

 

Public Function GetACAD() As Object

        Dim regs As Microsoft.Win32.RegistryKey = Nothing
        Dim AcadObj As Object = Nothing

       
        Try
            regs = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("SOFTWARE\Autodesk\AutoCAD\R19.1")
            If regs IsNot Nothing Then AcadObj = GetAcadOpp("19")
            If IsNothing(AcadObj) = False Then Return AcadObj

            regs = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("SOFTWARE\Autodesk\AutoCAD\R18.2")
            If regs IsNot Nothing Then AcadObj = GetAcadOpp("18")
            If IsNothing(AcadObj) = False Then Return AcadObj

            regs = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("SOFTWARE\Autodesk\AutoCAD\R18.1")
            If regs IsNot Nothing Then AcadObj = GetAcadOpp("18")
            If IsNothing(AcadObj) = False Then Return AcadObj

            regs = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("SOFTWARE\Autodesk\AutoCAD\R18.0")
            If regs IsNot Nothing Then AcadObj = GetAcadOpp("18")
            If IsNothing(AcadObj) = False Then Return AcadObj

            regs = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("SOFTWARE\Autodesk\AutoCAD\R17.2")
            If regs IsNot Nothing Then AcadObj = GetAcadOpp("17")
            If IsNothing(AcadObj) = False Then Return AcadObj

            regs = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("SOFTWARE\Autodesk\AutoCAD\R17.1")
            If regs IsNot Nothing Then AcadObj = GetAcadOpp("17")
            If IsNothing(AcadObj) = False Then Return AcadObj

        Catch ex As Exception
            MsgBox("Error Getting AutoCAD Info " & ex.Message)
            Return Nothing
        End Try

        Return Nothing

    End Function

    Private Function GetAcadOpp(ByVal AcadString As String) As Object
        Dim AcadApp As Object = Nothing

        Try
            Select Case (AcadString)
                Case "19"
                    AcadApp = GetObject(, "AutoCAD.Application.19")
                Case "18"
                    AcadApp = GetObject(, "AutoCAD.Application.18")
                Case "17"
                    AcadApp = GetObject(, "AutoCAD.Application.17")
            End Select
            If Not AcadApp Is Nothing Then Return AcadApp
        Catch ex As Exception
            AcadApp = Nothing
        Finally

        End Try

        If IsNothing(AcadApp) Then
            Try
                Select Case (AcadString)
                    Case "19"
                        AcadApp = CreateObject("AutoCAD.Application.19")
                    Case "18"
                        AcadApp = CreateObject("AutoCAD.Application.18")
                    Case "17"
                        AcadApp = CreateObject("AutoCAD.Application.17")
                End Select
                If Not AcadApp Is Nothing Then Return AcadApp
            Catch ex As Exception
                AcadApp = Nothing
            Finally

            End Try
        End If

        Return AcadApp

    End Function

 

Thanks & Regards,
G
Tags (1)
Message 3 of 3
alex_b
in reply to: ProfWolfMan

Hi ProfWolfMan,

 

My code (in C#) is essentially the same as yours.

To explain a bit more: the code launches Autocad and can communicate with and drive it; the problem is if the user tries to use it in the normal manner, then it crashes. It happens only in V2012.

Do you use console application or GUI?

 

Thanks,

 

alex

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

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost