<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Cannot Launch Autocad from external vb.net application. in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/cannot-launch-autocad-from-external-vb-net-application/m-p/7944172#M26242</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When starting a new AutoCAD process, you should wait for AutoCAD finish intialization before calling method on the AutoCAD Application instance.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;        Try
            While Not AcApp.GetAcadState.IsQuiescent
                Thread.Sleep(100)
            End While
        Catch ex As Exception
        End Try&lt;/PRE&gt;</description>
    <pubDate>Thu, 19 Apr 2018 09:23:18 GMT</pubDate>
    <dc:creator>_gile</dc:creator>
    <dc:date>2018-04-19T09:23:18Z</dc:date>
    <item>
      <title>Cannot Launch Autocad from external vb.net application.</title>
      <link>https://forums.autodesk.com/t5/net-forum/cannot-launch-autocad-from-external-vb-net-application/m-p/7944138#M26241</link>
      <description>&lt;P&gt;I have an vb.net application that take a list of drawings and&amp;nbsp; open every one in Autocad, do some changes and print it. The application is an EXE file and works fine if Autocad is already running in the computer but fail if Autocad is not running yet. I'm working with visual studio 2015 and autocad 2018. This is the code that opens Autocad:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Imports System&lt;BR /&gt;Imports System.Runtime.InteropServices&lt;BR /&gt;Imports AutoCAD&lt;/P&gt;&lt;P&gt;Public Class cAcad&lt;/P&gt;&lt;P&gt;Public Sub RunAcad()&lt;BR /&gt;Dim ProgId As String = "AutoCAD.Application.22"&lt;BR /&gt;Dim AcApp As AcadApplication = Nothing&lt;/P&gt;&lt;P&gt;Try&lt;BR /&gt;&amp;nbsp; &amp;nbsp;AcApp = DirectCast(Marshal.GetActiveObject(ProgId), AcadApplication)&lt;/P&gt;&lt;P&gt;Catch ex As Exception&lt;BR /&gt;&amp;nbsp; Try&lt;BR /&gt;&amp;nbsp; &amp;nbsp; Dim AcType As Type = Type.GetTypeFromProgID(ProgId)&lt;BR /&gt;&amp;nbsp; &amp;nbsp; AcApp = DirectCast(Activator.CreateInstance(AcType, True), AcadApplication)&lt;BR /&gt;&amp;nbsp; Catch ex2 As Exception&lt;BR /&gt;&amp;nbsp; &amp;nbsp; MessageBox.Show("Cannot create object of type " &amp;amp; ProgId &amp;amp; vbNewLine &amp;amp; ex2.Message)&lt;BR /&gt;&amp;nbsp; End Try&lt;BR /&gt;End Try&lt;BR /&gt;If AcApp IsNot Nothing Then&lt;BR /&gt;&amp;nbsp; Try&lt;BR /&gt;&amp;nbsp; &amp;nbsp; AcApp.Documents.Add()&lt;/P&gt;&lt;P&gt;&amp;nbsp; Catch ex As Exception&lt;BR /&gt;&amp;nbsp; &amp;nbsp; MessageBox.Show("Cannot add a new document " &amp;amp; ProgId &amp;amp; vbNewLine &amp;amp; ex.Message)&lt;/P&gt;&lt;P&gt;&amp;nbsp; End Try&lt;BR /&gt;End If&lt;BR /&gt;End Sub&lt;/P&gt;&lt;P&gt;End Class&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The error doesn't come&amp;nbsp;in "createInstance",&amp;nbsp;but it comes&amp;nbsp;in "documents.add" sentence because&amp;nbsp; Acad.exe is not running. The error is :&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;El servidor lanzó una excepción. (Excepción de HRESULT: 0x80010105 (RPC_E_SERVERFAULT)).&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;I have tried many different ways to create the new object but always found the same problem.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Note: When createObject is running I can see Acad.exe in taskManager but when the sentence finish, acad.exe disapear.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 19 Apr 2018 09:07:58 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/cannot-launch-autocad-from-external-vb-net-application/m-p/7944138#M26241</guid>
      <dc:creator>sat</dc:creator>
      <dc:date>2018-04-19T09:07:58Z</dc:date>
    </item>
    <item>
      <title>Re: Cannot Launch Autocad from external vb.net application.</title>
      <link>https://forums.autodesk.com/t5/net-forum/cannot-launch-autocad-from-external-vb-net-application/m-p/7944172#M26242</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When starting a new AutoCAD process, you should wait for AutoCAD finish intialization before calling method on the AutoCAD Application instance.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;        Try
            While Not AcApp.GetAcadState.IsQuiescent
                Thread.Sleep(100)
            End While
        Catch ex As Exception
        End Try&lt;/PRE&gt;</description>
      <pubDate>Thu, 19 Apr 2018 09:23:18 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/cannot-launch-autocad-from-external-vb-net-application/m-p/7944172#M26242</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2018-04-19T09:23:18Z</dc:date>
    </item>
    <item>
      <title>Re: Cannot Launch Autocad from external vb.net application.</title>
      <link>https://forums.autodesk.com/t5/net-forum/cannot-launch-autocad-from-external-vb-net-application/m-p/7944426#M26243</link>
      <description>&lt;P&gt;Thanks Guilles,&lt;/P&gt;&lt;P&gt;but I have the same problem because I can't access any property of the acApp object. When I try to access acAPP.getAcadState the error comes again. it seems that the acapp object is created but is damaged.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Finally I have found a solution using Process.Start. This runs perfectly. Here is the code in case anybody&amp;nbsp;wants to use it:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Public Function OpenAcad() As AcadApplication&lt;BR /&gt;Dim exePath As String = "C:\Program Files\Autodesk\AutoCAD 2018\acad.exe"&lt;BR /&gt;Dim AcApp As AcadApplication = Nothing&lt;BR /&gt;Dim ProgId As String = "AutoCAD.Application.22"&lt;/P&gt;&lt;P&gt;Try&lt;BR /&gt;&amp;nbsp; Dim p As Process&lt;BR /&gt;&amp;nbsp; p = Process.Start(exePath)&lt;/P&gt;&lt;P&gt;&amp;nbsp; While AcApp Is Nothing&lt;BR /&gt;&amp;nbsp; &amp;nbsp; Try&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; AcApp = DirectCast(Marshal.GetActiveObject(ProgId), AcadApplication)&lt;BR /&gt;&amp;nbsp; &amp;nbsp; Catch ex As Exception&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; AcApp = Nothing&lt;BR /&gt;&amp;nbsp; &amp;nbsp; End Try&lt;BR /&gt;&amp;nbsp; End While&lt;BR /&gt;&amp;nbsp; AcApp.Visible = True&lt;BR /&gt;&amp;nbsp; Catch ex As Exception&lt;BR /&gt;&amp;nbsp; &amp;nbsp; MessageBox.Show("Cannot get acad " &amp;amp; vbNewLine &amp;amp; ex.Message)&lt;BR /&gt;&amp;nbsp; End Try&lt;BR /&gt;&amp;nbsp; Return AcApp&lt;BR /&gt;End Function&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 19 Apr 2018 11:05:50 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/cannot-launch-autocad-from-external-vb-net-application/m-p/7944426#M26243</guid>
      <dc:creator>sat</dc:creator>
      <dc:date>2018-04-19T11:05:50Z</dc:date>
    </item>
    <item>
      <title>Re: Cannot Launch Autocad from external vb.net application.</title>
      <link>https://forums.autodesk.com/t5/net-forum/cannot-launch-autocad-from-external-vb-net-application/m-p/7945256#M26244</link>
      <description>&lt;P&gt;You marked your post as a solution, but your problem doesn't seem to be solved.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You are starting AutoCAD via System.Process, and then trying to get the running instance. If there is already a running instance, then you may get that one, rather than the instance you started.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you want to start a new instance and work with it, you should use Activator.CreateInstance(), as shown in the following C# example. It's also wise to use a timeout in case AutoCAD does something unexpected at startup, that blocks access via ActiveX, like shown in the example.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;   public static dynamic StartAcad()
   {
      dynamic acadObject = Activator.CreateInstance(Type.GetTypeFromProgID("AutoCAD.Application"));
      if(acadObject != null)
      {
         DateTime start = DateTime.Now;
         while(true)
         {
            try
            {
               acadObject.Visible = true;
               return acadObject;
            }
            catch
            {
               // If AutoCAD is not ready within 10 seconds, exit:
               if((DateTime.Now - start).Seconds &amp;gt; 10)
                  break;
               System.Threading.Thread.Sleep(100);
            }
         }
      }
      return null;
   }&lt;/PRE&gt;</description>
      <pubDate>Thu, 19 Apr 2018 15:35:50 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/cannot-launch-autocad-from-external-vb-net-application/m-p/7945256#M26244</guid>
      <dc:creator>ActivistInvestor</dc:creator>
      <dc:date>2018-04-19T15:35:50Z</dc:date>
    </item>
    <item>
      <title>Re: Cannot Launch Autocad from external vb.net application.</title>
      <link>https://forums.autodesk.com/t5/net-forum/cannot-launch-autocad-from-external-vb-net-application/m-p/7947036#M26245</link>
      <description>&lt;P&gt;Thanks for your post but,&lt;/P&gt;&lt;P&gt;I use process.start because all my tryals with activator.createInstance() fail.&lt;/P&gt;&lt;P&gt;Also, I call the start.process only if&amp;nbsp; I doesn't found a running instance of acad.exe.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have tried your example and it also fails in my computer. I always reach the timeout, even if I increasse it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The thing is that, I don't know why, the creatInstance try to open acad.exe but it fails without giving any exeption, but the object its not null. While the sentece&amp;nbsp;&lt;SPAN&gt;creatInstance&amp;nbsp;&lt;/SPAN&gt; is running, I can see ACAD.exe in task manager window, but when I reach next sentence, acad.exe disappear in task manager, then acadobject.visible=true always give me an exception:&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;El servidor RPC no esta disponible (exception HRESULT:0x800706BA)&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I take your idea of a timeout for my loop&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 20 Apr 2018 06:51:00 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/cannot-launch-autocad-from-external-vb-net-application/m-p/7947036#M26245</guid>
      <dc:creator>sat</dc:creator>
      <dc:date>2018-04-20T06:51:00Z</dc:date>
    </item>
  </channel>
</rss>

