<?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: Switch Layout using COM API in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/switch-layout-using-com-api/m-p/11241622#M12668</link>
    <description>&lt;P&gt;Yes, you are right.&amp;nbsp;&lt;SPAN&gt;&amp;nbsp;I want to switch autocad layout from external application.&lt;BR /&gt;Yes I have done coding to get instance of AutoCAD. According to the solution provided I have to create separate COMMAND and then load DLL into AutoCAD.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Later, in stand alone application c# code, I need to send newly created command to AutoCAD but it will work only if DLL is loaded into AutoCAD.&lt;BR /&gt;&lt;BR /&gt;Can we do without sending command and control by external application using COM API?&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Fri, 17 Jun 2022 11:38:32 GMT</pubDate>
    <dc:creator>nishad.dhapre</dc:creator>
    <dc:date>2022-06-17T11:38:32Z</dc:date>
    <item>
      <title>Switch Layout using COM API</title>
      <link>https://forums.autodesk.com/t5/net-forum/switch-layout-using-com-api/m-p/11236802#M12664</link>
      <description>&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;SPAN&gt;Hello All,&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to switch layout from model space layout to specific paper space layout(Layout1 or Layout2 and so on.....) using COM API (ActiveX). How can we achieve?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am using c# language.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you in advance.&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Wed, 15 Jun 2022 13:25:58 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/switch-layout-using-com-api/m-p/11236802#M12664</guid>
      <dc:creator>nishad.dhapre</dc:creator>
      <dc:date>2022-06-15T13:25:58Z</dc:date>
    </item>
    <item>
      <title>Re: Switch Layout using COM API</title>
      <link>https://forums.autodesk.com/t5/net-forum/switch-layout-using-com-api/m-p/11241547#M12665</link>
      <description>&lt;P&gt;Below code work for me:&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;        [CommandMethod("SwitchToLayout")]
        public void SwitchToLayout()
        {
            Document doc = Application.DocumentManager.MdiActiveDocument;
            Database db = doc.Database;
            var ed = doc.Editor;
            PromptStringOptions pStrOpts = new PromptStringOptions("\nType Layout Name: ");
            pStrOpts.AllowSpaces = true;
            PromptResult pStrRes = ed.GetString(pStrOpts);
            string layoutName = pStrRes.StringResult;
            if (pStrRes.Status == PromptStatus.OK)
            {
                LayoutManager lm = LayoutManager.Current;
                if (lm.LayoutExists(layoutName))
                {
                    LayoutManager.Current.CurrentLayout = layoutName;
                }
                else
                {
                    ed.WriteMessage("\nLayout cannot be found");
                }
            }
        }&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 17 Jun 2022 11:00:39 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/switch-layout-using-com-api/m-p/11241547#M12665</guid>
      <dc:creator>marcin.sachs</dc:creator>
      <dc:date>2022-06-17T11:00:39Z</dc:date>
    </item>
    <item>
      <title>Re: Switch Layout using COM API</title>
      <link>https://forums.autodesk.com/t5/net-forum/switch-layout-using-com-api/m-p/11241572#M12666</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/2034868"&gt;@marcin.sachs&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you but this code will work for creating command.&lt;/P&gt;&lt;P&gt;I am creating standalone application so I need to use COM API.&lt;BR /&gt;This code will not work for the same.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Nishad Dhapre&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 17 Jun 2022 11:12:41 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/switch-layout-using-com-api/m-p/11241572#M12666</guid>
      <dc:creator>nishad.dhapre</dc:creator>
      <dc:date>2022-06-17T11:12:41Z</dc:date>
    </item>
    <item>
      <title>Re: Switch Layout using COM API</title>
      <link>https://forums.autodesk.com/t5/net-forum/switch-layout-using-com-api/m-p/11241604#M12667</link>
      <description>&lt;P&gt;If I understand well you want to switch autocad layout from external application?&lt;BR /&gt;Firstly you need to get AutoCAD Instance: (below code for AutoCAD 2022)&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;public static AcadApplication GetAcadApplication(bool CreateNewIfNotLaunched)
        {
            AcadApplication acApp = null;
            const string strProgId = "AutoCAD.Application.24.1";
            try
            {
                acApp = (AcadApplication)Marshal.GetActiveObject(strProgId);
            }
            catch
            {
                if (CreateNewIfNotLaunched == true)
                {
                    try
                    {
                        acApp = new AcadApplication();
                        
                    }
                    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 acApp;
        }&lt;/LI-CODE&gt;&lt;P&gt;then you can send command to Autocad:&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;public static void SendCommandToCAD(object sender, EventArgs e, string command)
        {
            AcadApplication CAD = GetAcadApplication(false);
            if (CAD != null)
            {
                // wait for AutoCAD is visible
                while (true)
                {
                    try { CAD.Visible = true; break; }
                    catch { }
                }

                var doc = CAD.ActiveDocument;
                doc.SendCommand(command + " ");
            }
        }&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 17 Jun 2022 11:29:57 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/switch-layout-using-com-api/m-p/11241604#M12667</guid>
      <dc:creator>marcin.sachs</dc:creator>
      <dc:date>2022-06-17T11:29:57Z</dc:date>
    </item>
    <item>
      <title>Re: Switch Layout using COM API</title>
      <link>https://forums.autodesk.com/t5/net-forum/switch-layout-using-com-api/m-p/11241622#M12668</link>
      <description>&lt;P&gt;Yes, you are right.&amp;nbsp;&lt;SPAN&gt;&amp;nbsp;I want to switch autocad layout from external application.&lt;BR /&gt;Yes I have done coding to get instance of AutoCAD. According to the solution provided I have to create separate COMMAND and then load DLL into AutoCAD.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Later, in stand alone application c# code, I need to send newly created command to AutoCAD but it will work only if DLL is loaded into AutoCAD.&lt;BR /&gt;&lt;BR /&gt;Can we do without sending command and control by external application using COM API?&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 17 Jun 2022 11:38:32 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/switch-layout-using-com-api/m-p/11241622#M12668</guid>
      <dc:creator>nishad.dhapre</dc:creator>
      <dc:date>2022-06-17T11:38:32Z</dc:date>
    </item>
    <item>
      <title>Re: Switch Layout using COM API</title>
      <link>https://forums.autodesk.com/t5/net-forum/switch-layout-using-com-api/m-p/11241742#M12669</link>
      <description>&lt;P&gt;you can switch layout directly from external software also:&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;public static void SwitchLayout(object sender, EventArgs e)
        {
            AcadApplication CAD = GetAcadApplication(false);
            if (CAD != null)
            {
                // wait for AutoCAD is visible
                while (true)
                {
                    try { CAD.Visible = true; break; }
                    catch { }
                }

                AcadLayouts layouts = CAD.ActiveDocument.Layouts;

                foreach(AcadLayout layout in layouts)
                {
                    if(layout.Name == "Layout1")
                    {
                        CAD.ActiveDocument.ActiveLayout = layout;
                        break;
                    }
                }
            }
        }&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 17 Jun 2022 12:36:50 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/switch-layout-using-com-api/m-p/11241742#M12669</guid>
      <dc:creator>marcin.sachs</dc:creator>
      <dc:date>2022-06-17T12:36:50Z</dc:date>
    </item>
    <item>
      <title>Re: Switch Layout using COM API</title>
      <link>https://forums.autodesk.com/t5/net-forum/switch-layout-using-com-api/m-p/11242261#M12670</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can set the value of the &lt;A href="https://knowledge.autodesk.com/support/autocad/learn-explore/caas/CloudHelp/cloudhelp/2023/ENU/AutoCAD-Core/files/GUID-20529853-0C88-4417-8D8C-9783E9789BBC-htm.html" target="_blank" rel="noopener"&gt;CTAB&lt;/A&gt; system variable.&lt;/P&gt;
&lt;LI-CODE lang="csharp"&gt;acadApp.ActiveDocument.SetVariable("CTAB", "Layout1");&lt;/LI-CODE&gt;</description>
      <pubDate>Fri, 17 Jun 2022 16:28:30 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/switch-layout-using-com-api/m-p/11242261#M12670</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2022-06-17T16:28:30Z</dc:date>
    </item>
    <item>
      <title>Re: Switch Layout using COM API</title>
      <link>https://forums.autodesk.com/t5/net-forum/switch-layout-using-com-api/m-p/11248259#M12671</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/2034868"&gt;@marcin.sachs&lt;/a&gt;&amp;nbsp; and &lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/109424"&gt;@_gile&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you both of you, using both the method I can switch the layout.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 21 Jun 2022 10:04:44 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/switch-layout-using-com-api/m-p/11248259#M12671</guid>
      <dc:creator>nishad.dhapre</dc:creator>
      <dc:date>2022-06-21T10:04:44Z</dc:date>
    </item>
  </channel>
</rss>

