コレクションにアクセスする(.NET)

ほとんどのコレクションおよびコンテナ オブジェクトは、Document または Database オブジェクトを通じてアクセスされます。Document および Database オブジェクトには、使用可能なほとんどの Collection オブジェクトのオブジェクトやオブジェクト ID にアクセスするためのプロパティが含まれています。たとえば、次のコードは変数を定義し、現在の図面の Layers のコレクションを表す LayersTable オブジェクトを取得します。

C#

// Get the current document and start the Transaction Manager
Database acCurDb = Application.DocumentManager.MdiActiveDocument.Database;
using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
{
    // This example returns the layer table for the current database
    LayerTable acLyrTbl;
    acLyrTbl = acTrans.GetObject(acCurDb.LayerTableId,
                                 OpenMode.ForRead) as LayerTable;
 
     // Dispose of the transaction
}

VB.NET

'' Get the current document and start the Transaction Manager
Dim acCurDb As Database = Application.DocumentManager.MdiActiveDocument.Database
Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction()
 
    '' This example returns the layer table for the current database
    Dim acLyrTbl As LayerTable
    acLyrTbl = acTrans.GetObject(acCurDb.LayerTableId, _
                                 OpenMode.ForRead)
 
    '' Dispose of the transaction
End Using

VBA/ActiveX コード リファレンス

Dim layerCollection as AcadLayers
Set layerCollection = ThisDrawing.Layers