<?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 Delete all layouts in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/delete-all-layouts/m-p/11912484#M9086</link>
    <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;i would like to delete all layouts. I tested these two method.&lt;/P&gt;&lt;P&gt;I have problem with LayoutManager becuase delete is very slow.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;If DWG is complex and has for example 20 pages it toos lots of time (because function still swap page by page).&lt;/P&gt;&lt;P&gt;This second method is much more fastert but i will getting error if i delete all pages (even if i before created one which i jump over).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;i know that layer manager delete all dependencies but is there any way how to delete all old layouts faster?&lt;/P&gt;&lt;P&gt;(in second method my plan was call purge function after that)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;   private static bool DeleteAllLayouts()
        {
            Document acDoc = Application.DocumentManager.MdiActiveDocument;
            Editor ed = acDoc.Editor;
            using (DocumentLock LockDoc = acDoc.LockDocument())
            {
                using (Database db = acDoc.Database)
                {




                    // metode 1

                    using (Transaction tr = db.TransactionManager.StartTransaction())
                    {
                        using (DBDictionary layoutDict = (DBDictionary)db.LayoutDictionaryId.GetObject(OpenMode.ForWrite))
                        {
                            LayoutManager acLayoutMgr = LayoutManager.Current;
                            acLayoutMgr.CreateLayout("LayoutXX");
                            foreach (DBDictionaryEntry entry in layoutDict)
                            {
                                string layoutName = entry.Key.ToUpper();
                                if (layoutName != "MODEL" &amp;amp;&amp;amp; layoutName != "LAYOUTXX")
                                {
                                    acLayoutMgr.DeleteLayout(layoutName);
                                }
                            }
                            acLayoutMgr.RenameLayout("LayoutXX", "Layout1");
                            acLayoutMgr.CurrentLayout = "Model";
                            tr.Commit();
                            acLayoutMgr.Dispose();
                        }
                    }


                    // metode 2
                    using (Transaction tr = db.TransactionManager.StartTransaction())
                    {
                        DBDictionary layoutsEx = tr.GetObject(db.LayoutDictionaryId, OpenMode.ForRead) as DBDictionary;
                        BlockTable blkTbl = tr.GetObject(db.BlockTableId, OpenMode.ForWrite) as BlockTable;

                        using (BlockTableRecord blkBlkRec = new BlockTableRecord())
                        {
                            int layoutCount = layoutsEx.Count - 1;

                            blkBlkRec.Name = "*Paper_Space" + layoutCount.ToString();
                            blkTbl.Add(blkBlkRec);
                            tr.AddNewlyCreatedDBObject(blkBlkRec, true);

                            DBDictionary layouts = tr.GetObject(db.LayoutDictionaryId, OpenMode.ForWrite) as DBDictionary;

                            using (Layout lay = new Layout())
                            {
                                lay.LayoutName = "LayoutXX";
                                lay.AddToLayoutDictionary(db, blkBlkRec.ObjectId);
                                tr.AddNewlyCreatedDBObject(lay, true);
                            }
                        }
                        tr.Commit();
                    }

                    using (Transaction tr = db.TransactionManager.StartTransaction())
                    {
                        using (DBDictionary layoutDict = tr.GetObject(db.LayoutDictionaryId, OpenMode.ForRead) as DBDictionary)
                        {
                            foreach (DBDictionaryEntry de in layoutDict)
                            {
                                Layout layout = (Layout)tr.GetObject(de.Value, OpenMode.ForWrite);
                                string layoutName = de.Key;
                                if (layoutName != "Model" &amp;amp;&amp;amp; layoutName != "LayoutXX")
                                {
                                    layout.Erase();
                                }
                            }
                            tr.Commit();
                            ed.Regen();
                        }
                    }

                }
            }
            return true;
        }&lt;/LI-CODE&gt;</description>
    <pubDate>Fri, 21 Apr 2023 12:20:10 GMT</pubDate>
    <dc:creator>BestFriendCZ</dc:creator>
    <dc:date>2023-04-21T12:20:10Z</dc:date>
    <item>
      <title>Delete all layouts</title>
      <link>https://forums.autodesk.com/t5/net-forum/delete-all-layouts/m-p/11912484#M9086</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;i would like to delete all layouts. I tested these two method.&lt;/P&gt;&lt;P&gt;I have problem with LayoutManager becuase delete is very slow.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;If DWG is complex and has for example 20 pages it toos lots of time (because function still swap page by page).&lt;/P&gt;&lt;P&gt;This second method is much more fastert but i will getting error if i delete all pages (even if i before created one which i jump over).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;i know that layer manager delete all dependencies but is there any way how to delete all old layouts faster?&lt;/P&gt;&lt;P&gt;(in second method my plan was call purge function after that)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;   private static bool DeleteAllLayouts()
        {
            Document acDoc = Application.DocumentManager.MdiActiveDocument;
            Editor ed = acDoc.Editor;
            using (DocumentLock LockDoc = acDoc.LockDocument())
            {
                using (Database db = acDoc.Database)
                {




                    // metode 1

                    using (Transaction tr = db.TransactionManager.StartTransaction())
                    {
                        using (DBDictionary layoutDict = (DBDictionary)db.LayoutDictionaryId.GetObject(OpenMode.ForWrite))
                        {
                            LayoutManager acLayoutMgr = LayoutManager.Current;
                            acLayoutMgr.CreateLayout("LayoutXX");
                            foreach (DBDictionaryEntry entry in layoutDict)
                            {
                                string layoutName = entry.Key.ToUpper();
                                if (layoutName != "MODEL" &amp;amp;&amp;amp; layoutName != "LAYOUTXX")
                                {
                                    acLayoutMgr.DeleteLayout(layoutName);
                                }
                            }
                            acLayoutMgr.RenameLayout("LayoutXX", "Layout1");
                            acLayoutMgr.CurrentLayout = "Model";
                            tr.Commit();
                            acLayoutMgr.Dispose();
                        }
                    }


                    // metode 2
                    using (Transaction tr = db.TransactionManager.StartTransaction())
                    {
                        DBDictionary layoutsEx = tr.GetObject(db.LayoutDictionaryId, OpenMode.ForRead) as DBDictionary;
                        BlockTable blkTbl = tr.GetObject(db.BlockTableId, OpenMode.ForWrite) as BlockTable;

                        using (BlockTableRecord blkBlkRec = new BlockTableRecord())
                        {
                            int layoutCount = layoutsEx.Count - 1;

                            blkBlkRec.Name = "*Paper_Space" + layoutCount.ToString();
                            blkTbl.Add(blkBlkRec);
                            tr.AddNewlyCreatedDBObject(blkBlkRec, true);

                            DBDictionary layouts = tr.GetObject(db.LayoutDictionaryId, OpenMode.ForWrite) as DBDictionary;

                            using (Layout lay = new Layout())
                            {
                                lay.LayoutName = "LayoutXX";
                                lay.AddToLayoutDictionary(db, blkBlkRec.ObjectId);
                                tr.AddNewlyCreatedDBObject(lay, true);
                            }
                        }
                        tr.Commit();
                    }

                    using (Transaction tr = db.TransactionManager.StartTransaction())
                    {
                        using (DBDictionary layoutDict = tr.GetObject(db.LayoutDictionaryId, OpenMode.ForRead) as DBDictionary)
                        {
                            foreach (DBDictionaryEntry de in layoutDict)
                            {
                                Layout layout = (Layout)tr.GetObject(de.Value, OpenMode.ForWrite);
                                string layoutName = de.Key;
                                if (layoutName != "Model" &amp;amp;&amp;amp; layoutName != "LayoutXX")
                                {
                                    layout.Erase();
                                }
                            }
                            tr.Commit();
                            ed.Regen();
                        }
                    }

                }
            }
            return true;
        }&lt;/LI-CODE&gt;</description>
      <pubDate>Fri, 21 Apr 2023 12:20:10 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/delete-all-layouts/m-p/11912484#M9086</guid>
      <dc:creator>BestFriendCZ</dc:creator>
      <dc:date>2023-04-21T12:20:10Z</dc:date>
    </item>
    <item>
      <title>Re: Delete all layouts</title>
      <link>https://forums.autodesk.com/t5/net-forum/delete-all-layouts/m-p/11912842#M9087</link>
      <description>&lt;P&gt;The following example has been tested on a drawing with 75 complex layouts. It appears to me that you don't need to create a layout to keep. The layout manager will create a new layout if you delete all of them.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="visual-basic"&gt;&amp;lt;CommandMethod("LayoutDeleteAll")&amp;gt;
Public Sub CmdLayoutDeleteAll()
   GetCurrent() 'CommandBase - Sets Private aDoc, db, and ed 

   Dim lm As LayoutManager = LayoutManager.Current

   Using tr As Transaction = db.TransactionManager.StartTransaction
      Dim dict As DBDictionary = tr.GetObject(db.LayoutDictionaryId, OpenMode.ForRead)
      For Each entry As DBDictionaryEntry In dict
         Dim name As String = entry.Key.ToUpper
         If name &amp;lt;&amp;gt; "MODEL" Then
            lm.DeleteLayout(name)
         End If
      Next
      tr.Commit()
   End Using
End Sub&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 21 Apr 2023 14:25:35 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/delete-all-layouts/m-p/11912842#M9087</guid>
      <dc:creator>hippe013</dc:creator>
      <dc:date>2023-04-21T14:25:35Z</dc:date>
    </item>
    <item>
      <title>Re: Delete all layouts</title>
      <link>https://forums.autodesk.com/t5/net-forum/delete-all-layouts/m-p/11912912#M9088</link>
      <description>&lt;P&gt;You are correct that I don’t have to create a new layout this way…. but your sample is exactly my method 1.&lt;/P&gt;&lt;P&gt;I just tested (your VB code) and I have problem with this command (maybe it depends on complexity of model in model space)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;lm.DeleteLayout(name)&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;every time when it is call this command model space behaves like refresh and there is delay 1-2s… if there is simply model in model space that this function is fast&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 21 Apr 2023 14:50:27 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/delete-all-layouts/m-p/11912912#M9088</guid>
      <dc:creator>BestFriendCZ</dc:creator>
      <dc:date>2023-04-21T14:50:27Z</dc:date>
    </item>
    <item>
      <title>Re: Delete all layouts</title>
      <link>https://forums.autodesk.com/t5/net-forum/delete-all-layouts/m-p/11912949#M9089</link>
      <description>&lt;P&gt;&lt;div class="lia-vid-container video-embed-center"&gt;&lt;div id="lia-vid-6325511224112w996h540r999" class="lia-video-brightcove-player-container"&gt;&lt;video-js data-video-id="6325511224112" data-account="6057940548001" data-player="default" data-embed="default" class="vjs-fluid" controls="" data-application-id="" style="width: 100%; height: 100%;"&gt;&lt;/video-js&gt;&lt;/div&gt;&lt;script src="https://players.brightcove.net/6057940548001/default_default/index.min.js"&gt;&lt;/script&gt;&lt;script&gt;(function() {  var wrapper = document.getElementById('lia-vid-6325511224112w996h540r999');  var videoEl = wrapper ? wrapper.querySelector('video-js') : null;  if (videoEl) {     if (window.videojs) {       window.videojs(videoEl).ready(function() {         this.on('loadedmetadata', function() {           this.el().querySelectorAll('.vjs-load-progress div[data-start]').forEach(function(bar) {             bar.setAttribute('role', 'presentation');             bar.setAttribute('aria-hidden', 'true');           });         });       });     }  }})();&lt;/script&gt;&lt;a class="video-embed-link" href="https://forums.autodesk.com/t5/video/gallerypage/video-id/6325511224112"&gt;(view in My Videos)&lt;/a&gt;&lt;/div&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Like you can see there is take lots of the time and pc is powerful for CAD purpose&lt;/P&gt;</description>
      <pubDate>Fri, 21 Apr 2023 15:03:49 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/delete-all-layouts/m-p/11912949#M9089</guid>
      <dc:creator>BestFriendCZ</dc:creator>
      <dc:date>2023-04-21T15:03:49Z</dc:date>
    </item>
    <item>
      <title>Re: Delete all layouts</title>
      <link>https://forums.autodesk.com/t5/net-forum/delete-all-layouts/m-p/11913348#M9090</link>
      <description>&lt;P&gt;I see what you mean. I guess I don't know. My model space wasn't too complex, but the layouts were and there were 75 of them. The command executed very quickly.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 21 Apr 2023 17:36:43 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/delete-all-layouts/m-p/11913348#M9090</guid>
      <dc:creator>hippe013</dc:creator>
      <dc:date>2023-04-21T17:36:43Z</dc:date>
    </item>
  </channel>
</rss>

