Skip to content

Instantly share code, notes, and snippets.

@pzurek
Created March 31, 2010 23:45
Show Gist options
  • Save pzurek/351107 to your computer and use it in GitHub Desktop.
Save pzurek/351107 to your computer and use it in GitHub Desktop.
public void Initialize()
{
DocumentCollection dm = Application.DocumentManager;
dm.DocumentActivated += delegate(object s, DocumentCollectionEventArgs d){
Document doc = d.Document;
doc.CommandWillStart += delegate(object sender, CommandEventArgs e){
if ((e.GlobalCommandName == "PUBLISH") ||
(e.GlobalCommandName == "EXPORT") ||
(e.GlobalCommandName == "3DDWF")){
// Register for publishing events
Publisher pb = Application.Publisher;
pb.AboutToBeginBackgroundPublishing += new AboutToBeginBackgroundPublishingEventHandler(pb_AboutToBeginBackgroundPublishing);
pb.AboutToBeginPublishing += new AboutToBeginPublishingEventHandler(pb_AboutToBeginPublishing);
pb.BeginEntity += new BeginEntityEventHandler(pb_BeginEntity);
pb.BeginSheet += new BeginSheetEventHandler(pb_BeginSheet);
}
};
doc.CommandEnded += new CommandEventHandler(doc_CommandEnded);
doc.CommandFailed += new CommandEventHandler(doc_CommandEnded);
doc.CommandCancelled += new CommandEventHandler(doc_CommandEnded);
};
}
void doc_CommandEnded(object sender, CommandEventArgs e){
if ((e.GlobalCommandName == "PUBLISH") ||
(e.GlobalCommandName == "EXPORT") ||
(e.GlobalCommandName == "3DDWF")){
// Unregister from publishing events
Publisher pb = Application.Publisher;
pb.AboutToBeginBackgroundPublishing -= new AboutToBeginBackgroundPublishingEventHandler(pb_AboutToBeginBackgroundPublishing);
pb.AboutToBeginPublishing -= new AboutToBeginPublishingEventHandler(pb_AboutToBeginPublishing);
pb.BeginEntity -= new BeginEntityEventHandler(pb_BeginEntity);
pb.BeginSheet -= new BeginSheetEventHandler(pb_BeginSheet);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment