public class Commands
{
[CommandMethod("TEST")]
public static void Test()
{
var doc = Application.DocumentManager.MdiActiveDocument;
var db = doc.Database;
var ed = doc.Editor;
var pir = ed.GetInteger("\nEnter the start number: ");
if (pir.Status != PromptStatus.OK)
return;
int index = pir.Value;
using (var tr = db.TransactionManager.StartTransaction())
{
var cSpace = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
while (true)
{
using(var text
= new DBText
()) {
text.SetDatabaseDefaults();
text.Height = 0.5;
text.TextString = index.ToString();
var jig
= new TextJig
(text
); var pr = ed.Drag(jig);
if (pr.Status == PromptStatus.Cancel)
return;
if (pr.Status == PromptStatus.None)
break;
cSpace.AppendEntity(text);
tr.AddNewlyCreatedDBObject(text, true);
db.TransactionManager.QueueForGraphicsFlush();
index++;
}
}
tr.Commit();
}
}
}
public class TextJig : EntityJig
{
DBText text;
Point3d dragPoint;
public TextJig(DBText text) : base(text)
{
this.text = text;
}
protected override SamplerStatus Sampler(JigPrompts prompts)
{
var options
= new JigPromptPointOptions
("\nSpecify insertion point: "); options.UserInputControls =
UserInputControls.Accept3dCoordinates | UserInputControls.NullResponseAccepted;
var result = prompts.AcquirePoint(options);
if (result.Value.IsEqualTo(dragPoint))
return SamplerStatus.NoChange;
dragPoint = result.Value;
return SamplerStatus.OK;
}
protected override bool Update()
{
text.Position = dragPoint;
return true;
}
}