Hi,
You can use Editor.GetString() to prompt the user for a text style but you'll also have to check if this text style already exists in the drawing text style table.
[CommandMethod("Test")]
public void Test()
{
var doc = AcAp.DocumentManager.MdiActiveDocument;
var db = doc.Database;
var ed = doc.Editor;
// prompt for insertion point
var ptResult = ed.GetPoint("\nInsertion point: ");
if (ptResult.Status != PromptStatus.OK)
return;
var point = ptResult.Value;
using (var tr = db.TransactionManager.StartTransaction())
{
var styles = (TextStyleTable)tr.GetObject(db.TextStyleTableId, OpenMode.ForRead);
// prompt for text style
var strOptions = new PromptStringOptions("\nEnter the text style name: ");
PromptResult strResult;
while (true)
{
strResult = ed.GetString(strOptions);
if (strResult.Status != PromptStatus.OK)
return;
if (styles.Has(strResult.StringResult))
break;
ed.WriteMessage("\nText style not found: {0}", strResult.StringResult);
}
var styleId = styles[strResult.StringResult];
// prompt for text contents
strOptions.Message = "\nEnter the text: ";
strOptions.AllowSpaces = true;
strResult = ed.GetString(strOptions);
if (strResult.Status != PromptStatus.OK)
return;
var textString = strResult.StringResult;
// add the text to the current space
var text = new DBText();
text.Position = point;
text.TextStyleId = styleId;
text.TextString = textString;
var curSpace = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
curSpace.AppendEntity(text);
tr.AddNewlyCreatedDBObject(text, true);
tr.Commit();
}
}