public ObjectId make(string str, Point3d pt,string layer,Color color,double hei,double factor,
TextHorizontalMode horMode = TextHorizontalMode.TextLeft, TextVerticalMode verMode = TextVerticalMode.TextBottom)
{
var res = ObjectId.Null;
using (Transaction tr = db.TransactionManager.StartTransaction())
{
BlockTable bt = tr.GetObject(db.BlockTableId,OpenMode.ForRead) as BlockTable;
BlockTableRecord mSpace = tr.GetObject(bt[BlockTableRecord.ModelSpace],OpenMode.ForWrite) as BlockTableRecord;
DBText dbText = new DBText();
dbText.SetDatabaseDefaults(db);
dbText.Position = pt;// Point3d.Origin;
dbText.Height = hei;// 5.0;
dbText.TextString = str;// "Autodesk";
dbText.HorizontalMode = horMode;// TextHorizontalMode.TextCenter;
dbText.VerticalMode = verMode;// TextVerticalMode.TextVerticalMid;
dbText.AlignmentPoint = pt;// Point3d.Origin;
dbText.WidthFactor = factor;
if (true)
{ // For adding a text with an alignment to an in-memory database
// set the working database before using AdjustAlignment
Database prevWorkingDb = HostApplicationServices.WorkingDatabase;
HostApplicationServices.WorkingDatabase = db;
dbText.AdjustAlignment(db);
HostApplicationServices.WorkingDatabase = prevWorkingDb;
}
res = mSpace.AppendEntity(dbText);
tr.AddNewlyCreatedDBObject(dbText, true);
if (layer != null && layer != "") dbText.Layer = layer;
if (color != null) dbText.Color = color;
tr.Commit();
}
return res;// ObjectId.Null;
}