.NET
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic to the Top
- Bookmark
- Subscribe
- Printer Friendly Page
Re: Connecting to AutoCAD
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Both ways is woking for me with A2009 Win7
Try again
{code}
''1st way
Private Function GetAcadVer() As String
Dim acadver As Object
Try
acadver = My.Computer.Registry.GetValue("HKEY_CLASSES_ROOT\A
String.Empty, String.Empty)
If TypeOf acadver Is String Then
'MessageBox.Show("String acadver: " & acadver.ToString())
Return acadver.ToString()
Else
Return Nothing
End If
Catch
Return Nothing
End Try
End Function
Public Sub connectAutoCad()
Dim acApp As Object = Nothing
Dim progID As String = GetAcadVer()
Try
'try to get a current instance of AutoCAD
acApp = Marshal.GetActiveObject(progID)
Catch
'try to create a new instance of AutoCAD
Dim acType As Type = Type.GetTypeFromProgID(progID)
acApp = Activator.CreateInstance(acType, True)
End Try
acApp.GetType().InvokeMember("visible", Reflection.BindingFlags.SetProperty + Reflection.BindingFlags.IgnoreCase, Nothing, acApp, New Object() {True})
acApp.GetType().InvokeMember("eval", Reflection.BindingFlags.InvokeMethod + Reflection.BindingFlags.IgnoreCase, Nothing, acApp, New Object() {"MsgBox(" + """Hello Discussion group""" + ")"})
acApp.GetType().InvokeMember("quit", Reflection.BindingFlags.InvokeMethod + Reflection.BindingFlags.IgnoreCase, Nothing, acApp, Nothing)
Marshal.FinalReleaseComObject(acApp)
acApp = Nothing
End Sub
''2nd way
Private Sub GetAcadApp(ByVal AcadString As String)
Dim AcadApp As Object = Nothing
Try
AcadApp = GetObject(, "AutoCAD.Application." & AcadString)
Catch
AcadApp = CreateObject("AutoCAD.Application." & AcadString)
AcadApp.GetType().InvokeMember("Visible", Reflection.BindingFlags.SetProperty + Reflection.BindingFlags.IgnoreCase, Nothing, AcadApp, New Object() {True})
MessageBox.Show(AcadApp.GetType().InvokeMember("Na
Finally
AcadApp.GetType().InvokeMember("Quit", Reflection.BindingFlags.InvokeMethod + Reflection.BindingFlags.IgnoreCase, Nothing, AcadApp, Nothing)
Marshal.FinalReleaseComObject(AcadApp)
AcadApp = Nothing
End Try
End Sub
''example:
''on button click call
'' GetAcadApp("17")
{code}
~'J'~
C6309D9E0751D165D0934D0621DFF27919
Re: Connecting to AutoCAD
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Still doesn't work. Just to confirm, did the code you use work with just one version of AutoCAD or have you been able to use it to connect to different versions on different machines using the same executable?
Re: Connecting to AutoCAD
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
I'm working nowhere, sorry
just tested this code on my home machine - A2009(eng) release
C6309D9E0751D165D0934D0621DFF27919
Re: Connecting to AutoCAD
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
cvaught wrote:Same problem still exists. It starts acad.exe but cannot connect to it. Any other opitons? This seems like it should be pretty straight forward. How else can a stand along application support multiple versions of AutoCAD?
There is no way that the same exe can support multiple versions of AutoCAD.
Different version or OS (X64 ,X86) of AutoCAD has different library.
The best way is to recomplie another project (the same code but has different reference librayies).
Huilung Chen



