访问集合
 
 

大部分的集合和容器对象都是通过 Document 或 Database 对象访问的。Document 和 Database 对象都包含一些相应的特性用来访问大多数可用集合的对象或对象 ID。例如,以下代码定义一个变量,并将其设置为当前图形的 LayersTable 对象:

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

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
}
VBA/ActiveX 代码参考