vinayan
vinayan

Reputation: 1637

How to Get all opened AutoCad documents(drawings) using .NET

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

Upvotes: 1

Views: 11484

Answers (2)

Wingman4l7
Wingman4l7

Reputation: 678

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

Upvotes: 2

JayP
JayP

Reputation: 809

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

Upvotes: 3

Related Questions