<?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 Get AutoCAD.Application Instance in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/get-autocad-application-instance/m-p/10966377#M13556</link>
    <description>&lt;P&gt;Hi everybody.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to get an AutoCAD.Application instance.&lt;/P&gt;&lt;P&gt;However, an error occurs when GetActiveObject() is executed during the AutoCAD loading screen.&lt;/P&gt;&lt;P&gt;If I set a breakpoint and call GetActiveObject() after loading is finished, the instance is got well.&lt;/P&gt;&lt;P&gt;Is there an event or other method in .Net to use when the loading window ends?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;internal class Program
{
    static void Main(string[] args)
    {
        AcadApplication objAcad = default(AcadApplication);
        const string strProgId = "AutoCAD.Application.24.1";

        Process myProcess = new Process();
        myProcess.StartInfo.FileName = @"C:\Program Files\Autodesk\AutoCAD 2022\" + "acad.exe";
        myProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
        myProcess.Start();
        
        try
        {
            objAcad = Marshal.GetActiveObject(strProgId) as AcadApplication;
            if (objAcad is null)
                throw new Exception("obj is null");
        }
        catch(Exception ex) // An error occurs if no instance is running
         {
            Type acType = Type.GetTypeFromProgID(strProgId);

            objAcad = (AcadApplication)Activator.CreateInstance(acType, true);
        }

        objAcad.Visible = true;
    }
}&lt;/LI-CODE&gt;</description>
    <pubDate>Wed, 23 Feb 2022 01:30:47 GMT</pubDate>
    <dc:creator>shkangE79NB</dc:creator>
    <dc:date>2022-02-23T01:30:47Z</dc:date>
    <item>
      <title>Get AutoCAD.Application Instance</title>
      <link>https://forums.autodesk.com/t5/net-forum/get-autocad-application-instance/m-p/10966377#M13556</link>
      <description>&lt;P&gt;Hi everybody.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to get an AutoCAD.Application instance.&lt;/P&gt;&lt;P&gt;However, an error occurs when GetActiveObject() is executed during the AutoCAD loading screen.&lt;/P&gt;&lt;P&gt;If I set a breakpoint and call GetActiveObject() after loading is finished, the instance is got well.&lt;/P&gt;&lt;P&gt;Is there an event or other method in .Net to use when the loading window ends?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;internal class Program
{
    static void Main(string[] args)
    {
        AcadApplication objAcad = default(AcadApplication);
        const string strProgId = "AutoCAD.Application.24.1";

        Process myProcess = new Process();
        myProcess.StartInfo.FileName = @"C:\Program Files\Autodesk\AutoCAD 2022\" + "acad.exe";
        myProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
        myProcess.Start();
        
        try
        {
            objAcad = Marshal.GetActiveObject(strProgId) as AcadApplication;
            if (objAcad is null)
                throw new Exception("obj is null");
        }
        catch(Exception ex) // An error occurs if no instance is running
         {
            Type acType = Type.GetTypeFromProgID(strProgId);

            objAcad = (AcadApplication)Activator.CreateInstance(acType, true);
        }

        objAcad.Visible = true;
    }
}&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 23 Feb 2022 01:30:47 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/get-autocad-application-instance/m-p/10966377#M13556</guid>
      <dc:creator>shkangE79NB</dc:creator>
      <dc:date>2022-02-23T01:30:47Z</dc:date>
    </item>
    <item>
      <title>Re: Get AutoCAD.Application Instance</title>
      <link>https://forums.autodesk.com/t5/net-forum/get-autocad-application-instance/m-p/10966910#M13557</link>
      <description>&lt;P&gt;Could you please clarify why you need to do all this manually instead of just calling new AcadApplication()&lt;A href="https://www.tommypet.com/" target="_blank" rel="noopener"&gt;&lt;FONT color="#fef3e3"&gt;I&lt;/FONT&gt;&lt;/A&gt;(if you can guarantee exact version of AutoCad Installed) or&amp;nbsp;or&amp;nbsp;ActivatorCreateInstance(acType)&amp;nbsp;(version independent)? Both approaches should connect to running AutoCAD instance or run new one if none running.&lt;/P&gt;</description>
      <pubDate>Wed, 23 Feb 2022 09:41:47 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/get-autocad-application-instance/m-p/10966910#M13557</guid>
      <dc:creator>itimdavid27</dc:creator>
      <dc:date>2022-02-23T09:41:47Z</dc:date>
    </item>
    <item>
      <title>Re: Get AutoCAD.Application Instance</title>
      <link>https://forums.autodesk.com/t5/net-forum/get-autocad-application-instance/m-p/10967213#M13558</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;Typically, this is done this way (see &lt;A href="https://help.autodesk.com/view/OARX/2022/ENU/?guid=GUID-C8C65D7A-EC3A-42D8-BF02-4B13C2EA1A4B" target="_blank" rel="noopener"&gt;this topic&lt;/A&gt; from the documentation):&lt;/P&gt;
&lt;LI-CODE lang="csharp"&gt;  AcadApplication acadApp = null;
  const string progId = "AutoCAD.Application.24.1";
 
  // Try to get a running instance of AutoCAD
  try
  {
      acadApp = (AcadApplication)Marshal.GetActiveObject(progId);
  }
  catch // An error occurs if no instance is running
  {
      try
      {
          // Try to create a new instance of AutoCAD
          acadApp = (AcadApplication)Activator.CreateInstance(Type.GetTypeFromProgID(progId), true);
      }
      catch
      {
          // If an instance of AutoCAD is not created then message and exit
          System.Windows.Forms.MessageBox.Show(
		      "Instance of 'AutoCAD.Application' could not be created.");
 
          return;
      }
  }&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 23 Feb 2022 12:48:46 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/get-autocad-application-instance/m-p/10967213#M13558</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2022-02-23T12:48:46Z</dc:date>
    </item>
  </channel>
</rss>

