您可以循环访问“图层”(Layers) 和“线型”(Linetypes) 表格,以查找图形中的所有图层和线型。 循环访问“图层”(Layers) 表下面的代码循环访问“层”表,以收集图形中所有层的名称。然后,这些名称将显示在消息框中。 VB.NETImports Autodesk.AutoCAD.Runtime Imports Autodesk.AutoCAD.ApplicationServices Imports Autodesk.AutoCAD.DatabaseServices <CommandMethod("DisplayLayerNames")> _ Public Sub DisplayLayerNames() '' 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() '' Open the Layer table for read Dim acLyrTbl As LayerTable acLyrTbl = acTrans.GetObject(acCurDb.LayerTableId, _ OpenMode.ForRead) Dim sLayerNames As String = "" For Each acObjId As ObjectId In acLyrTbl Dim acLyrTblRec As LayerTableRecord acLyrTblRec = acTrans.GetObject(acObjId, _ OpenMode.ForRead) sLayerNames = sLayerNames & vbLf & acLyrTblRec.Name Next Application.ShowAlertDialog("The layers in this drawing are: " & _ sLayerNames) '' Dispose of the transaction End Using End Sub C#using Autodesk.AutoCAD.Runtime; using Autodesk.AutoCAD.ApplicationServices; using Autodesk.AutoCAD.DatabaseServices; [CommandMethod("DisplayLayerNames")] public static void DisplayLayerNames() { // Get the current document and database Document acDoc = Application.DocumentManager.MdiActiveDocument; Database acCurDb = acDoc.Database; // Start a transaction using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction()) { // Open the Layer table for read LayerTable acLyrTbl; acLyrTbl = acTrans.GetObject(acCurDb.LayerTableId, OpenMode.ForRead) as LayerTable; string sLayerNames = ""; foreach (ObjectId acObjId in acLyrTbl) { LayerTableRecord acLyrTblRec; acLyrTblRec = acTrans.GetObject(acObjId, OpenMode.ForRead) as LayerTableRecord; sLayerNames = sLayerNames + "\n" + acLyrTblRec.Name; } Application.ShowAlertDialog("The layers in this drawing are: " + sLayerNames); // Dispose of the transaction } } VBA/ActiveX 代码参考Sub DisplayLayerNames() Dim layerNames As String Dim entry As AcadLayer layerNames = "" For Each entry In ThisDrawing.Layers layerNames = layerNames + entry.Name + vbCrLf Next MsgBox "The layers in this drawing are: " + _ vbCrLf + layerNames End Sub 相关概念父主题: |
|Archiver|CAD开发者社区 ( 苏ICP备2022047690号-1 苏公网安备32011402011833)
GMT+8, 2025-1-8 19:22
Powered by Discuz! X3.4
Copyright © 2001-2021, Tencent Cloud.