You certainly know that this kind of attribute reference will be erased if the ATTSYNC command is run for this block.
Here's an example of AutoCAD plugin (i.e., a class library DLL which have to be netloaded in AutoCAD) containg custom command which shows a little dialog box to let the user enter the attribute value, then it prompts the user to select a block reference and specify the attribute insertion point.
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Runtime;
namespace AmazingRequestSample
{
public class Commands
{
[CommandMethod("ADDATTREF")]
public static void AddAttributeReference()
{
var doc = Application.DocumentManager.MdiActiveDocument;
var db = doc.Database;
var ed = doc.Editor;
// display a dialog box to get the attribute value
string attValue;
using (var dialog = new AttributeValueDialog())
{
if (Application.ShowModalDialog(dialog) != System.Windows.Forms.DialogResult.OK)
return;
attValue = dialog.AttributeValue;
}
// prompts the user to select a block reference
var peo = new PromptEntityOptions("\nSelect block reference: ");
peo.SetRejectMessage("\nSelected object is not a block reference.");
peo.AddAllowedClass(typeof(BlockReference), true);
var per = ed.GetEntity(peo);
if (per.Status != PromptStatus.OK)
return;
// prompts the user to specify the attribute insertion point
var ppr = ed.GetPoint("\nSpecify the attribute insertion point: ");
if (ppr.Status != PromptStatus.OK)
return;
var insPoint = ppr.Value.TransformBy(ed.CurrentUserCoordinateSystem);
// create the attribute reference and add it to the attribute collection of the selected block
using (var tr = db.TransactionManager.StartTransaction())
{
var br = (BlockReference)tr.GetObject(per.ObjectId, OpenMode.ForWrite);
var attRef = new AttributeReference(insPoint, attValue, "TAG", db.Textstyle)
{ LockPositionInBlock = false };
br.AttributeCollection.AppendAttribute(attRef);
tr.AddNewlyCreatedDBObject(attRef, true);
tr.Commit();
}
}
}
}
The dialog box

using System.Windows.Forms;
namespace AmazingRequestSample
{
public partial class AttributeValueDialog : Form
{
public AttributeValueDialog()
{
InitializeComponent();
AcceptButton = buttonOk;
CancelButton = buttonCancel;
buttonOk.DialogResult = DialogResult.OK;
buttonCancel.DialogResult = DialogResult.Cancel;
}
public string AttributeValue => textBoxAttValue.Text;
}
}