[CommandMethod("0Annotatelevels")]
public static void LevelAnnotator()
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Transaction tr = doc.TransactionManager.StartTransaction();
List<string> listOfLayers = new List<string>();
string filePath = @"C:\Developments\Lists\101.txt";
StreamReader sr = new StreamReader(filePath, System.Text.Encoding.Default);
string line;
while ((line = sr.ReadLine()) != null)
{
listOfLayers.Add(line);
}
PromptKeywordOptions selectFormat = new PromptKeywordOptions("\nSet level ");
foreach (var layer in listOfLayers)
{
selectFormat.Keywords.Add(layer);
}
selectFormat.AllowNone = false;
PromptResult selected = doc.Editor.GetKeywords(selectFormat);
using (tr)
{
BlockTable bt = (BlockTable)db.BlockTableId.GetObject(OpenMode.ForWrite);
BlockTableRecord btr = (BlockTableRecord)tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
Point3d point = SelectionUtilities.GetPointFromUser("Set insertion point");
using (MText mtext = new MText())
{
mtext.Location = point;
mtext.TextHeight = 500;
mtext.Attachment = AttachmentPoint.BottomLeft;
mtext.Contents = "\\L" + $"{selected.StringResult}";
mtext.Layer = "-10-Text";
btr.AppendEntity(mtext);
tr.AddNewlyCreatedDBObject(mtext, true);
}
tr.Commit();
}
}