How does one index the documents in the documentmanger collection? The intent is to cycle through the open documents one by one in a forwards or backwards direction. The specific function I want to create would take a direction argument, 1 or -1, and would switch the active document to the "next" or the "previous" document. Obviously I do not understand how the documentmanager collection works, so I could use a pertinent example to help me out please. I see how to For Each through the collection, but that is not the intent.
Thank you, aks
Solved! Go to Solution.
Solved by SENL1362. Go to Solution.
Looking for this ?
...
using System.Linq;
..
Document doc = Application.DocumentManager.MdiActiveDocument;
Editor ed = doc.Editor;
ed.WriteMessage("\n{0} Documents open", Application.DocumentManager.Count);
var theDocs = Application.DocumentManager.Cast<Document>().ToList();
ed.WriteMessage("\n{0} Documents open", theDocs.Count);
int indx=theDocs.IndexOf(doc);
ed.WriteMessage("\nCurrent Document {0}, has Index={1} in List", doc.Name,indx);
indx = (theDocs.IndexOf(doc) + theDocs.Count - 1) % theDocs.Count;
ed.WriteMessage("\nPrevious Index={0} is {1}", indx, (theDocs.ElementAt(indx)).Name);
indx = (theDocs.IndexOf(doc) + theDocs.Count + 1) % theDocs.Count;
ed.WriteMessage("\nNext Index={0} is {1}", indx, (theDocs.ElementAt(indx)).Name);