I do not have access to Acad2010, but I tried with Acad2009 and Acad2011 (both are AcadMap) with .NET3.5 (VS2008). The event fires as expected. This is the code (I added some comments regarding the event with relevant lines of code):
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Runtime;
[assembly: CommandClass(typeof(ObjectOpenedEvent.MyCommand))]
namespace ObjectOpenedEvent
{
public class MyCommand
{
[CommandMethod("MyCommand")]
public static void RunThisMethod()
{
Document dwg = Autodesk.AutoCAD.ApplicationServices.
Application.DocumentManager.MdiActiveDocument;
Editor ed = dwg.Editor;
dwg.Database.ObjectOpenedForModify+=
new ObjectEventHandler(Database_ObjectOpenedForModify);
bool go = true;
while (go)
{
PromptEntityOptions opt =
new PromptEntityOptions("\nPick an entity:");
PromptEntityResult res = ed.GetEntity(opt);
if (res.Status == PromptStatus.OK)
{
ObjectId entId = res.ObjectId;
ModifyObject(dwg.Database, entId);
}
else
{
go = false;
}
}
dwg.Database.ObjectOpenedForModify -= Database_ObjectOpenedForModify;
ed.WriteMessage("\nMyCommand executed.");
}
private static void Database_ObjectOpenedForModify(object sender, ObjectEventArgs e)
{
Document dwg = Autodesk.AutoCAD.ApplicationServices.
Application.DocumentManager.MdiActiveDocument;
dwg.Editor.WriteMessage(
"\nObjectOpenedForModify event being handled on this object: {0}",
e.DBObject.ObjectId.ToString());
}
private static void ModifyObject(Database db, ObjectId entId)
{
using (Transaction tran = db.TransactionManager.StartTransaction())
{
Entity ent = (Entity)tran.GetObject(entId, OpenMode.ForRead);
//This line does not trigger the envent
ent.UpgradeOpen();
//The event only triggered when the first line of code
//that modified the entity is to be executed.
//That is, event fires first that the ColorIndex is changed
ent.ColorIndex = 1;
//The event only fires once per entity being opened.
//Thus this line does not trigger the event
ent.Layer = "Layer1";
ent.DowngradeOpen();
tran.Commit();
}
}
}
}
Here is the Acad's text window, after picking 3 entities (the code prints text inside the event handler, so we know the event fires):
Command: mycommand
Pick an entity:
ObjectOpenedForModify event being handled on this object: (2129323136)
Pick an entity:
ObjectOpenedForModify event being handled on this object: (2129323144)
Pick an entity:
ObjectOpenedForModify event being handled on this object: (2129323152)
Pick an entity: *Cancel*
MyCommand executed.
I did not try Document.ImpliedSelectionChanged event, though.