.NET

.NET

Reply
Valued Contributor
aksaks
Posts: 93
Registered: ‎03-23-2009
Message 1 of 3 (159 Views)
Accepted Solution

Beginner question - How to index though documentmanger collection?

159 Views, 2 Replies
11-16-2011 11:49 AM

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

 

 

 

 

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);


Mentor
SENL1362
Posts: 232
Registered: ‎07-20-2011
Message 2 of 3 (138 Views)

Re: Beginner question - How to index though documentmanger collection?

11-17-2011 03:40 AM in reply to: aksaks

 

 

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);


Valued Contributor
aksaks
Posts: 93
Registered: ‎03-23-2009
Message 3 of 3 (118 Views)

Re: Beginner question - How to index though documentmanger collection?

11-17-2011 11:26 AM in reply to: SENL1362

Very informative .Thank you. 

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.