<?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: multiple layout export to separate CAD files using c# in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/multiple-layout-export-to-separate-cad-files-using-c/m-p/10602496#M16766</link>
    <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any has ideal for this error ? Thanks you&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="ChuongHo_0-1630922157289.png" style="width: 400px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/961736i79E3A5837C46483A/image-size/medium?v=v2&amp;amp;px=400" role="button" title="ChuongHo_0-1630922157289.png" alt="ChuongHo_0-1630922157289.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 06 Sep 2021 09:56:52 GMT</pubDate>
    <dc:creator>Chuong.Ho</dc:creator>
    <dc:date>2021-09-06T09:56:52Z</dc:date>
    <item>
      <title>multiple layout export to separate CAD files using c#</title>
      <link>https://forums.autodesk.com/t5/net-forum/multiple-layout-export-to-separate-cad-files-using-c/m-p/10245117#M16760</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;I am trying to run the below code which I got from theswamp.org website but its not working, kindly can anyone&amp;nbsp; highlight the issue and try to solve it.&lt;/P&gt;&lt;P&gt;&lt;A href="https://www.theswamp.org/index.php?topic=44472.0" target="_blank"&gt;EXPORTLAYOUTS command example (theswamp.org)&lt;/A&gt;&lt;/P&gt;&lt;P&gt;[CommandMethod("EXPORTLAYOUTS")]&lt;BR /&gt;public static void ExportLayoutsCommand()&lt;BR /&gt;{&lt;BR /&gt;var doc = Application.DocumentManager.MdiActiveDocument;&lt;BR /&gt;var db = doc.Database;&lt;BR /&gt;var editor = doc.Editor;&lt;BR /&gt;try&lt;BR /&gt;{&lt;/P&gt;&lt;P&gt;// check if drawing saved or not&lt;BR /&gt;if ((short)Application.GetSystemVariable("DWGTITLED") == 0)&lt;BR /&gt;{&lt;BR /&gt;editor.WriteMessage("\nCommand cannot be used on an unnamed drawing");&lt;BR /&gt;return;&lt;BR /&gt;}&lt;BR /&gt;string format =Path.Combine(Path.GetDirectoryName(doc.Name),Path.GetFileNameWithoutExtension(doc.Name))+ "_{0}.dwg";&lt;BR /&gt;editor.WriteMessage(format);&lt;BR /&gt;string[] names = null;&lt;BR /&gt;using (Transaction tr = doc.TransactionManager.StartTransaction())&lt;BR /&gt;{&lt;BR /&gt;// Get the localized name of the model tab:&lt;BR /&gt;BlockTableRecord btr = SymbolUtilityServices.GetBlockModelSpaceId(db).GetObject(OpenMode.ForRead) as BlockTableRecord;&lt;BR /&gt;Layout layout = btr.LayoutId.GetObject(OpenMode.ForRead) as Layout;&lt;BR /&gt;string model = layout.LayoutName;&lt;BR /&gt;// Open the Layout dictionary:&lt;BR /&gt;IDictionary layouts = db.LayoutDictionaryId.GetObject(OpenMode.ForRead) as IDictionary;&lt;BR /&gt;// Get the names and ids of all paper space layouts into a list:&lt;BR /&gt;names = layouts.Keys.Cast&amp;lt;string&amp;gt;().Where(name =&amp;gt; name != model).ToArray();&lt;BR /&gt;tr.Commit();&lt;BR /&gt;}&lt;BR /&gt;int cmdecho = 0;&lt;BR /&gt;#if DEBUG&lt;BR /&gt;cmdecho = 1;&lt;BR /&gt;#endif&lt;BR /&gt;using (new ManagedSystemVariable("CMDECHO", cmdecho))&lt;BR /&gt;using (new ManagedSystemVariable("CMDDIA", 0))&lt;BR /&gt;using (new ManagedSystemVariable("FILEDIA", 0))&lt;BR /&gt;using (new ManagedSystemVariable("CTAB"))&lt;BR /&gt;{&lt;BR /&gt;foreach (string name in names)&lt;BR /&gt;{&lt;BR /&gt;string filename = string.Format(format, name);&lt;BR /&gt;editor.WriteMessage("\nExporting {0}\n", filename);&lt;BR /&gt;Application.SetSystemVariable("CTAB", name);&lt;BR /&gt;editor.Command("._EXPORTLAYOUT", filename);&lt;/P&gt;&lt;P&gt;}&lt;BR /&gt;}&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;public static class EditorInputExtensionMethods&lt;BR /&gt;{&lt;BR /&gt;public static PromptStatus Command(this Editor editor, params object[] args)&lt;BR /&gt;{&lt;BR /&gt;if (editor == null)throw new ArgumentNullException("editor");&lt;BR /&gt;return runCommand(editor, args);&lt;BR /&gt;}&lt;BR /&gt;static Func&amp;lt;Editor, object[], PromptStatus&amp;gt; runCommand = GenerateRunCommand();&lt;BR /&gt;static Func&amp;lt;Editor, object[], PromptStatus&amp;gt; GenerateRunCommand()&lt;BR /&gt;{&lt;BR /&gt;MethodInfo method = typeof(Editor).GetMethod("RunCommand",&lt;BR /&gt;BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);&lt;BR /&gt;var instance = Expression.Parameter(typeof(Editor), "instance");&lt;BR /&gt;var args = Expression.Parameter(typeof(object[]), "args");&lt;BR /&gt;return Expression.Lambda&amp;lt;Func&amp;lt;Editor, object[], PromptStatus&amp;gt;&amp;gt;(Expression.Call(instance, method, args), instance, args).Compile();&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;/// &amp;lt;summary&amp;gt;&lt;BR /&gt;/// Automates saving/changing/restoring system variables&lt;BR /&gt;/// &amp;lt;/summary&amp;gt;&lt;BR /&gt;public class ManagedSystemVariable : IDisposable&lt;BR /&gt;{&lt;BR /&gt;string name /*= null*/;&lt;BR /&gt;object oldval /*= null*/;&lt;BR /&gt;public ManagedSystemVariable(string name, object value): this(name)&lt;BR /&gt;{&lt;BR /&gt;Application.SetSystemVariable(name, value);&lt;BR /&gt;}&lt;BR /&gt;public ManagedSystemVariable(string name)&lt;BR /&gt;{&lt;BR /&gt;if (string.IsNullOrWhiteSpace(name))throw new ArgumentException("name");&lt;BR /&gt;this.name = name;&lt;BR /&gt;this.oldval = Application.GetSystemVariable(name);&lt;BR /&gt;}&lt;BR /&gt;public void Dispose()&lt;BR /&gt;{&lt;BR /&gt;if (oldval != null)&lt;BR /&gt;{&lt;BR /&gt;object temp = oldval;&lt;BR /&gt;oldval = null;&lt;BR /&gt;Application.SetSystemVariable(name, temp);&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;catch (System.Exception ex)&lt;BR /&gt;{&lt;BR /&gt;#if DEBUG&lt;BR /&gt;editor.WriteMessage(ex.ToString());&lt;BR /&gt;#else&lt;BR /&gt;throw ex;&lt;BR /&gt;#endif&lt;BR /&gt;}&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 16 Apr 2021 17:45:29 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/multiple-layout-export-to-separate-cad-files-using-c/m-p/10245117#M16760</guid>
      <dc:creator>Ahmed_204</dc:creator>
      <dc:date>2021-04-16T17:45:29Z</dc:date>
    </item>
    <item>
      <title>Re: multiple layout export to separate CAD files using c#</title>
      <link>https://forums.autodesk.com/t5/net-forum/multiple-layout-export-to-separate-cad-files-using-c/m-p/10246246#M16761</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/2457429"&gt;@Ahmed_204&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;i tested&amp;nbsp;&lt;EM&gt;EXPORTLAYOUTS2&lt;/EM&gt; and it works fine, what errors did you get?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Linq.Expressions;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Runtime;

// requires a reference to AcExportLayout.dll:
using AcExportLayout = Autodesk.AutoCAD.ExportLayout;

namespace ClassLibrary1
{
    public static class ExportLayoutsCommands
    {
        /// &amp;lt;summary&amp;gt;
        /// Automates the EXPORTLAYOUT command to export 
        /// all paper space layouts to .DWG files.
        /// 
        /// In this example, we export each layout to
        /// a drawing file in the same location as the
        /// current drawing, wherein each file has the
        /// name "&amp;lt;dwgname&amp;gt;_&amp;lt;layoutname&amp;gt;.dwg".
        /// 
        /// This is not a functionally-complete example:
        /// 
        /// No checking is done to see if any of the 
        /// files already exist, and existing files 
        /// are overwritten without warning or error.
        /// 
        /// No checking is done to detect if an existing
        /// file exists and is in-use by another user, or 
        /// cannot be overwritten for any other reason.
        /// 
        /// No checking is done to ensure that the user
        /// has sufficient rights to write files in the
        /// target location.
        /// 
        /// You can and should deal with any or all of
        /// the above as per your own requirements.
        /// 
        /// &amp;lt;/summary&amp;gt;

        

        /// &amp;lt;summary&amp;gt;
        /// 
        /// Doesn't use the command line, requires AutoCAD R12 
        /// or later and a reference to AcExportLayout.dll:
        /// 
        /// This version can be used from the application context, 
        /// which can make it easier to use in a batch process that
        /// exports layouts of many files.
        /// 
        /// The example also shows how to use the AcExportLayout
        /// component to export a layout to an in-memory Database
        /// without creating a drawing file.
        /// 
        /// &amp;lt;/summary&amp;gt;

        [CommandMethod("EXPORTLAYOUTS2", CommandFlags.Session)]
        public static void ExportLayouts2()
        {
            var doc = Application.DocumentManager.MdiActiveDocument;
            var db = doc.Database;
            var editor = doc.Editor;
            try
            {
                if ((short)Application.GetSystemVariable("DWGTITLED") == 0)
                {
                    editor.WriteMessage(
                       "\nCommand cannot be used on an unnamed drawing"
                    );
                    return;
                }
                string format =
                   Path.Combine(
                      Path.GetDirectoryName(doc.Name),
                      Path.GetFileNameWithoutExtension(doc.Name))
                   + "_{0}.dwg";

                Dictionary&amp;lt;string, ObjectId&amp;gt; layouts = null;

                using (doc.LockDocument())
                {
                    using (Transaction tr = doc.TransactionManager.StartTransaction())
                    {
                        // Get the localized name of the model tab:
                        BlockTableRecord btr = (BlockTableRecord)
                           SymbolUtilityServices.GetBlockModelSpaceId(db)
                              .GetObject(OpenMode.ForRead);
                        Layout layout = (Layout)
                           btr.LayoutId.GetObject(OpenMode.ForRead);
                        string model = layout.LayoutName;
                        // Open the Layout dictionary:
                        IDictionary layoutDictionary = (IDictionary)
                           db.LayoutDictionaryId.GetObject(OpenMode.ForRead);
                        // Get the names and ids of all paper space layouts 
                        // into a Dictionary&amp;lt;string,ObjectId&amp;gt;:
                        layouts = layoutDictionary.Cast&amp;lt;DictionaryEntry&amp;gt;()
                           .Where(e =&amp;gt; ((string)e.Key) != model)
                           .ToDictionary(
                              e =&amp;gt; (string)e.Key,
                              e =&amp;gt; (ObjectId)e.Value);

                        tr.Commit();
                    }

                    /// Get the export layout 'engine':
                    Autodesk.AutoCAD.ExportLayout.Engine engine =
                       Autodesk.AutoCAD.ExportLayout.Engine.Instance();

                    using (new ManagedSystemVariable("CTAB"))
                    {
                        foreach (var entry in layouts)
                        {
                            string filename = string.Format(format, entry.Key);
                            editor.WriteMessage("\nExporting {0} =&amp;gt; {1}\n", entry.Key, filename);
                            Application.SetSystemVariable("CTAB", entry.Key);
                            using (Database database = engine.ExportLayout(entry.Value))
                            {
                                if (engine.EngineStatus == AcExportLayout.ErrorStatus.Succeeded)
                                {
                                    database.SaveAs(filename, DwgVersion.Newest);
                                }
                                else
                                {
                                    editor.WriteMessage("\nExportLayout failed: ",
                                       engine.EngineStatus.ToString());
                                    break;
                                }
                            }
                        }
                    }
                }
            }
            catch (System.Exception ex)
            {
#if DEBUG
            editor.WriteMessage( ex.ToString() );
#else
                throw ex;
#endif
            }
        }
    }

    /// &amp;lt;summary&amp;gt;
    /// Automates saving/changing/restoring system variables
    /// &amp;lt;/summary&amp;gt;
    public class ManagedSystemVariable : IDisposable
    {
        string name = null;
        object oldval = null;

        public ManagedSystemVariable(string name, object value)
           : this(name)
        {
            Application.SetSystemVariable(name, value);
        }

        public ManagedSystemVariable(string name)
        {
            if (string.IsNullOrWhiteSpace(name))
                throw new ArgumentException("name");
            this.name = name;
            this.oldval = Application.GetSystemVariable(name);
        }

        public void Dispose()
        {
            if (oldval != null)
            {
                object temp = oldval;
                oldval = null;
                Application.SetSystemVariable(name, temp);
            }
        }
    }

}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 17 Apr 2021 06:19:12 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/multiple-layout-export-to-separate-cad-files-using-c/m-p/10246246#M16761</guid>
      <dc:creator>essam-salah</dc:creator>
      <dc:date>2021-04-17T06:19:12Z</dc:date>
    </item>
    <item>
      <title>Re: multiple layout export to separate CAD files using c#</title>
      <link>https://forums.autodesk.com/t5/net-forum/multiple-layout-export-to-separate-cad-files-using-c/m-p/10246248#M16762</link>
      <description>&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/2457429"&gt;@Ahmed_204&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;you have to reference&amp;nbsp;&lt;STRONG&gt;&lt;EM&gt;AcExportLayout.dll&lt;/EM&gt;&lt;/STRONG&gt; you found it in the same location of &lt;EM&gt;acdbmgd.dll&lt;/EM&gt;.&lt;/P&gt;</description>
      <pubDate>Sat, 17 Apr 2021 06:20:37 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/multiple-layout-export-to-separate-cad-files-using-c/m-p/10246248#M16762</guid>
      <dc:creator>essam-salah</dc:creator>
      <dc:date>2021-04-17T06:20:37Z</dc:date>
    </item>
    <item>
      <title>Re: multiple layout export to separate CAD files using c#</title>
      <link>https://forums.autodesk.com/t5/net-forum/multiple-layout-export-to-separate-cad-files-using-c/m-p/10246684#M16763</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/3650456"&gt;@essam-salah&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;After I referenced&amp;nbsp;&lt;STRONG&gt;&lt;EM&gt;AcExportLayout.dll , &lt;/EM&gt;&lt;/STRONG&gt;Exportlayout2 worked fine but my issue now while trying to use EXPORTLAYOUTS I am receiving the below error.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;EM&gt;._EXPORTLAYOUT Autodesk.AutoCAD.Runtime.Exception: eInvalidInput&lt;BR /&gt;at Autodesk.AutoCAD.ApplicationServices.Core.Application.SetSystemVariable(String name, Object value)&lt;BR /&gt;at Export_Layout.ManagedSystemVariable.Dispose() in H:\AutoCAD Building Add-ins with C#_LinkedIn Course\My Autocad Projects\Export Layouts\Export_Layout\myCommands.cs:line 356&lt;BR /&gt;at Export_Layout.MyCommands.ExportLayoutsCommand() in H:\AutoCAD Building Add-ins with C#_LinkedIn Course\My Autocad Projects\Export Layouts\Export_Layout\myCommands.cs:line 141&lt;/EM&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;EM&gt;Thanks for your support.&lt;/EM&gt;&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 17 Apr 2021 12:59:41 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/multiple-layout-export-to-separate-cad-files-using-c/m-p/10246684#M16763</guid>
      <dc:creator>Ahmed_204</dc:creator>
      <dc:date>2021-04-17T12:59:41Z</dc:date>
    </item>
    <item>
      <title>Re: multiple layout export to separate CAD files using c#</title>
      <link>https://forums.autodesk.com/t5/net-forum/multiple-layout-export-to-separate-cad-files-using-c/m-p/10246842#M16764</link>
      <description>&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/2457429"&gt;@Ahmed_204&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;yes it gives the same error, and the problem is in line&lt;STRONG&gt;&lt;EM&gt;&amp;nbsp;editor.Command("._EXPORTLAYOUT", filename);&lt;/EM&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;and i think it's a common problem in autocad sending comman with parameters.&lt;/P&gt;</description>
      <pubDate>Sat, 17 Apr 2021 14:56:48 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/multiple-layout-export-to-separate-cad-files-using-c/m-p/10246842#M16764</guid>
      <dc:creator>essam-salah</dc:creator>
      <dc:date>2021-04-17T14:56:48Z</dc:date>
    </item>
    <item>
      <title>Re: multiple layout export to separate CAD files using c#</title>
      <link>https://forums.autodesk.com/t5/net-forum/multiple-layout-export-to-separate-cad-files-using-c/m-p/10251185#M16765</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&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;Do you know any possible solution for the above error ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for your support.&lt;/P&gt;</description>
      <pubDate>Mon, 19 Apr 2021 17:12:44 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/multiple-layout-export-to-separate-cad-files-using-c/m-p/10251185#M16765</guid>
      <dc:creator>Ahmed_204</dc:creator>
      <dc:date>2021-04-19T17:12:44Z</dc:date>
    </item>
    <item>
      <title>Re: multiple layout export to separate CAD files using c#</title>
      <link>https://forums.autodesk.com/t5/net-forum/multiple-layout-export-to-separate-cad-files-using-c/m-p/10602496#M16766</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any has ideal for this error ? Thanks you&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="ChuongHo_0-1630922157289.png" style="width: 400px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/961736i79E3A5837C46483A/image-size/medium?v=v2&amp;amp;px=400" role="button" title="ChuongHo_0-1630922157289.png" alt="ChuongHo_0-1630922157289.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 06 Sep 2021 09:56:52 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/multiple-layout-export-to-separate-cad-files-using-c/m-p/10602496#M16766</guid>
      <dc:creator>Chuong.Ho</dc:creator>
      <dc:date>2021-09-06T09:56:52Z</dc:date>
    </item>
    <item>
      <title>Re: multiple layout export to separate CAD files using c#</title>
      <link>https://forums.autodesk.com/t5/net-forum/multiple-layout-export-to-separate-cad-files-using-c/m-p/10721319#M16767</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/2457429"&gt;@Ahmed_204&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;I am trying to run the below code which I got from theswamp.org website but its not working, kindly can anyone&amp;nbsp; highlight the issue and try to&amp;nbsp;&lt;A href="https://albaqueen.com%20" target="_blank" rel="noopener"&gt;밤알바&lt;/A&gt; solve it.&lt;/P&gt;&lt;P&gt;&lt;A href="https://www.theswamp.org/index.php?topic=44472.0" target="_blank" rel="noopener"&gt;EXPORTLAYOUTS command example (theswamp.org)&lt;/A&gt;&lt;/P&gt;&lt;P&gt;[CommandMethod("EXPORTLAYOUTS")]&lt;BR /&gt;public static void ExportLayoutsCommand()&lt;BR /&gt;{&lt;BR /&gt;var doc = Application.DocumentManager.MdiActiveDocument;&lt;BR /&gt;var db = doc.Database;&lt;BR /&gt;var editor = doc.Editor;&lt;BR /&gt;try&lt;BR /&gt;{&lt;/P&gt;&lt;P&gt;// check if drawing saved or not&lt;BR /&gt;if ((short)Application.GetSystemVariable("DWGTITLED") == 0)&lt;BR /&gt;{&lt;BR /&gt;editor.WriteMessage("\nCommand cannot be used on an unnamed drawing");&lt;BR /&gt;return;&lt;BR /&gt;}&lt;BR /&gt;string format =Path.Combine(Path.GetDirectoryName(doc.Name),Path.GetFileNameWithoutExtension(doc.Name))+ "_{0}.dwg";&lt;BR /&gt;editor.WriteMessage(format);&lt;BR /&gt;string[] names = null;&lt;BR /&gt;using (Transaction tr = doc.TransactionManager.StartTransaction())&lt;BR /&gt;{&lt;BR /&gt;// Get the localized name of the model tab:&lt;BR /&gt;BlockTableRecord btr = SymbolUtilityServices.GetBlockModelSpaceId(db).GetObject(OpenMode.ForRead) as BlockTableRecord;&lt;BR /&gt;Layout layout = btr.LayoutId.GetObject(OpenMode.ForRead) as Layout;&lt;BR /&gt;string model = layout.LayoutName;&lt;BR /&gt;// Open the Layout dictionary:&lt;BR /&gt;IDictionary layouts = db.LayoutDictionaryId.GetObject(OpenMode.ForRead) as IDictionary;&lt;BR /&gt;// Get the names and ids of all paper space layouts into a list:&lt;BR /&gt;names = layouts.Keys.Cast&amp;lt;string&amp;gt;().Where(name =&amp;gt; name != model).ToArray();&lt;BR /&gt;tr.Commit();&lt;BR /&gt;}&lt;BR /&gt;int cmdecho = 0;&lt;BR /&gt;#if DEBUG&lt;BR /&gt;cmdecho = 1;&lt;BR /&gt;#endif&lt;BR /&gt;using (new ManagedSystemVariable("CMDECHO", cmdecho))&lt;BR /&gt;using (new ManagedSystemVariable("CMDDIA", 0))&lt;BR /&gt;using (new ManagedSystemVariable("FILEDIA", 0))&lt;BR /&gt;using (new ManagedSystemVariable("CTAB"))&lt;BR /&gt;{&lt;BR /&gt;foreach (string name in names)&lt;BR /&gt;{&lt;BR /&gt;string filename = string.Format(format, name);&lt;BR /&gt;editor.WriteMessage("\nExporting {0}\n", filename);&lt;BR /&gt;Application.SetSystemVariable("CTAB", name);&lt;BR /&gt;editor.Command("._EXPORTLAYOUT", filename);&lt;/P&gt;&lt;P&gt;}&lt;BR /&gt;}&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;public static class EditorInputExtensionMethods&lt;BR /&gt;{&lt;BR /&gt;public static PromptStatus Command(this Editor editor, params object[] args)&lt;BR /&gt;{&lt;BR /&gt;if (editor == null)throw new ArgumentNullException("editor");&lt;BR /&gt;return runCommand(editor, args);&lt;BR /&gt;}&lt;BR /&gt;static Func&amp;lt;Editor, object[], PromptStatus&amp;gt; runCommand = GenerateRunCommand();&lt;BR /&gt;static Func&amp;lt;Editor, object[], PromptStatus&amp;gt; GenerateRunCommand()&lt;BR /&gt;{&lt;BR /&gt;MethodInfo method = typeof(Editor).GetMethod("RunCommand",&lt;BR /&gt;BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);&lt;BR /&gt;var instance = Expression.Parameter(typeof(Editor), "instance");&lt;BR /&gt;var args = Expression.Parameter(typeof(object[]), "args");&lt;BR /&gt;return Expression.Lambda&amp;lt;Func&amp;lt;Editor, object[], PromptStatus&amp;gt;&amp;gt;(Expression.Call(instance, method, args), instance, args).Compile();&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;/// &amp;lt;summary&amp;gt;&lt;BR /&gt;/// Automates saving/changing/restoring system variables&lt;BR /&gt;/// &amp;lt;/summary&amp;gt;&lt;BR /&gt;public class ManagedSystemVariable : IDisposable&lt;BR /&gt;{&lt;BR /&gt;string name /*= null*/;&lt;BR /&gt;object oldval /*= null*/;&lt;BR /&gt;public ManagedSystemVariable(string name, object value): this(name)&lt;BR /&gt;{&lt;BR /&gt;Application.SetSystemVariable(name, value);&lt;BR /&gt;}&lt;BR /&gt;public ManagedSystemVariable(string name)&lt;BR /&gt;{&lt;BR /&gt;if (string.IsNullOrWhiteSpace(name))throw new ArgumentException("name");&lt;BR /&gt;this.name = name;&lt;BR /&gt;this.oldval = Application.GetSystemVariable(name);&lt;BR /&gt;}&lt;BR /&gt;public void Dispose()&lt;BR /&gt;{&lt;BR /&gt;if (oldval != null)&lt;BR /&gt;{&lt;BR /&gt;object temp = oldval;&lt;BR /&gt;oldval = null;&lt;BR /&gt;Application.SetSystemVariable(name, temp);&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;catch (System.Exception ex)&lt;BR /&gt;{&lt;BR /&gt;#if DEBUG&lt;BR /&gt;editor.WriteMessage(ex.ToString());&lt;BR /&gt;#else&lt;BR /&gt;throw ex;&lt;BR /&gt;#endif&lt;BR /&gt;}&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;I was facing the same issue could you please let me know which solution you have found and what is the best one?actually i also facing the same issue.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 28 Oct 2021 20:04:59 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/multiple-layout-export-to-separate-cad-files-using-c/m-p/10721319#M16767</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2021-10-28T20:04:59Z</dc:date>
    </item>
    <item>
      <title>Re: multiple layout export to separate CAD files using c#</title>
      <link>https://forums.autodesk.com/t5/net-forum/multiple-layout-export-to-separate-cad-files-using-c/m-p/10722064#M16768</link>
      <description>&lt;P&gt;I have spent several weeks researching it and there is no solution to this problem&lt;/P&gt;</description>
      <pubDate>Fri, 29 Oct 2021 05:08:08 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/multiple-layout-export-to-separate-cad-files-using-c/m-p/10722064#M16768</guid>
      <dc:creator>Chuong.Ho</dc:creator>
      <dc:date>2021-10-29T05:08:08Z</dc:date>
    </item>
  </channel>
</rss>

