Application.DocumentManager.DocumentCreated += new DocumentCollectionEventHandler(DocumentManager_DocumentCreated);
Application.DocumentManager.DocumentToBeDestroyed += new DocumentCollectionEventHandler(DocumentManager_DocumentToBeDestroyed);
List<ObjectId> modify = new List<ObjectId>();
private void DocumentManager_DocumentCreated(object sender, Autodesk.AutoCAD.ApplicationServices.DocumentCollectionEventArgs e)
{
document.CommandWillStart += new CommandEventHandler(MdiActiveDocument_CommandWillStart);
document.CommandEnded += new CommandEventHandler(MdiActiveDocument_CommandFinish);
document.CommandFailed += new CommandEventHandler(MdiActiveDocument_CommandFinish);
document.CommandCancelled += new CommandEventHandler(MdiActiveDocument_CommandFinish);
}
private void DocumentManager_DocumentToBeDestroyed(object sender, Autodesk.AutoCAD.ApplicationServices.DocumentCollectionEventArgs e)
{
document.CommandWillStart -= new CommandEventHandler(MdiActiveDocument_CommandWillStart);
document.CommandEnded -= new CommandEventHandler(MdiActiveDocument_CommandFinish);
document.CommandFailed -= new CommandEventHandler(MdiActiveDocument_CommandFinish);
document.CommandCancelled -= new CommandEventHandler(MdiActiveDocument_CommandFinish);
}
private void MdiActiveDocument_CommandWillStart(object sender, CommandEventArgs e)
{
Database database = document.Database;
database.ObjectModified += new ObjectEventHandler(database_ObjectModified);
}
private void MdiActiveDocument_CommandFinish(object sender, CommandEventArgs e)
{
Database database = document.Database;
database.ObjectModified -= new ObjectEventHandler(database_ObjectModified);
ApplyChanges(commandName, document);
}
private void database_ObjectModified(object sender, ObjectEventArgs e)
{
modify.Add(e.DBObject.Id);
}
private void ApplyChanges(string commandName, Document document)
{
try
{
foreach(var id in modify)
{
if (id.IsErased || id.IsNull)
continue;
Transaction tr = null;
try
{
tr = document.Database.TransactionManager.StartTransaction();
using (var obj = tr.GetObject(id, OpenMode.ForWrite))
if (obj is Member member)
{
//постобработка
RefreshMember(member);
}
tr.Commit();
}
catch
{
if (tr != null)
tr.Abort();
}
finally
{
if (tr != null)
tr.Dispose();
}
}
}
finally
{
modify.Clear();
}
}
public static void RefreshMember(Member member)
{
if (!member.IsWriteEnabled)
{
member.UpgradeOpen();
}
member.RecordGraphicsModified(true);
double test = member.InsulationThickness;
member.InsulationThickness = test + 10;
member.InsulationThickness = test;
}