.NET

Reply
Member
detox
Posts: 3
Registered: ‎02-26-2006
Message 1 of 2 (114 Views)

Abort delete event

114 Views, 1 Replies
03-23-2006 11:48 PM
Hi all.

It is necessary to interrupt removal of object

Database acadDB = HostApplicationServices.WorkingDatabase;
acadDB.ObjectErased += new ObjectErasedEventHandler(acadDB_ObjectErased);

void acadDB_ObjectErased(object sender, ObjectErasedEventArgs e)
{
// any actions
//e.Abort(); ????????
}

How to not admit removal of object
Member
detox
Posts: 3
Registered: ‎02-26-2006
Message 2 of 2 (114 Views)

Re: Abort delete event

03-27-2006 12:54 AM in reply to: detox
Really, it is necessary to do so?

Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
doc.CommandWillStart += new CommandEventHandler(doc_CommandWillStart);
doc.CommandEnded += new CommandEventHandler(doc_CommandEnded);

Database acadDB = HostApplicationServices.WorkingDatabase;
acadDB.ObjectErased += new ObjectErasedEventHandler(acadDB_ObjectErased);

DBObjectCollection dbObjects = new DBObjectCollection();

void doc_CommandWillStart(object sender, CommandEventArgs e)
{
switch (e.GlobalCommandName)
{
case "ERASE":
dbObjects.Clear();
break;
default:
break;
}
}
void acadDB_ObjectErased(object sender, ObjectErasedEventArgs e)
{
dbObjects.Add(e.DBObject);
}
void doc_CommandEnded(object sender, CommandEventArgs e)
{
switch (e.GlobalCommandName)
{
case "ERASE":
RestoreObjects(dbObjects);
break;
default:
break;
}
}
void RestoreObjects(DBObjectCollection dbObjects)
{
Database db = HostApplicationServices.WorkingDatabase;
Transaction trans = db.TransactionManager.StartTransaction();
try
{
BlockTable bt = (BlockTable)trans.GetObject(db.BlockTableId, OpenMode.ForWrite);
BlockTableRecord btr = (BlockTableRecord)trans.GetObject(bt[BlockTableRecord.PaperSpace], OpenMode.ForWrite);

foreach (DBObject item in dbObjects)
{
Entity restore = (Entity)item.Clone();
btr.AppendEntity(restore);
trans.AddNewlyCreatedDBObject(restore, true);
}
trans.Commit();
}
finally
{
trans.Dispose();
}
}

The most unpleasant, that thus is removed allocation....
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Are You Going To Be @ AU 2014? Feel free to drop by our AU topic post and share your plans, plug a class that you're teaching, or simply check out who else from the community might be in attendance. Ohh and don't forgot to stop by the Autodesk Help | Learn | Collaborate booths in the Exhibit Hall and meet our community team if you get a chance!