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