문제

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