AutoCAD 将图层设置信息保存在对象的扩展字典中。首次保存图层状态时,AutoCAD 将执行以下操作:LayerTable
每次在图形中保存另一个图层设置时,AutoCAD 都会创建另一个对象来描述所保存的设置,并将其存储在 ACAD_LAYERSTATE 字典中。下图说明了该过程。XRecordXRecord 在处理图层状态时,您不需要(也不应尝试)直接操作条目。使用对象的函数访问字典。一旦您引用了字典,您就可以单步执行表示为对象的每个条目。LayerStateManagerDBDictionaryEntry 列出图形中保存的图层状态如果已在当前图形中保存了图层状态,则以下代码将列出所有已保存的图层状态的名称: VB.NETImports 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 C#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 } } VBA/ActiveX 代码参考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 相关概念父主题: |
|Archiver|CAD开发者社区 ( 苏ICP备2022047690号-1 苏公网安备32011402011833)
GMT+8, 2025-1-8 19:50
Powered by Discuz! X3.4
Copyright © 2001-2021, Tencent Cloud.