<?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: Opening AutoCAD and AutoCAD Electrical Simultaneouly using C# in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/opening-autocad-and-autocad-electrical-simultaneouly-using-c/m-p/10591116#M15413</link>
    <description>&lt;P&gt;sorry i missed "Marshal" in your original post. the link i provided works with the&amp;nbsp;System.Diagnostics.Process.Start method - something like this:&lt;/P&gt;&lt;P&gt;System.Diagnostics.Process.Start (@"C:\Program Files\Autodesk\AutoCAD 2020\acad.exe", "/product ACAD /language \"en-US\"") ;&lt;/P&gt;&lt;P&gt;if you want to try that check the "Target" value in the desktop icons if you have them.&lt;/P&gt;&lt;P&gt;i have never used interop. search this forum for "gettypefromprogid".&lt;/P&gt;&lt;P&gt;there is also&amp;nbsp;&lt;A href="https://adndevblog.typepad.com/autocad/2013/12/accessing-com-applications-from-the-running-object-table.html" target="_blank" rel="noopener"&gt;&amp;gt;&amp;gt;this link&amp;lt;&amp;lt;&lt;/A&gt;&amp;nbsp;for multiple instances but not sure if you need that.&amp;nbsp; &amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 01 Sep 2021 16:45:23 GMT</pubDate>
    <dc:creator>fieldguy</dc:creator>
    <dc:date>2021-09-01T16:45:23Z</dc:date>
    <item>
      <title>Opening AutoCAD and AutoCAD Electrical Simultaneouly using C#</title>
      <link>https://forums.autodesk.com/t5/net-forum/opening-autocad-and-autocad-electrical-simultaneouly-using-c/m-p/10587201#M15408</link>
      <description>&lt;P&gt;Hi,&lt;BR /&gt;&lt;BR /&gt;I have been working on creating a Windows application (in C#) to open some drawings in both AutoCAD and AutoCAD electrical.&lt;BR /&gt;As of now, I am able to open the last used AutoCAD application&lt;BR /&gt;like if I have opened and closed AutoCAD, the windows application will open AutoCAD&lt;BR /&gt;If I have opened and closed AutoCAD electrical, the windows application will open AutoCAD Electrical&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am using the Marshal method and create instance method to try and open both.&lt;/P&gt;&lt;P&gt;My question is that, is it possible to open both AutoCAD and AutoCAD Electrical simultaneouly from the windows application?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance.&lt;/P&gt;</description>
      <pubDate>Tue, 31 Aug 2021 11:54:15 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/opening-autocad-and-autocad-electrical-simultaneouly-using-c/m-p/10587201#M15408</guid>
      <dc:creator>thanigai1311</dc:creator>
      <dc:date>2021-08-31T11:54:15Z</dc:date>
    </item>
    <item>
      <title>Re: Opening AutoCAD and AutoCAD Electrical Simultaneouly using C#</title>
      <link>https://forums.autodesk.com/t5/net-forum/opening-autocad-and-autocad-electrical-simultaneouly-using-c/m-p/10587436#M15409</link>
      <description>&lt;P&gt;check this link. &lt;A href="https://knowledge.autodesk.com/support/autocad/learn-explore/caas/sfdcarticles/sfdcarticles/Startup-switches-for-AutoCAD.html" target="_blank" rel="noopener"&gt;https://knowledge.autodesk.com/support/autocad/learn-explore/caas/sfdcarticles/sfdcarticles/Startup-switches-for-AutoCAD.html&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 31 Aug 2021 13:23:43 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/opening-autocad-and-autocad-electrical-simultaneouly-using-c/m-p/10587436#M15409</guid>
      <dc:creator>fieldguy</dc:creator>
      <dc:date>2021-08-31T13:23:43Z</dc:date>
    </item>
    <item>
      <title>Re: Opening AutoCAD and AutoCAD Electrical Simultaneouly using C#</title>
      <link>https://forums.autodesk.com/t5/net-forum/opening-autocad-and-autocad-electrical-simultaneouly-using-c/m-p/10589525#M15410</link>
      <description>&lt;P&gt;Hi&lt;BR /&gt;Thanks for the reply but I want to open them from a Windows application(WinForm) using C#&lt;/P&gt;</description>
      <pubDate>Wed, 01 Sep 2021 05:56:50 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/opening-autocad-and-autocad-electrical-simultaneouly-using-c/m-p/10589525#M15410</guid>
      <dc:creator>thanigai1311</dc:creator>
      <dc:date>2021-09-01T05:56:50Z</dc:date>
    </item>
    <item>
      <title>Re: Opening AutoCAD and AutoCAD Electrical Simultaneouly using C#</title>
      <link>https://forums.autodesk.com/t5/net-forum/opening-autocad-and-autocad-electrical-simultaneouly-using-c/m-p/10590231#M15411</link>
      <description>&lt;P&gt;i understand that you want to start autocad from a winform - that is the first line in your post. you said "&lt;SPAN&gt;I am using the Marshal method and create instance method to try and open both".&amp;nbsp;&lt;/SPAN&gt;show your code for that.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 01 Sep 2021 11:16:50 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/opening-autocad-and-autocad-electrical-simultaneouly-using-c/m-p/10590231#M15411</guid>
      <dc:creator>fieldguy</dc:creator>
      <dc:date>2021-09-01T11:16:50Z</dc:date>
    </item>
    <item>
      <title>Re: Opening AutoCAD and AutoCAD Electrical Simultaneouly using C#</title>
      <link>https://forums.autodesk.com/t5/net-forum/opening-autocad-and-autocad-electrical-simultaneouly-using-c/m-p/10590695#M15412</link>
      <description>&lt;P&gt;Hi&lt;BR /&gt;Here I attach the method that used to call and open a new instance of the application&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;AcadApplication acadApp = null
public AcadApplication TryOpenAcadapplication()
            try
            {
                acadApp  = (AcadApplication)Marshal.GetActiveObject(AutoCAD.Application);
            }
            catch
            {
                try
                {
                    acadApp = (AcadApplication)Activator.CreateInstance(Type.GetTypeFromProgID(AutoCAD.Application));
                   acadApp.Visible = true;
                }
                catch (System.Exception ex)
                {
                     MessageBox.Show(ex.ToString());
                     MessageBox.Show(AutoCAD Application cannot be opened)
                }
            }&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 01 Sep 2021 14:09:51 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/opening-autocad-and-autocad-electrical-simultaneouly-using-c/m-p/10590695#M15412</guid>
      <dc:creator>thanigai1311</dc:creator>
      <dc:date>2021-09-01T14:09:51Z</dc:date>
    </item>
    <item>
      <title>Re: Opening AutoCAD and AutoCAD Electrical Simultaneouly using C#</title>
      <link>https://forums.autodesk.com/t5/net-forum/opening-autocad-and-autocad-electrical-simultaneouly-using-c/m-p/10591116#M15413</link>
      <description>&lt;P&gt;sorry i missed "Marshal" in your original post. the link i provided works with the&amp;nbsp;System.Diagnostics.Process.Start method - something like this:&lt;/P&gt;&lt;P&gt;System.Diagnostics.Process.Start (@"C:\Program Files\Autodesk\AutoCAD 2020\acad.exe", "/product ACAD /language \"en-US\"") ;&lt;/P&gt;&lt;P&gt;if you want to try that check the "Target" value in the desktop icons if you have them.&lt;/P&gt;&lt;P&gt;i have never used interop. search this forum for "gettypefromprogid".&lt;/P&gt;&lt;P&gt;there is also&amp;nbsp;&lt;A href="https://adndevblog.typepad.com/autocad/2013/12/accessing-com-applications-from-the-running-object-table.html" target="_blank" rel="noopener"&gt;&amp;gt;&amp;gt;this link&amp;lt;&amp;lt;&lt;/A&gt;&amp;nbsp;for multiple instances but not sure if you need that.&amp;nbsp; &amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 01 Sep 2021 16:45:23 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/opening-autocad-and-autocad-electrical-simultaneouly-using-c/m-p/10591116#M15413</guid>
      <dc:creator>fieldguy</dc:creator>
      <dc:date>2021-09-01T16:45:23Z</dc:date>
    </item>
    <item>
      <title>Re: Opening AutoCAD and AutoCAD Electrical Simultaneouly using C#</title>
      <link>https://forums.autodesk.com/t5/net-forum/opening-autocad-and-autocad-electrical-simultaneouly-using-c/m-p/10593341#M15414</link>
      <description>&lt;P&gt;The startup application is determined by the registry. There is a post here that may be what you need, or at least to guide you in the right direction:&lt;/P&gt;&lt;P&gt;&lt;A href="https://forums.autodesk.com/t5/autocad-forum/what-does-quot-autocad-dwg-launcher-quot-does-in-detail/m-p/8028027/highlight/true#M934674" target="_blank" rel="noopener"&gt;AutoCAD DWG Launcher Registry&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you do find the solution, please post it for everyone to see.&lt;/P&gt;</description>
      <pubDate>Thu, 02 Sep 2021 11:31:20 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/opening-autocad-and-autocad-electrical-simultaneouly-using-c/m-p/10593341#M15414</guid>
      <dc:creator>jtoverka</dc:creator>
      <dc:date>2021-09-02T11:31:20Z</dc:date>
    </item>
    <item>
      <title>Re: Opening AutoCAD and AutoCAD Electrical Simultaneouly using C#</title>
      <link>https://forums.autodesk.com/t5/net-forum/opening-autocad-and-autocad-electrical-simultaneouly-using-c/m-p/10593944#M15415</link>
      <description>&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/81963"&gt;@fieldguy&lt;/a&gt;&amp;nbsp;'s reply (Message 6) provided enough technical information, I think.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However, I wish you provided more information on why you need to start multiple AutoCAD (and its verticals) instances from a stand-alone desktop EXE. If the solution is meant for user working in front of computer, I can hardly see it is user friendly: running 2 app for a job task (the win form app plus one automated ACAD instance) is bad enough in most cases; running 3 or more? I'd consider it is disaster. I'd avoid this kind of solution at all cost.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;With that said, as&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/81963"&gt;@fieldguy&lt;/a&gt;&amp;nbsp;'s advice, I quickly built a console EXE app to just prove how to do what you want:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The app does following:&lt;/P&gt;
&lt;P&gt;1. Start 2 instance of AutoCAD: vanilla AutoCAD2020 and C3D 2021. They are started with Process.Start() with proper arguments, which include switch "/product", so that the Acad instance is started as the desired Acad vertical.&lt;/P&gt;
&lt;P&gt;2. Use ROT (Running Object Table) to identify different "Product" of the Acad instance and obtain the COM objects back, which could be cast into AcadApplication for early binding. But I'd keep the COM object as dynamic for late binding.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The code for the console app:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;using System;
using System.Collections.Generic;
using System.Diagnostics;

namespace GetMultiComInstances
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Press Enter to continue...");
            Console.ReadLine();

            var clsIds = StartAutoCADInstances();

            // Wait for the AutoCADs get fully started before searching the ROT
            // If the code to go through ROT runs with the different Acad instance
            // are already there, there is no need to wait.
            System.Threading.Thread.Sleep(20000);

            var instances = RotUtils.GetAcadInstanceComObjects(clsIds);
            if (instances!=null &amp;amp;&amp;amp; instances.Count&amp;gt;0)
            {
                foreach (var ins in instances)
                {
                    // Get a late bound AcadApplication object
                    dynamic acad = ins.Item2; 

                    // For example, from acad.Caption property,
                    // one can tell the acad COM object is AutoCAD, or C3D
                    Console.WriteLine($"Instance: {ins.Item1}; Product: {acad.Caption}");
                }
            }

            Console.WriteLine("Press Enter to exit...");
            Console.ReadLine();
        }

        private static List&amp;lt;string&amp;gt; StartAutoCADInstances()
        {
            var clsIds = new List&amp;lt;string&amp;gt;();

            var clsId = StartPlainAcad2020();
            if (!string.IsNullOrEmpty(clsId)) clsIds.Add(clsId);

            clsId = StartC3D2021();
            if (!string.IsNullOrEmpty(clsId)) clsIds.Add(clsId);

            return clsIds;
        }

        private static string StartPlainAcad2020()
        {
            try
            {
                Console.WriteLine("Starting AutoCAD 2020...Please wait...");
                var process = Process.Start(
                    @"C:\Program Files\Autodesk\AutoCAD 2020\acad.exe",
                    "\"C:\\Temp\\Test01.dwg\" /product ACAD /language \"en - US\"");
                process.WaitForInputIdle();
                Console.WriteLine("AutoCAD 2020 started!");

                Type t = Type.GetTypeFromProgID("AutoCAD.Application.23.1");
                return t.GUID.ToString();
            }
            catch
            {
                Console.WriteLine("Starting AutoCAD 2020 failed!");
                return null;
            }
        }

        private static string StartC3D2021()
        {
            try
            {
                Console.WriteLine("Starting C3D 2021...Please wait...");
                var process =  Process.Start(
                    @"C:\Program Files\Autodesk\AutoCAD 2021\acad.exe", 
                    "\"C:\\Temp\\Test02.dwg\" /ld \"C:\\Program Files\\Autodesk\\AutoCAD 2021\\AecBase.dbx\" " +
                    "/p \"&amp;lt;&amp;lt;C3D_Metric&amp;gt;&amp;gt;\" /product \"C3D\" /language \"en - US\"");
                process.WaitForInputIdle();
                Console.WriteLine("C3D 2021 started!");

                Type t = Type.GetTypeFromProgID("AutoCAD.Application.24");
                return t.GUID.ToString();
            }
            catch
            {
                Console.WriteLine("Starting C3D 2021 failed!");
                return null;
            }
        }
    }
}
&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The code of RotUtils class:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices.ComTypes;
using System.Text;
using System.Threading.Tasks;

namespace GetMultiComInstances
{
    public class RotUtils
    {
        [DllImport("ole32.dll")]
        private static extern void CreateBindCtx(int reserved, out IBindCtx ppbc);

        [DllImport("ole32.dll")]
        private static extern int GetRunningObjectTable(int reserved, out IRunningObjectTable prot);

        public static List&amp;lt;Tuple&amp;lt;string, object&amp;gt;&amp;gt; GetAcadInstanceComObjects(List&amp;lt;string&amp;gt; classIds)
        {
            IRunningObjectTable rot;
            IEnumMoniker enumMoniker;
            GetRunningObjectTable(0, out rot);
            if (rot == null) return null;

            rot.EnumRunning(out enumMoniker);
            if (enumMoniker == null) return null;

            IntPtr pNumFetched = new IntPtr();
            IMoniker[] monikers = new IMoniker[1];

            List&amp;lt;Tuple&amp;lt;string, object&amp;gt;&amp;gt; instances = new List&amp;lt;Tuple&amp;lt;string, object&amp;gt;&amp;gt;();

            // go through all entries and identifies app instances
            while (enumMoniker.Next(1, monikers, pNumFetched) == 0)
            {
                IBindCtx bindCtx;
                CreateBindCtx(0, out bindCtx);
                if (bindCtx == null) continue;

                string displayName;
                monikers[0].GetDisplayName(bindCtx, null, out displayName);
                Console.WriteLine("Display Name: {0}", displayName);
                foreach (var clsId in classIds)
                {
                    if (displayName.ToUpper().Contains(clsId.ToUpper()))
                    {
                        object comObject;
                        rot.GetObject(monikers[0], out comObject);
                        if (comObject != null)
                        {
                            instances.Add(new Tuple&amp;lt;string, object&amp;gt;(displayName, comObject));
                        }
                    }
                }
            }

            return instances;
        }
    }
}
&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hope this helps. Again, I strongly doubt that running a desktop exe to automate 2 or more instance of AutoCAD is a good solution in most cases, if not all cases.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 02 Sep 2021 15:11:30 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/opening-autocad-and-autocad-electrical-simultaneouly-using-c/m-p/10593944#M15415</guid>
      <dc:creator>norman.yuan</dc:creator>
      <dc:date>2021-09-02T15:11:30Z</dc:date>
    </item>
    <item>
      <title>Re: Opening AutoCAD and AutoCAD Electrical Simultaneouly using C#</title>
      <link>https://forums.autodesk.com/t5/net-forum/opening-autocad-and-autocad-electrical-simultaneouly-using-c/m-p/10594069#M15416</link>
      <description>&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/543921"&gt;@norman.yuan&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If versions of AutoCAD and AutoCAD "vertical" (AE, C3D, etc) are equal (for example 2020 and 2020) - it is impossible to distinguish they in ROT - ROT has only one copy of AutoCAD.&lt;/P&gt;</description>
      <pubDate>Thu, 02 Sep 2021 15:44:56 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/opening-autocad-and-autocad-electrical-simultaneouly-using-c/m-p/10594069#M15416</guid>
      <dc:creator>Alexander.Rivilis</dc:creator>
      <dc:date>2021-09-02T15:44:56Z</dc:date>
    </item>
    <item>
      <title>Re: Opening AutoCAD and AutoCAD Electrical Simultaneouly using C#</title>
      <link>https://forums.autodesk.com/t5/net-forum/opening-autocad-and-autocad-electrical-simultaneouly-using-c/m-p/10594116#M15417</link>
      <description>&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/481027"&gt;@Alexander.Rivilis&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Yes, you are right. My code does not suggest that the COM objects returned from ROT search can be recognized as different verticals of AutoCAD. They are just COM instances of AcadApplication for each running AutoCAD session. That is why I mention the the code comment to use "acad.Caption" would provide the hint of vertical product name (well, unless the running AutoCAD has custom app that manipulate the main window's caption, as AutoCAD .NET API allows it).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So, to make sure which vertical the COM object is, it may require further work, such as trapping exceptions by invoke vertical-only object... But for the OP's original question, if he/she already knows which products to start/or are already started, and there is not code to manipulate the app's caption, it might be good enough to just tell from the Caption property of AcadApplication object.&lt;/P&gt;</description>
      <pubDate>Thu, 02 Sep 2021 15:59:11 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/opening-autocad-and-autocad-electrical-simultaneouly-using-c/m-p/10594116#M15417</guid>
      <dc:creator>norman.yuan</dc:creator>
      <dc:date>2021-09-02T15:59:11Z</dc:date>
    </item>
    <item>
      <title>Re: Opening AutoCAD and AutoCAD Electrical Simultaneouly using C#</title>
      <link>https://forums.autodesk.com/t5/net-forum/opening-autocad-and-autocad-electrical-simultaneouly-using-c/m-p/10602826#M15418</link>
      <description>&lt;P&gt;Thanks for the solution &lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/543921"&gt;@norman.yuan&lt;/a&gt;,&lt;BR /&gt;I think this will solve my problem.&lt;BR /&gt;and once again thanks for the Input&lt;/P&gt;</description>
      <pubDate>Mon, 06 Sep 2021 12:33:18 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/opening-autocad-and-autocad-electrical-simultaneouly-using-c/m-p/10602826#M15418</guid>
      <dc:creator>thanigai1311</dc:creator>
      <dc:date>2021-09-06T12:33:18Z</dc:date>
    </item>
  </channel>
</rss>

