Attributes

The Revit API provides several attributes for configuring ExternalCommand and ExternalApplication behavior.

TransactionAttribute

The custom attribute Autodesk.Revit.Attributes.TransactionMode must be applied to your implementation class of the IExternalCommand interface to control transaction behavior for the external command. There is no default for this option. This mode controls how the API framework expects transactions to be used when the command is invoked. The supported values are:

In either mode, the TransactionMode applies only to the active document. You may open other documents during the course of the command, and you may have complete control over the creation and use of Transactions, SubTransactions, and TransactionGroups on those other documents (even in ReadOnly mode).

For example, to set an external command to use manual transaction mode:

Code Region 3-18: TransactionAttribute
[Transaction(TransactionMode.Manual)]
public class Command : IExternalCommand
{
        public Autodesk.Revit.IExternalCommand.Result Execute(
                Autodesk.Revit.ExternalCommandData commandData,
                ref string message, Autodesk.Revit.DB.ElementSet elements)
        {
                // Command implementation, which modifies the active document directly 
                // after starting a new transaction
        }
}
See Transactions. ### JournalingAttribute The custom attribute Autodesk.Revit.Attributes.JournalingAttribute can optionally be applied to your implementation class of the IExternalCommand interface to control the journaling behavior during the external command execution. There are two options for journaling: JournalMode.NoCommandData - Contents of the ExternalCommandData.JournalData map are not written to the Revit journal. This option allows Revit API calls to write to the journal as needed. This option allows commands which invoke the Revit UI for selection or responses to task dialogs to replay correctly. JournalMode.UsingCommandData - Uses the IDictionary<String, String> supplied in the command data. This will hide all Revit journal entries between the external command invocation and the IDictionary<String, String< entry. Commands which invoke the Revit UI for selection or responses to task dialogs may not replay correctly. This is the default if the JournalingAttribute is not specified.
Code Region 3-19: JournalingAttribute
[Journaling(JournalingMode.UsingCommandData)]
public class Command : IExternalCommand
{
        public Autodesk.Revit.IExternalCommand.Result Execute(
                Autodesk.Revit.ExternalCommandData commandData, 
                ref string message, Autodesk.Revit.DB.ElementSet elements)
        {
                return Autodesk.Revit.UI.Result.Succeeded;
        }
}