I forgot to change the layers it is easy to figure out
Creats 10 layers & add 5 mtext to each layout
[CommandMethod("AddToEachLayout")]
public static void AddToEachLayout()
{
Database db = HostApplicationServices.WorkingDatabase;
using (Transaction trx = db.TransactionManager.StartTransaction())
{
LayerTable layerTble = db.LayerTableId.GetObject(OpenMode.ForWrite) as LayerTable;
for (int i = 1; i < 11; i++)
{
LayerTableRecord layerTblRec = new LayerTableRecord();
layerTblRec.Name = "Layer" + i;
layerTblRec.Color = Color.FromColorIndex(ColorMethod.ByAci, (short)i);
layerTble.Add(layerTblRec);
trx.AddNewlyCreatedDBObject(layerTblRec, true);
}
DBDictionary layoutDictionary = db.LayoutDictionaryId.GetObject(OpenMode.ForRead) as DBDictionary;
Point3d pnt = Point3d.Origin;
foreach (DBDictionaryEntry DictEntry in layoutDictionary)
{
Layout layout = DictEntry.Value.GetObject(OpenMode.ForRead) as Layout;
BlockTableRecord layoutBtr = layout.BlockTableRecordId.GetObject(OpenMode.ForWrite) as BlockTableRecord;
TextStyleTableRecord txtStyle = db.Textstyle.GetObject(OpenMode.ForWrite) as TextStyleTableRecord;
txtStyle.TextSize = 2.2;
for (int j = 0; j < 50; j = j + 10)
{
MText mtxt = new MText();
mtxt.Contents = "Here Is Text";
mtxt.Height = txtStyle.TextSize;
mtxt.Location = new Point3d(pnt.X + j, pnt.Y + j, 0);
layoutBtr.AppendEntity(mtxt);
trx.AddNewlyCreatedDBObject(mtxt, true);
}
}
trx.Commit();
}
}