Hi,
Full set of code given below:
using (DocumentLock lk = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.LockDocument())
{
using (Transaction Trans = acaddoc.Database.TransactionManager.StartTransaction())
{
BlockTable acBlkTbl;
acBlkTbl = Trans.GetObject(acaddatabase.BlockTableId,
OpenMode.ForRead) as BlockTable;
BlockTableRecord acBlkTblRec;
acBlkTblRec = Trans.GetObject(acBlkTbl[BlockTableRecord.ModelSpace],
OpenMode.ForWrite) as BlockTableRecord;
PromptSelectionOptions Options = new PromptSelectionOptions();
Options.SingleOnly = true;
Options.SinglePickInSpace = true; //Stores the active document
SelectionFilter Filter = new SelectionFilter(new TypedValue[] { new TypedValue(100, "AcDbEntity") });
PromptSelectionResult Selection;
Selection = acaddoc.Editor.GetSelection(Options, Filter);
if (Selection.Status == PromptStatus.OK)
{
SelectionSet acSSet = Selection.Value;
foreach (SelectedObject acSSObj in acSSet)
{
Entity acadentity = Trans.GetObject(acSSObj.ObjectId, OpenMode.ForWrite) as Entity;
acadentity.Highlight();
string entname = RXClass.GetClass(acadentity.GetType()).DxfName;
if (entname == "INSERT") // for "LWPOLYLINE"
{
BlockReference acblockref = (acadentity) as BlockReference;
if (TxtIncrementStart.Text != null && TxtIncrementvalue.Text != null && TxtIncrementFieldname.Text != null)
{
inc = inc + Convert.ToInt32(TxtIncrementvalue.Text);
string strfieldvalue = Convert.ToString(inc);
DBText acText = new DBText();
acText.SetDatabaseDefaults();
acText.Position = acblockref.Position;
acText.Height = 5;
acText.TextString = strfieldvalue;
acBlkTblRec.AppendEntity(acText);
Trans.AddNewlyCreatedDBObject(acText, true);
UpdateValuetoSingleField(acadentity.Layer, acadentity.ObjectId, strfieldname, strfieldvalue);
}
}
}
}
Trans.Commit();
}
}
}
}
acadeditor.Regen();
}
Regards,
Viswanathan Solaisamy