<?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 Rename Layout in an external dwg file using autocad .net c# in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/rename-layout-in-an-external-dwg-file-using-autocad-net-c/m-p/8882540#M21951</link>
    <description>&lt;P&gt;Hello,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I can rename a layout of an open file using the following code :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt; static public void renamelayoutName(string last_name, string new_name)
        {

            Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
            Database db = doc.Database;
            Editor ed = doc.Editor;

            using (doc.LockDocument())
            {
                //get the Layout name

                bool bUpdate = false;

                using (Transaction tr = db.TransactionManager.StartTransaction())
                {

                    DBDictionary dLayouts = tr.GetObject(db.LayoutDictionaryId, OpenMode.ForRead) as DBDictionary;

                    if (dLayouts.Contains(last_name))
                    {

                        bUpdate = true;
                    }

                    tr.Commit();

                }

                if (bUpdate)
                {

                    LayoutManager acLayoutMgr = LayoutManager.Current;

                    acLayoutMgr.RenameLayout(last_name, new_name);

                    doc.Editor.Regen();

                }

                else
                {
                    ed.WriteMessage("No Layout with name " + last_name);

                }

            }
        }&lt;/PRE&gt;&lt;P&gt;I want to rename a layout of an external dwg file, how can I do it ? Thank you&lt;/P&gt;</description>
    <pubDate>Mon, 01 Jul 2019 11:54:03 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2019-07-01T11:54:03Z</dc:date>
    <item>
      <title>Rename Layout in an external dwg file using autocad .net c#</title>
      <link>https://forums.autodesk.com/t5/net-forum/rename-layout-in-an-external-dwg-file-using-autocad-net-c/m-p/8882540#M21951</link>
      <description>&lt;P&gt;Hello,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I can rename a layout of an open file using the following code :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt; static public void renamelayoutName(string last_name, string new_name)
        {

            Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
            Database db = doc.Database;
            Editor ed = doc.Editor;

            using (doc.LockDocument())
            {
                //get the Layout name

                bool bUpdate = false;

                using (Transaction tr = db.TransactionManager.StartTransaction())
                {

                    DBDictionary dLayouts = tr.GetObject(db.LayoutDictionaryId, OpenMode.ForRead) as DBDictionary;

                    if (dLayouts.Contains(last_name))
                    {

                        bUpdate = true;
                    }

                    tr.Commit();

                }

                if (bUpdate)
                {

                    LayoutManager acLayoutMgr = LayoutManager.Current;

                    acLayoutMgr.RenameLayout(last_name, new_name);

                    doc.Editor.Regen();

                }

                else
                {
                    ed.WriteMessage("No Layout with name " + last_name);

                }

            }
        }&lt;/PRE&gt;&lt;P&gt;I want to rename a layout of an external dwg file, how can I do it ? Thank you&lt;/P&gt;</description>
      <pubDate>Mon, 01 Jul 2019 11:54:03 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/rename-layout-in-an-external-dwg-file-using-autocad-net-c/m-p/8882540#M21951</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2019-07-01T11:54:03Z</dc:date>
    </item>
    <item>
      <title>Re: Rename Layout in an external dwg file using autocad .net c#</title>
      <link>https://forums.autodesk.com/t5/net-forum/rename-layout-in-an-external-dwg-file-using-autocad-net-c/m-p/8882796#M21952</link>
      <description>&lt;P&gt;You have to set the side database as WorkingDatabase before calling LayoutManager.Current. Do not forget to reset the WorkingDatabase to the active document one.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's an extension method example.&lt;/P&gt;
&lt;PRE&gt;    public static class Extension
    {
        public static void RenameLayout(this Database targetDb, string oldName, string newName)
        {
            var workingDb = HostApplicationServices.WorkingDatabase;
            try
            {
                HostApplicationServices.WorkingDatabase = targetDb;
                var layoutMgr = LayoutManager.Current;
                layoutMgr.RenameLayout(oldName, newName);
            }
            catch (System.Exception ex)
            {
                Application.ShowAlertDialog(ex.Message);
            }
            finally
            {
                HostApplicationServices.WorkingDatabase = workingDb;
            }
        }
    }&lt;/PRE&gt;
&lt;P&gt;Calling example:&lt;/P&gt;
&lt;PRE&gt;            using (var sideDb = new Database(false, true))
            {
                sideDb.ReadDwgFile(filename, FileOpenMode.OpenForReadAndAllShare, true, null);
                sideDb.RenameLayout(oldName, newName);
                sideDb.SaveAs(filename, DwgVersion.Current);
            }&lt;/PRE&gt;</description>
      <pubDate>Mon, 01 Jul 2019 13:20:22 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/rename-layout-in-an-external-dwg-file-using-autocad-net-c/m-p/8882796#M21952</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2019-07-01T13:20:22Z</dc:date>
    </item>
    <item>
      <title>Re: Rename Layout in an external dwg file using autocad .net c#</title>
      <link>https://forums.autodesk.com/t5/net-forum/rename-layout-in-an-external-dwg-file-using-autocad-net-c/m-p/9253567#M21953</link>
      <description>&lt;P&gt;This worked great, thank you so much!&lt;/P&gt;</description>
      <pubDate>Wed, 15 Jan 2020 23:48:14 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/rename-layout-in-an-external-dwg-file-using-autocad-net-c/m-p/9253567#M21953</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2020-01-15T23:48:14Z</dc:date>
    </item>
  </channel>
</rss>

