Execute Method


The method that Revit will invoke to perform an update.

Namespace: Autodesk.Revit.DB
Assembly: RevitAPI (in RevitAPI.dll) Version: 2015.0.0.0 (2015.0.0.0)
Since: 2011

Syntax

C#
void Execute(
	UpdaterData data
)
Visual Basic
Sub Execute ( _
	data As UpdaterData _
)
Visual C++
void Execute(
	UpdaterData^ data
)

Parameters

data
Type: Autodesk.Revit.DB UpdaterData
Provides all necessary data needed to perform the update, including the document and information about the changes that triggered the update.

Remarks

The purpose of this method is to allow your updater to react to changes that have been made to the document, and make appropriate related changes to the same document. Although it can be used to also update data outside of the document, such changes will not become part of the original transaction and will not be subject to undo or redo when the original transaction is undone or redone. If you do use this method to modify data outside of the document, you should also subscribe to the DocumentChanged event to update your data when the original transaction is undone or redone.

The method is invoked by Revit at the end of a document transaction in which elements that matched the UpdateTrigger for this Updater were added, changed or deleted. The method may be invoked more than once for the same transaction due to changes made by other Updaters.

All changes to the document made during the invocation of this method will become a part of the invoking transaction, and maintained for undo and redo operations. When implementing this method you may not open any new transactions (an exception will be thrown), but you may use sub-transactions as required.

The following methods may not be called while executing an Updater, because they introduce cross references between elements. A ForbiddenForDynamicUpdateException will be thrown when an updater attempts to call any of these methods:

  • void Autodesk.Revit.DB.ViewSheet.AddView(Autodesk.Revit.DB.View, Autodesk.Revit.DB.UV)
  • Autodesk.Revit.DB.Family Autodesk.Revit.DB.Document.LoadFamily(Autodesk.Revit.DB.Document, Autodesk.Revit.DB.IFamilyLoadOptions)
  • Autodesk.Revit.DB.Structure.AreaReinforcement Autodesk.Revit.Creation.Document.NewAreaReinforcement(Autodesk.Revit.DB.Element, Autodesk.Revit.DB.CurveArray, Autodesk.Revit.DB.XYZ)
  • Autodesk.Revit.DB.Structure.PathReinforcement Autodesk.Revit.Creation.Document.NewPathReinforcement(Autodesk.Revit.DB.Element, Autodesk.Revit.DB.CurveArray, bool)
  • void Autodesk.Revit.DB.MEPSystem.Add(Autodesk.Revit.DB.ConnectorSet)

Although the following methods are allowed during execution of an updater, they can also throw ForbiddenForDynamicUpdateException when cross-references between elements are established as a result of the call. One such example could be creating a face wall that intersect with an existing face wall, so those two would have to be joined together. Apply caution when calling these methods from an updater:

  • Autodesk.Revit.DB.ElementSet Autodesk.Revit.Creation.ItemFactoryBase.NewFamilyInstances(System.Collections.Generic.List<Autodesk.Revit.Creation.FamilyInstanceCreationData>)
  • Autodesk.Revit.DB.FamilyInstance Autodesk.Revit.Creation.ItemFactoryBase.NewFamilyInstance(Autodesk.Revit.DB.XYZ, Autodesk.Revit.DB.FamilySymbol, Autodesk.Revit.DB.Element,Autodesk.Revit.DB.Structure.StructuralType)
  • Autodesk.Revit.DB.FamilyInstance Autodesk.Revit.Creation.Document.NewFamilyInstance(Autodesk.Revit.DB.XYZ, Autodesk.Revit.DB.FamilySymbol, Autodesk.Revit.DB.Element, Autodesk.Revit.DB.Level, Autodesk.Revit.DB.Structure.StructuralType)
  • Autodesk.Revit.DB.FaceWall Autodesk.Revit.DB.FaceWall.Create(Autodesk.Revit.DB.Document, Autodesk.Revit.DB.ElementId, Autodesk.Revit.DB.WallLocationLine, Autodesk.Revit.DB.Reference)

Some UI methods may not be called while executing an Updater too, otherwise ForbiddenForDynamicUpdateException will be thrown. Such methods include: PickObject, PickObjects, PickElementsByRectangle, PickPoint, PickOne and WindowSelect.

Also, most of the methods of the UpdaterRegistry class may not be called during an updater's execution otherwise an InvalidOperationException would be thrown.

In addition to the forbidden methods listed above, other API methods that require documents to be in transaction-free state may not be called either. Such methods include but are not limited to Save, SaveAs, Close, LoadFamily, etc. Please refer to the documentation of the respective methods for more information.

See Also