//Get the name of each registered PerformanceRule and then execute all of them. foreach (PerformanceAdviserRuleId id in PerformanceAdviser.GetPerformanceAdviser().GetAllRuleIds()) { string ruleName = PerformanceAdviser.GetPerformanceAdviser().GetRuleName(id); } PerformanceAdviser.GetPerformanceAdviser().ExecuteAllRules(document);
The following excerpt from the PerformanceAdviserControl sample in the Revit API SDK Samples folder demonstrates the 以下摘录摘自Revit API SDK Samples文件夹中的PerformanceAdviserControl示例,演示了用于标识文档中任何正面翻转的门的自定义规则的实现。(在示例项目查看完整类实现。)
publicclassFlippedDoorCheck : Autodesk.Revit.DB.IPerformanceAdviserRule { #region Constructor /// /// Set up rule name, description, and error handling /// publicFlippedDoorCheck() { m_name = "Flipped Door Check"; m_description = "An API-based rule to search for and return any doors that are face-flipped"; m_doorWarningId = new Autodesk.Revit.DB.FailureDefinitionId(new Guid("25570B8FD4AD42baBD78469ED60FB9A3")); m_doorWarning = Autodesk.Revit.DB.FailureDefinition.CreateFailureDefinition(m_doorWarningId, Autodesk.Revit.DB.FailureSeverity.Warning, "Some doors in this project are face-flipped."); } #endregion
#region IPerformanceAdviserRule implementation /// /// Does some preliminary work before executing tests on elements. In this case, /// we instantiate a list of FamilyInstances representing all doors that are flipped. /// /// The document being checked publicvoidInitCheck(Autodesk.Revit.DB.Document document) { if (m_FlippedDoors == null) m_FlippedDoors = new List<Autodesk.Revit.DB.ElementId>(); else m_FlippedDoors.Clear(); return; }
/// /// This method does most of the work of the IPerformanceAdviserRule implementation. /// It is called by PerformanceAdviser. /// It examines the element passed to it (which was previously filtered by the filter /// returned by GetElementFilter() (see below)). After checking to make sure that the /// element is an instance, it checks the FacingFlipped property of the element. /// /// If it is flipped, it adds the instance to a list to be used later. /// /// The active document /// The current element being checked publicvoidExecuteElementCheck(Autodesk.Revit.DB.Document document, Autodesk.Revit.DB.Element element) { if ((element is Autodesk.Revit.DB.FamilyInstance)) { Autodesk.Revit.DB.FamilyInstance doorCurrent = element as Autodesk.Revit.DB.FamilyInstance; if (doorCurrent.FacingFlipped) m_FlippedDoors.Add(doorCurrent.Id); }
}
/// /// This method is called by PerformanceAdviser after all elements in document /// matching the ElementFilter from GetElementFilter() are checked by ExecuteElementCheck(). /// /// This method checks to see if there are any elements (door instances, in this case) in the /// m_FlippedDoor instance member. If there are, it iterates through that list and displays /// the instance name and door tag of each item. /// /// The active document publicvoidFinalizeCheck(Autodesk.Revit.DB.Document document) { if (m_FlippedDoors.Count == 0) System.Diagnostics.Debug.WriteLine("No doors were flipped. Test passed."); else { //Pass the element IDs of the flipped doors to the revit failure reporting APIs. Autodesk.Revit.DB.FailureMessage fm = new Autodesk.Revit.DB.FailureMessage(m_doorWarningId); fm.SetFailingElements(m_FlippedDoors); Autodesk.Revit.DB.Transaction failureReportingTransaction = new Autodesk.Revit.DB.Transaction(document, "Failure reporting transaction"); failureReportingTransaction.Start(); document.PostFailure(fm); failureReportingTransaction.Commit(); m_FlippedDoors.Clear(); } }
/// /// Gets the description of the rule /// /// The rule description publicstringGetDescription() { return m_description; }
/// /// This method supplies an element filter to reduce the number of elements that PerformanceAdviser /// will pass to GetElementCheck(). In this case, we are filtering for door elements. /// /// The document being checked /// A door element filter public Autodesk.Revit.DB.ElementFilter GetElementFilter(Autodesk.Revit.DB.Document document) { returnnew Autodesk.Revit.DB.ElementCategoryFilter(Autodesk.Revit.DB.BuiltInCategory.OST_Doors); }
/// /// Gets the name of the rule /// /// The rule name publicstringGetName() { return m_name; }
/// /// Returns true if this rule will iterate through elements and check them, false otherwise /// /// True publicboolWillCheckElements() { returntrue; }