using Autodesk.AutoCAD.ApplicationServices; using Autodesk.AutoCAD.DatabaseServices; using Autodesk.AutoCAD.EditorInput; using Autodesk.AutoCAD.Geometry; using Autodesk.AutoCAD.Runtime; using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace layerlist { public class Class1 { // This method can have any name [CommandMethod("DL")] public void TestDisplayLayers() { { Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument; Database db = doc.Database; Editor ed = doc.Editor; Transaction tr = doc.Database.TransactionManager.StartTransaction(); var curSpace = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite); List<string> info = LayersToList(db); PromptPointResult ppr; PromptPointOptions ppo = new PromptPointOptions(""); ppo.Message = "\n Select the place for print output:"; //get the coordinates from user ppr = ed.GetPoint(ppo); if (ppr.Status != PromptStatus.OK) return; Point3d startPoint = ppr.Value.TransformBy(ed.CurrentUserCoordinateSystem); //Point3d startPoint1 = startPoint.Subtract(); Vector3d disp = new Vector3d(0.0, -2.0 * db.Textsize, 0.0); Vector3d disp2 = new Vector3d(0.0, -2.0 * db.Textsize, 0.0); TextStyleTable ts = (TextStyleTable)tr.GetObject(db.TextStyleTableId, OpenMode.ForRead); ObjectId mtStyleid = db.Textstyle; if (ts.Has("NAL-TEXT")) { mtStyleid = ts["NAL-FORMAT"]; } foreach (string lname in info) { MText mtext = new MText(); mtext.Location = startPoint; mtext.Width = 75.207; mtext.Height = 1.488; mtext.TextStyleId = mtStyleid; mtext.Contents = "\n" + lname; curSpace.AppendEntity(mtext); tr.AddNewlyCreatedDBObject(mtext, true); db.TransactionManager.QueueForGraphicsFlush(); startPoint += disp; } tr.Commit(); } } public List<string> LayersToList(Database db) { List<string> lstlay = new List<string>(); LayerTableRecord layer; using (Transaction tr = db.TransactionManager.StartOpenCloseTransaction()) { LayerTable lt = tr.GetObject(db.LayerTableId, OpenMode.ForRead) as LayerTable; foreach (ObjectId layerId in lt) { layer = tr.GetObject(layerId, OpenMode.ForWrite) as LayerTableRecord; lstlay.Add(layer.Name); } } return lstlay; } } }
foreach
lname.StartsWith("NL")
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)