ObjectAppended not working as required

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Howdy folks, have a question about the ObjectAppended event. Code below should explain the predicament. I want to only capture the items between adding the handler and subtracting it. As of now, it seems to be adding everything to my DBObjectionCollection even after removing the handler. Any suggestions?
Document acDoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
Database acCurDb = acDoc.Database;
using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
{
DocumentCollection dm = Application.DocumentManager;
Editor ed = dm.MdiActiveDocument.Editor;
Database destDb = dm.MdiActiveDocument.Database;
Database sourceDb = new Database(false, true);
Database sourceDb1 = new Database(false, true);
try
{
//Inserting Fan
// Read the DWG into a side database
sourceDb.ReadDwgFile(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "requireddrawing.dwg"), System.IO.FileShare.Read, true, "");
Autodesk.AutoCAD.DatabaseServices.TransactionManager tm = sourceDb.TransactionManager;
Matrix3d transform = ed.CurrentUserCoordinateSystem;
transform = transform * Matrix3d.Scaling(scale, Point3d.Origin);
Point3d dblmirrorpoint = new Point3d(0, (100) / 2, 0);
recentlyaddeditem.Dispose();
recentlyaddeditem = new DBObjectCollection();
destDb.ObjectAppended += DestDb_ObjectAppended;
destDb.Insert(transform, sourceDb, true);
ed.WriteMessage("\nThe number of items added is " + recentlyaddeditem.Count.ToString());
acTrans.Commit();
destDb.ObjectAppended -= DestDb_ObjectAppended;
}
catch
{ }
}
}
private void DestDb_ObjectAppended(object sender, ObjectEventArgs e)
{
Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
using (Transaction tr = db.TransactionManager.StartOpenCloseTransaction())
{
try
{
recentlyaddeditem.Add(e.DBObject);
//doc.Editor.WriteMessage("Object added");
}
catch
{ }
tr.Commit();
}
}
DBObjectCollection recentlyaddeditem = new DBObjectCollection();