Revit API 2012 provides a new Performance Advisor Rule API with which we can access to all the existing native Revit peformance advisor rules or create our own ones and hook them up into the system.
We have demonstrated listing out all existing peformance advisor rules, running an existing one, create a new one, hooking it up into the system, and executing the new one. We also presented a nice table that contains all the native Revit peformance advisor rules for references. In this post, let us see how to delete a native PerformanceAdviserRule such as the ‘View clipping is disabled’ one from the system.
We need to figure out the PerformanceAdviserRule guid first so as to identify the rule and filter it out from the system. With the table handy, this task cannot be more straightforward:
A Nice Table Listing Out All Native Revit Performance Advisor Rules
As can be checked out from the table, the GUID of the rule is "b37b2ae0-6eab-423d-bec7-59c5598d1c82". With this piece of information ready, it’s also straightforward to delete it from the PerformanceAdviser system.
string ruleName = "View clipping is disabled";
string guid = "b37b2ae0-6eab-423d-bec7-59c5598d1c82";
PerformanceAdviser adviser = PerformanceAdviser.GetPerformanceAdviser();
PerformanceAdviserRuleId ruleId = adviser.GetAllRuleIds()
.FirstOrDefault(r => r.Guid.ToString()
.Equals(guid, StringComparison.InvariantCultureIgnoreCase));
if (ruleId != null)
{
TaskDialog.Show("Delete PerformanceAdviserRule", string.Format("Rule '{0}' is there in the system!", ruleName));
adviser.DeleteRule(ruleId);
TaskDialog.Show("Delete PerformanceAdviserRule", string.Format("Rule '{0}' has been removed from the system!", ruleName));
PerformanceAdviserRuleId ruleId1 = adviser.GetAllRuleIds()
.FirstOrDefault(r => r.Guid.ToString()
.Equals(guid, StringComparison.InvariantCultureIgnoreCase));
if (ruleId1 == null)
{
TaskDialog.Show("Delete PerformanceAdviserRule", string.Format("Rule '{0}' is gone!", ruleName));
}
}
else
{
TaskDialog.Show("Delete PerformanceAdviserRule", string.Format("Rule '{0}' is not there in the system!", ruleName));
}
After the code is added to an external command and it is run, the following task dialogs will show up one after another to tell us everything goes as expected.
Please note no need to start a transaction for the PerformanceAdvisor Rule deletion. It is natural since they are memory resident only.
Revit Addin Wizard (RevitAddinWizard) provides a PerformanceAdvisor Rule Creator to help implement custom performance advisor rules automatically and quickly. RevitAddinWizard can be downloaded from the Download link at the bottom of the blog index page.
Recent Comments