.NET

Reply
Member
3 Posts
0 Kudos
Registered: ‎02-26-2006
Post 1 of 2

Abort delete event

115 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
3 Posts
0 Kudos
Registered: ‎02-26-2006
Post 2 of 2

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 interested in helping shape the future of the Autodesk Community? To participate in this brief usability study, please click here. Your time and input is greatly appreciated!