AutoCAD では、画層設定情報は LayerTable オブジェクトの拡張ディクショナリに保存されます。画層状態を初めて保存するときに、AutoCAD は以下を実行します。
図面の別の画層設定を保存するたびに、AutoCAD は保存された設定を記述する別の XRecord オブジェクトを作成し、その XRecord を ACAD_LAYERSTATE ディクショナリに追加します。次の図に処理を示します。
画層状態を操作するときは、項目を直接操作する必要はありません(操作を試みないでください)。LayerStateManager オブジェクトの関数を使用し、ディクショナリにアクセスします。ディクショナリを参照できるようになったら、DBDictionaryEntry オブジェクトとして表される各項目を確認できます。
画層状態が現在の図面に保存されている場合、次のコードはすべての画層状態の名前を一覧表示します。
Imports Autodesk.AutoCAD.Runtime Imports Autodesk.AutoCAD.ApplicationServices Imports Autodesk.AutoCAD.DatabaseServices <CommandMethod("ListLayerStates")> _ Public Sub ListLayerStates() '' Get the current document and database Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument Dim acCurDb As Database = acDoc.Database '' Start a transaction Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction() Dim acLyrStMan As LayerStateManager acLyrStMan = acCurDb.LayerStateManager Dim acDbDict As DBDictionary acDbDict = acTrans.GetObject(acLyrStMan.LayerStatesDictionaryId(True), _ OpenMode.ForRead) Dim sLayerStateNames As String = "" For Each acDbDictEnt As DBDictionaryEntry In acDbDict sLayerStateNames = sLayerStateNames & vbLf & acDbDictEnt.Key Next Application.ShowAlertDialog("The saved layer settings in this drawing are:" & _ sLayerStateNames) '' Dispose of the transaction End Using End Sub
using Autodesk.AutoCAD.Runtime; using Autodesk.AutoCAD.ApplicationServices; using Autodesk.AutoCAD.DatabaseServices; [CommandMethod("ListLayerStates")] public static void ListLayerStates() { // Get the current document and database Document acDoc = Application.DocumentManager.MdiActiveDocument; Database acCurDb = acDoc.Database; // Start a transaction using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction()) { LayerStateManager acLyrStMan; acLyrStMan = acCurDb.LayerStateManager; DBDictionary acDbDict; acDbDict = acTrans.GetObject(acLyrStMan.LayerStatesDictionaryId(true), OpenMode.ForRead) as DBDictionary; string sLayerStateNames = ""; foreach (DBDictionaryEntry acDbDictEnt in acDbDict) { sLayerStateNames = sLayerStateNames + "\n" + acDbDictEnt.Key; } Application.ShowAlertDialog("The saved layer settings in this drawing are:" + sLayerStateNames); // Dispose of the transaction } }
Sub ListLayerStates() On Error Resume Next Dim oLSMDict As AcadDictionary Dim XRec As Object Dim layerstateNames As String layerstateNames = "" ' Get the ACAD_LAYERSTATES dictionary, which is in the ' extension dictionary in the Layers object. Set oLSMDict = ThisDrawing.Layers. _ GetExtensionDictionary.Item("ACAD_LAYERSTATES") ' List the name of each saved layer setting. Settings are ' stored as XRecords in the dictionary. For Each XRec In oLSMDict layerstateNames = layerstateNames + XRec.Name + vbCrLf Next XRec MsgBox "The saved layer settings in this drawing are: " + _ vbCrLf + layerstateNames End Sub