In this post, we shall look the steps involved in executing a performance adviser rule.
While listing all the existing performance adviser rules, we can use the name of a rule to search for a specific rule that we wish to execute. Another approach for selecting rules for execution, is to create a dialog with a list of registered rules and provide the ability for users to select one or more rules for execution from the dialog. The Revit SDK sample called PerformanceAdviserControl sample uses a similar approach by providing a list of rules for the users to select from, for execution.
Once we know the rules that we are interested in, we can use PerformanceAdviser.ExecuteRules() method to execute the given rules using the rule ids. ExecuteRules() method takes a document and a set of rule ids as input arguments. It returns a list of FailureMessages, which we can iterate through and display, for instance, in a standard Revit warning dialog using Document.PostFailure() method.
The following command shows a simple example of executing “Overlapping walls” performance adviser rule:
public class ExecutePerformanceRule : IExternalCommand
public Result Execute(ExternalCommandData commandData,
ref string message, ElementSet elements)
Document doc =
// Get access to the Performance Adviser object
PerformanceAdviser adviser =
// List all the rules
IList<PerformanceAdviserRuleId> ruleIds =
// Create an empty list for the rules to be executed
IList<PerformanceAdviserRuleId> rulesIdsToExecute =
// Iterate through each
foreach (PerformanceAdviserRuleId ruleId in ruleIds)
if (adviser.GetRuleName(ruleId).Equals("Overlapping walls"))
// Now we need to post the results
IList<FailureMessage> failureMessages = adviser.ExecuteRules(
foreach (FailureMessage fm in failureMessages)
Transaction trans = new Transaction(doc, "Failure Reporting");
In the next post and the last post on this series on this topic, we shall look at defining a custom rule.