For somebody else to whom this would be interesting as well
Take a look at SetImpliedSelection method of document Editor
Here is Q&D example:
(slightly tested on A2009)
Code:
static public void AddItemsExm()
{
Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
Database db = HostApplicationServices.WorkingDatabase;
using (Transaction tr = db.TransactionManager.StartTransaction())
{
try
{
BlockTableRecord btr = tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite) as BlockTableRecord;
SelectionFilter sf = new SelectionFilter(
new TypedValue[] { new TypedValue(0, "LINE") });
PromptSelectionOptions pso = new PromptSelectionOptions();
pso.MessageForAdding = "\nSelect lines only >>";
pso.SingleOnly = false;
PromptSelectionResult res = ed.GetSelection(pso, sf);
if (res.Status != PromptStatus.OK)
return;
SelectionSet main = res.Value;
ObjectId[] oids = main.GetObjectIds();
ed.WriteMessage("\nSelected {0} objects", oids.Length);
Line ln = new Line(new Point3d(0, 0, 0), new Point3d(0, 1000, 0));//dummy line for test
btr.AppendEntity(ln);
tr.AddNewlyCreatedDBObject(ln, true);
int cnt = oids.Length;
Array.Resize(ref oids, cnt + 1);
oids[cnt] = ln.ObjectId;
SelectionSet newset = SelectionSet.FromObjectIds(oids);
main = null;
ed.SetImpliedSelection(newset);
ed.WriteMessage("\nAfter adding line: {0} objects", newset.GetObjectIds().Length);
foreach (SelectedObject obj in newset)
{
Entity en = (Entity)tr.GetObject(obj.ObjectId, OpenMode.ForRead);
en.UpgradeOpen();
en.ColorIndex = 1;
en.DowngradeOpen();
}
tr.Commit();
}
catch (Autodesk.AutoCAD.Runtime.Exception ex)
{
Autodesk.AutoCAD.ApplicationServices.Application.ShowAlertDialog(ex.Message);
}
}
}
~'J'~