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

AutoCAD version handling

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
ProfWolfMan
652 Views, 2 Replies

AutoCAD version handling

 

Hi all,
I have below code to get a autocad instance.
It gets already running acad object or creates new one when acad unavailable.
'-------------------------------------------------------------------------------------
Public Function GetACAD() As Object
        Dim regs As RegistryKey = Nothing
        'HKEY_LOCAL_MACHINE\SOFTWARE\Autodesk\AutoCAD\R18.1
        Try
            regs = Registry.CurrentUser.OpenSubKey("SOFTWARE\Autodesk\AutoCAD\R17.2")
            If regs IsNot Nothing Then Return GetAcadOpp("17")
            regs = Registry.CurrentUser.OpenSubKey("SOFTWARE\Autodesk\AutoCAD\R17.1")
            If regs IsNot Nothing Then Return GetAcadOpp("17")
            regs = Registry.CurrentUser.OpenSubKey("SOFTWARE\Autodesk\AutoCAD\R17.0")
            If regs IsNot Nothing Then Return GetAcadOpp("17")
            regs = Registry.CurrentUser.OpenSubKey("SOFTWARE\Autodesk\AutoCAD\R16.2")
            If regs IsNot Nothing Then Return GetAcadOpp("16")
            regs = Registry.CurrentUser.OpenSubKey("SOFTWARE\Autodesk\AutoCAD\R16.1")
            If regs IsNot Nothing Then Return GetAcadOpp("16")
            regs = Registry.CurrentUser.OpenSubKey("SOFTWARE\Autodesk\AutoCAD\R16.0")
            If regs IsNot Nothing Then Return GetAcadOpp("16")
        Catch ex As Exception
            MsgBox("Error Getting AutoCAD Info " & ex.Message)
        End Try
        Return Nothing
    End Function
'-------------------------------------------------------------------------------------
    Private Function GetAcadOpp(ByVal AcadString As String) As Object
        Dim AcadApp As Object = Nothing
        Try
            AcadApp = GetObject(, "AutoCAD.Application." & AcadString)
            Return AcadApp
        Catch ex As Exception
            AcadApp = Nothing
        Finally
        End Try
        If IsNothing(AcadApp) Then
            Try
                AcadApp = CreateObject("AutoCAD.Application." & AcadString)
                Return AcadApp
            Catch ex As Exception
                AcadApp = Nothing
            Finally
            End Try
        End If
        Return AcadApp
    End Function
'-------------------------------------------------------------------------------------
i do not want to modify the code when newer version came.
 i want to run my application irrespective of any version. because my application uses very basic functions of autocad.
without checking current installed autocad version, how can i achive this?
how managed dlls handle this? please share.
note : My application task is just inserts a block and explode it & do little modifications.
all these functions are same and available from almost all acad releses.

 

Thanks & Regards,
G
2 REPLIES 2
Message 2 of 3
leefsma
in reply to: ProfWolfMan

Hi G,

 

Did you try to simply use the ProgId "AutoCAD.Application", without specifiying the version? This should launch the last version run by the user.

 

For any other approach, you would need to scan the registry in order to detect installed versions like you are doing currently.

 

The managed dlls are loaded directly by AutoCAD and they reside in its install folder, so the situation is different. For client dlls, they can be demand loaded and need to create entries in the specifc registry location corresponding to the AutoCAD version they need to be loaded by.

 

I hope it helps.

 

Philippe Leefsma
Developer Consultant
Developer Technical Services
Global Subscription & Support
 

Autodesk EMEA

  

www.autodesk.com/joinadn

 

Message 3 of 3
ProfWolfMan
in reply to: leefsma

Hi Leefsma,

 

In my working environment we have AutoCAD2008 and AutoCAD2011. I tested both it working well.

Some time i need to run my tool in our client place, they have only AutoCAD2005.

 

For me, it is long time headache. Thank you very much to clear this.

 

 

Thanks & Regards,
G

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