Revit API 2012 provides a new Performance Advisor Rule API with which we can access to all the existing native Revit peformance advisor rules, execuate any of them, and create our own ones when necessary and hook them up into the system.
We have created a custom Performance Advisor Rule (PerformanceAdviserRule) previously. In this article, let us create some code to run it and see how it behaves in Revit. Here is the code to execute our custom performance advisor rule.
PerformanceAdviser adviser = PerformanceAdviser.GetPerformanceAdviser();
PerformanceAdviserRuleId ruleId = WallTooShortMonitor.RuleId;
if (ruleId != null)
{
IList<FailureMessage> msgList = adviser.ExecuteRules(CachedDoc, new List<PerformanceAdviserRuleId> { ruleId });
Transaction tr = new Transaction(CachedDoc, "FailureMessage Posting");
tr.Start();
foreach (FailureMessage m in msgList)
{
CachedDoc.PostFailure(m);
}
tr.Commit();
}
As can be seen, it is pretty much the same as executing a native performance advisor rule. We did make things easier as discussed in the previous post. The PerformanceAdviserRuleId of our custom rule has been created as a public static member and we can access to it anytime anywhere. Therefore, we do not have to iterate through the PerformanceAdviserRuleId collection as we did to those native rules before. Once again, we do not have to disable some rules so as to run only the others. We can call another method ExecuteRules() to only run our own rule. Once again, The PostFailure() call must have a transaction to accompany though ground is not so clear.
In case there are some walls shorter than 1 foot, a task dialog like the following may pop up after the above code is run in an external command, for example.
Then we can choose to show the problematic elements or even delete those when necessary.
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