سؤال

I am using AutoCAD 2012 and the .NET API. Can someone help me how can i loop through the document objects of all the open documents? i am trying to do something like the code below..I have this question on Autodesk Forum too..but not sure how much active it is :)

public void GetDocNames()
        {
            DocumentCollection docs = Application.DocumentManager;

            for (int i = 0; i < docs.Count; i++)
            {
                AcadDocument doc = docs[i];
                Debug.Print(doc.Name);
            }
        }
هل كانت مفيدة؟

المحلول

You have tagged both C# and VB.NET. The C# version is as follows:

public void GetDocNames()
{
  DocumentCollection docs = Application.DocumentManager;

  foreach (Document doc in docs)
  {
    Application.ShowAlertDialog(doc.Name);
  }
}

نصائح أخرى

The VB.NET version:

Private Sub getAcadDocNames()
    'collection of all opened documents
    Dim AcadDocs As DocumentCollection = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager 

    For Each doc As Document In AcadDocs
        Debug.Print(doc.Name)
    Next doc
End Sub

Note that you may want to fully qualify the path of the DocumentManager property (as I've done here) if you've also imported System.Windows.Forms (which also has an Application namespace).

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top