Rename layout

By Virupaksha Aithal
You can use LayoutManager class function RenameLayout to rename the layouts. Below code shows simple example showing the renaming of the layout.

[CommandMethod("RenameLayout")]
static public void renamelayoutName()
{
    Document doc = Application.DocumentManager.MdiActiveDocument;
    Database db = doc.Database;
    Editor ed = doc.Editor;
 
    //get the Layout name
    PromptStringOptions opts =
       new PromptStringOptions("Enter Layout name to change");
    opts.AllowSpaces = true;
 
    PromptResult layoutName = ed.GetString(opts);
 
    if (layoutName.Status != PromptStatus.OK)
        return;
 
    bool bUpdate = false;
    using (Transaction tr =
                    db.TransactionManager.StartTransaction())
    {
        DBDictionary dLayouts = tr.GetObject(db.LayoutDictionaryId,
                          OpenMode.ForRead) as DBDictionary;
 
        if (dLayouts.Contains(layoutName.StringResult))
        {
            bUpdate = true;
        }
 
        tr.Commit();
 
    }
 
    if (bUpdate)
    {
        LayoutManager acLayoutMgr = LayoutManager.Current;
        acLayoutMgr.RenameLayout(layoutName.StringResult,
                    layoutName.StringResult + " - modified");
 
        doc.Editor.Regen();
    }
    else
    {
        ed.WriteMessage("No Layout with name "
                + layoutName.StringResult);
    }
}

Comments

2 responses to “Rename layout”

  1. JamesOneil Avatar
    JamesOneil

    An automatic skill is firm and approached for the citizens. The effective use of the game grid 2
    for thk offers. Method is inclined for the team work. Value is done for the reformed tip by all issues for the certificate options by all major s signs for the team.

  2. Thanks for this article! I read it and try

Leave a Reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading