Here is the link to the code I found from Fixo. It's way down the page at post #12. Fixo is really good at this kind of stuff and he has been a big help in the past. I sent him a PM with the code I modified to see if he has time to assist. The code works and it will actually open an existing drawing, which is what I'm eventually going to have to do, like the VBA code I am using now. It also opens AutoCAD up in a very tall and narrow window instead of maximized. In addition, I will need to load and execute the LISP program.
http://www.dreamincode.net/forums/to...pen-a-drawing/
Here is the code from Fixo as I have modified it. It was actually a form, but I am working on a user-input-less process so I changed it over to a Console Application.
Code:
Imports System.Runtime.InteropServices
Imports System.Reflection
Imports System.Globalization
Imports System.Collections
Public Class ReflectionCommands
<System.Security.SuppressUnmanagedCodeSecurity()> _
Public Shared Sub TestACAD(ByVal dwgname As String)
'Save current culture to variable
Dim thisThread As System.Globalization.CultureInfo = System.Threading.Thread.CurrentThread.CurrentCulture
'Set culture to whatever you want
thisThread = New System.Globalization.CultureInfo("en-US")
Dim appProgID As String = "AutoCAD.Application"
Dim filename As String = dwgname
'NGet reference on intergrace IDispatch
Dim AcadType As Type = Type.GetTypeFromProgID(appProgID)
'Launch AutoCAD
Dim AcadApp As Object = Activator.CreateInstance(AcadType)
Dim visargs() As Object = New Object(0) {}
visargs(0) = True
'Set Application Window visible
AcadApp.GetType().InvokeMember("Visible", BindingFlags.SetProperty, Nothing, AcadApp, visargs, Nothing)
Dim AcadDocs As Object = AcadApp.GetType().InvokeMember("Documents", BindingFlags.GetProperty, Nothing, AcadApp, Nothing)
'Create array of parameters
Dim args() As Object = New Object(1) {}
args(0) = filename
args(1) = False ' read-only=false
'open a drawing
Dim AcDoc As Object = AcadDocs.GetType.InvokeMember("Open", BindingFlags.InvokeMethod, Nothing, AcadDocs, args, Nothing)
Dim Util As Object = New Object
Try
'Get reference on active document
AcDoc = AcadApp.GetType.InvokeMember("ActiveDocument", BindingFlags.GetProperty, Nothing, AcadApp, Nothing, Nothing)
'Get reference on AcadUtility
Util = AcDoc.GetType().InvokeMember("Utility", BindingFlags.GetProperty, Nothing, AcDoc, Nothing)
'Get reference on ModelSpace
Dim oSpace As Object = AcDoc.GetType.InvokeMember("ModelSpace", BindingFlags.GetProperty, Nothing, AcDoc, Nothing)
Catch ex As Exception
End Try
End Sub
End Class
Module Module1
Sub Main()
Dim fname As String = "H:\Test123.dwg"
ReflectionCommands.TestACAD(fname)
End Sub
End Module
Bookmarks