Understanding the order of events

Most of the event procedures consist of four types for each event:

  • Initialize – your code should use these types of event procedures to prepare for batch operations.
  • Before and After – your code should perform the following:
    • Check conditions for the individual documents
    • Change property values for the individual documents
    • Perform necessary actions on the individual documents
  • Terminate – your code should invoke any necessary user interface procedures and release resources. This is typically some overview of the result.

Within a single event, the event procedures are invoked in the above order. The Initialize and Terminate procedures are invoked once each for the entire batch and for most of the events only the Vault object is available. The Before and After procedures are invoked once for each object (document, folder, and so on) affected by the event and during these events, the affected objects are available.

Note    Your code should not assume that all of the event types will occur under all conditions. For example, if an unexpected error occurs during an operation, the After or Terminate events might not occur.

The command a user executes may also involve more than one type of event. The following example lists the NewDocument and CalculateFileName events and the order in which they occur when a new document is created:

  1. DocGenericEvent_InitializeNewDocument
  2. DocGenericEvent_InitializeCalculateFileName
  3. DocGenericEvent_BeforeNewDocument
  4. DocGenericEvent_AfterNewDocument
  5. DocGenericEvent_BeforeCalculateFileName
  6. DocGenericEvent_AfterCalculateFileName
  7. DocGenericEvent_TerminateCalculateFileName
  8. DocGenericEvent_TerminateNewDocument

The preceding example is a relatively simple one in which all of the events are in the DocGenericEvent category and only one document is involved. In the following example, events in the DocGenericEvent and DocCopyMoveEvent categories occur in the order listed when a batch of documents (some of which might have references) is copied:

Before the batch of documents is processed:

  1. DocCopyMoveEvent_PrepareCopy
  2. DocCopyMoveEvent_InitializeCopy
  3. DocGenericEvent_InitializeNewDocument
  4. DocGenericEvent_InitializeCalculateFileName

For each source document in the batch:

  1. DocCopyMoveEvent_BeforeCopyWithReferences (if the source document has references)
  2. DocCopyMoveEvent_BeforeCopy
  3. DocCopyMoveEvent_AfterCopy
  4. DocCopyMoveEvent_BeforeCopy (for each reference of the current source document)
  5. DocCopyMoveEvent_AfterCopy (for each reference of the current source document)
  6. DocCopyMoveEvent_AfterCopyWithReferences (if the source document has references)

For each destination document (copy made) in the batch:

  1. DocGenericEvent_BeforeNewDocument
  2. DocGenericEvent_AfterNewDocument
  3. DocGenericEvent_BeforeCalculateFileName
  4. DocGenericEvent_AfterCalculateFileName

After the batch of documents has been processed:

  1. DocGenericEvent_TerminateCalculateFileName
  2. DocGenericEvent_TerminateNewDocument
  3. DocCopyMoveEvent_TerminateCopy

These same events occur when documents are moved, derived, or replaced but with the corresponding events (DocCopyMoveEvent_InitializeMove, DocCopyMoveEvent_BeforeMove, and so on) instead of DocCopyMoveEvent_InitializeCopy, DocCopyMoveEvent_BeforeCopy, and so on. The only difference is that the source and destination documents are the same document.

The order of the events within each category for specific Meridian commands are listed in the concept topic for each event category, About the document generic events, for example.