<CommandMethod("IterateLayers")> _
Public Sub IterateLayers()
''获得当前文档和数据库,并启动一个事务 Get the current document and database, and start a transaction
Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument
Dim acCurDb As Database = acDoc.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)
'' 遍历层表并输出每一个层的名称 Step through the Layer table and print each layer name
For Each acObjId As ObjectId In acLyrTbl
Dim acLyrTblRec As LayerTableRecord
acLyrTblRec = acTrans.GetObject(acObjId, OpenMode.ForRead)
acDoc.Editor.WriteMessage(vbLf & acLyrTblRec.Name)
Next
'' 销毁事务 Dispose of the transaction
End Using
End Sub