Imports System Imports System.Runtime.InteropServices Imports Autodesk.AutoCAD.Interop Public Interface IMessageFilter _ Function HandleInComingCall(ByVal dwCallType As Integer, ByVal hTaskCaller As IntPtr, ByVal dwTickCount As Integer, ByVal lpInterfaceInfo As IntPtr) As Integer _ Function RetryRejectedCall(ByVal hTaskCallee As IntPtr, ByVal dwTickCount As Integer, ByVal dwRejectType As Integer) As Integer _ Function MessagePending(ByVal hTaskCallee As IntPtr, ByVal dwTickCount As Integer, ByVal dwPendingType As Integer) As Integer End Interface Public Class Form1 'rename this to match your form name Implements IMessageFilter Private Declare Function CoRegisterMessageFilter Lib "ole32.dll" (ByVal lpMessageFilter As IMessageFilter, ByRef lplpMessageFilter As IMessageFilter) As Integer Function IMessageFilter_HandleInComingCall(ByVal dwCallType As Integer, ByVal hTaskCaller As IntPtr, ByVal dwTickCount As Integer, ByVal lpInterfaceInfo As IntPtr) As Integer Implements IMessageFilter.HandleInComingCall Return 0 ' SERVERCALL_ISHANDLED End Function Function IMessageFilter_RetryRejectedCall(ByVal hTaskCallee As IntPtr, ByVal dwTickCount As Integer, ByVal dwRejectType As Integer) As Integer Implements IMessageFilter.RetryRejectedCall Return 1000 ' Retry in a second End Function Function IMessageFilter_MessagePending(ByVal hTaskCallee As IntPtr, ByVal dwTickCount As Integer, ByVal dwPendingType As Integer) As Integer Implements IMessageFilter.MessagePending Return 1 ' PENDINGMSG_WAITNOPROCESS End Function Public Sub New() ' This call is required by the Windows Form Designer. InitializeComponent() ' Add any initialization after the InitializeComponent() call. Dim oldFilter As IMessageFilter CoRegisterMessageFilter(Me, oldFilter) End Sub 'put your form code here, and if you have a Sub New, make sure to merge your Sub New with the code in the one above. Public acApp As AcadApplication = Nothing Private Sub btnStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStart.Click acApp = Nothing Const progID As String = "AutoCAD.Application.18" Try acApp = DirectCast(Marshal.GetActiveObject(progID), AcadApplication) Catch ex1 As Exception Try Dim acType As Type = Type.GetTypeFromProgID(progID) acApp = DirectCast(Activator.CreateInstance(acType, True), AcadApplication) Catch ex2 As Exception MessageBox.Show("Cannot create object of type """ & progID & """") End Try End Try If acApp IsNot Nothing Then Try Dim doc As AcadDocument = acApp.ActiveDocument Dim pt1(2) As Double pt1(0) = 4 pt1(1) = 0 pt1(2) = 0 doc.ModelSpace.AddCircle(pt1, 4) Dim pt2(2) As Double pt2(0) = 7 pt2(1) = 8 pt2(2) = 0 doc.ModelSpace.AddLine(pt1, pt2) Dim SaveType As Common.AcSaveAsType = Common.AcSaveAsType.ac2010_dwg doc.SaveAs("D:\Test.dwg", SaveType, ) doc.Close() Catch ex1 As Exception MsgBox(ex1.Message) Finally Try acApp.Application.Quit() Catch ex2 As Exception MsgBox(ex2.Message) End Try End Try End If End Sub End Class