Performance Adviser API – Part 1

By Saikat Bhattacharya

Performance Adviser API, added in Autodesk® Revit® 2012 product, allows developers to execute a set of built-in or custom rules against a given model, and to display a warning dialog about the elements that fail to satisfy the rules. You can use this feature to flag the user about possible performance degradations, and to create your own rules that could be run on a model to check for adherence to certain design guidelines. For example, you may want to signal the user where walls may be overlapping.

In this post and the subsequent ones, we’ll look at this API, and discuss how to gain access to the performance adviser rules, how to execute the rules, and how to define custom rules.

Listing performance adviser rules

The performance adviser rules are a set of application-wide rules. To work with performance adviser rules, we use an application-wide, singleton class called PerformanceAdviser. This class is a “registry” of all the performance checking rules as well as an engine to execute the rules. You can access the singleton PerformanceAdviser instance using a PerformanceAdviser.GetPerformanceAdviser()static method.

Once we have access to the PerformanceAdviser object, we can use the GetAllRuleIds() method to obtain a list of rule IDs registered in the application. We can then iterate through each rule ID and get the rule information for the corresponding rule ID, using the methods, such as GetRuleName() and GetRuleDescription().

The following command illustrates how to list all the registered performance adviser:

using System;    using System.Collections.Generic;    using System.Linq;    using System.Text;         using Autodesk.Revit.UI;    using Autodesk.Revit.DB;    using Autodesk.Revit.Attributes;         namespace PASample    {           [Transaction(TransactionMode.Manual)]      public class ListPerformanceAdviserRules: IExternalCommand      {             public Autodesk.Revit.UI.Result Execute(ExternalCommandData           commandData, ref string message, ElementSet elements)          {            // Get access to PerformanceAdviser object            PerformanceAdviser adviser =               PerformanceAdviser.GetPerformanceAdviser();            // Get access to the rules in the PerformanceAdviser object            IList ruleIds =               adviser.GetAllRuleIds();                            String ruleInfo = String.Empty;            // Loop through each rule Id and get rule name, description            foreach (PerformanceAdviserRuleId ruleId in ruleIds)            {              ruleInfo = ruleInfo + "n" + adviser.GetRuleName(ruleId)                 + " : " + adviser.GetRuleDescription(ruleId);            }                 TaskDialog.Show("Existing Rules Info", ruleInfo);                        return Result.Succeeded;          }            }    }         In the subsequent post, we shall look at executing a rule.

Comments

Leave a Reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading