Author Topic: Move Layout to other position  (Read 671 times)

0 Members and 1 Guest are viewing this topic.

Offline Vario

  • Newbie
  • *
  • Posts: 3
  • Karma: +0/-0
    • prefered language: VB
    • Prog expertise: Good
    • View Profile
Move Layout to other position
« on: February 07, 2012, 02:23:49 PM »
Hi!
according to another problem i tried a workaround, but now im stuck...

how can i move a layout to another tabposition?
if a change the Property Tabindex, there is no effect.
even the property TabSelected = true has no effect selecting the Layout. The only way where it is possible is using the layoutmanager.
but for the other property tabindex i cannot find a function or property which works...

anybody know?

Offline frits432

  • Newbie
  • *
  • Posts: 15
  • Karma: +1/-0
  • Gender: Male
    • prefered language: C
    • Prog expertise: Beginner
    • View Profile
Re: Move Layout to other position
« Reply #1 on: February 09, 2012, 09:42:42 AM »
You might have  forgotten to "Open" the layouts.
The code below is ordering the layout's based on their names.
based on an article of
Norman Yuan http://drive-cad-with-code.blogspot.com/2011/06/set-layout-in-order.html

See attachments 1 and 2 for an example of the layout names

Quote
   public class MyCommands
    {
        [CommandMethod("OrderLayout")]
        public static void OrderAllLayouts()
        {
            Document dwg = Application.DocumentManager.MdiActiveDocument;
            Editor ed = dwg.Editor;

            SetLayoutOrder();
            ed.Regen();
        }

        private static void SetLayoutOrder()
        {
            Document doc = Application.DocumentManager.MdiActiveDocument;
            Database db = doc.Database;
            Editor ed = doc.Editor;
            var layouts = new Dictionary<string, Layout>();

            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                DBDictionary layoutDICT = (DBDictionary)tr.GetObject(db.LayoutDictionaryId, OpenMode.ForRead);
                ed.WriteMessage("\nBefore Sort");
                long j = 0;
                foreach (DBDictionaryEntry dictEntry in layoutDICT)
                {
                    Layout layout = tr.GetObject(dictEntry.Value, OpenMode.ForRead) as Layout;
                    if (!layout.ModelType)
                    {
                        layouts.Add(layout.LayoutName, layout);
                        ed.WriteMessage("\n Layout[{0}]={1}, tab={2}", j++, layout.LayoutName, layout.TabOrder);
                    }
                }
                var sortedLayoutNames = layouts.Keys
                 .Where(n => n.Contains('-'))
                 .Select(n => n.Split(new char[] { '-' }))
                 .OrderBy(n => n[0])
                 .ThenBy(n => n[1])
                 .ThenBy(n => Convert.ToInt32(n[2]))
                 .Select(n => string.Join("-", n))
                .Select((n, i) => { layouts[n].UpgradeOpen(); layouts[n].TabOrder = i + 1; return i + layouts[n].LayoutName; }).ToList();

                //ed.WriteMessage("\nsortedLayoutNames");
                //foreach (string sortedLayoutname in sortedLayoutNames)
                //    ed.WriteMessage("\n{0}", sortedLayoutname);

                ed.WriteMessage("\nAfter Sort");
                j = 0;
                foreach (DBDictionaryEntry dictEntry in layoutDICT)
                {
                    Layout layout = tr.GetObject(dictEntry.Value, OpenMode.ForRead) as Layout;
                    ed.WriteMessage("\n Layout[{0}]={1}, tab={2}", j++, layout.LayoutName, layout.TabOrder);
                }

                tr.Commit();

            }
        }
}
Frits