Let us see how to create a parameter categorizer method and add it to a class with the assistance of RevitAddinCoder. Click on the Parameter Categorizer tool button of the RevitAddinCoder,
or the menu item,
The Parameter Categorizer coder window will show up:
If some wanted categories are checked, the categorizer name is given, and a class is chosen, and the active project is a C# one, the following C# code will be created.
/// <summary>
/// Sample Usage:
///
///object[] appParams2 = GetApplicableParametersToCategories(CachedDoc);
///using (StreamWriter sw = new StreamWriter(@"c:\test.csv"))
///{
/// List<BuiltInParameter> list1 = appParams1[0] as List<BuiltInParameter>;
/// List<string> list2 = appParams1[1] as List<string>;
/// foreach (BuiltInParameter p in list1)
/// {
/// sw.WriteLine(p.ToString());
/// }
/// sw.WriteLine();
/// foreach (string s in list2)
/// {
/// sw.WriteLine(s);
/// }
///}
///
/// </summary>
/// <param name="RvtDocument">Revit Document</param>
/// <returns>List array: the 1st points to BuiltInParameter; the 2nd custom parameter.</returns>
public static object[] GetApplicableParametersToCategories(RvtDocument doc)
{
List<ElementId> catList = new List<ElementId>();
catList.Add(doc.Settings.Categories.get_Item(BuiltInCategory.OST_Walls).Id);
catList.Add(doc.Settings.Categories.get_Item(BuiltInCategory.OST_WallsDefault).Id);
catList.Add(doc.Settings.Categories.get_Item(BuiltInCategory.OST_WallsFinish1).Id);
catList.Add(doc.Settings.Categories.get_Item(BuiltInCategory.OST_WallsFinish2).Id);
List<ElementId> paramList = ParameterFilterUtilities.GetFilterableParametersInCommon(doc, catList).ToList();
List<BuiltInParameter> list1 = new List<BuiltInParameter>();
List<string> list2 = new List<string>();
foreach (ElementId id in paramList)
{
if (id.IntegerValue < 0)
{
list1.Add((BuiltInParameter)id.IntegerValue);
}
else
{
list2.Add(doc.get_Element(id).Name);
}
}
return new object[] { list1, list2 };
}
If the active project is a VB.NET one, the following VB.NET code will be created.
''' <summary>
''' Sample Usage:
'''
'''Dim appParams1 As Object() = GetApplicableParametersToCategories(CachedDoc)
'''Using sw As New StreamWriter("c:\temp\test.csv")
''' Dim list1 As List(Of BuiltInParameter) = TryCast(appParams1(0), List(Of BuiltInParameter))
''' Dim list2 As List(Of String) = TryCast(appParams1(1), List(Of String))
''' For Each p As BuiltInParameter In list1
''' sw.WriteLine(p.ToString())
''' Next
''' sw.WriteLine()
''' For Each s As String In list2
''' sw.WriteLine(s)
''' Next
'''End Using
'''
''' </summary>
''' <param name="doc">Revit Document</param>
''' <returns>List array: the 1st points to BuiltInParameter; the 2nd custom parameter.</returns>
''' <remarks></remarks>
Public Shared Function GetApplicableParametersToCategories(ByVal doc As RvtDocument) As Object()
Dim catList As New List(Of Autodesk.Revit.DB.ElementId)()
catList.Add(doc.Settings.Categories.Item(BuiltInCategory.OST_Walls).Id)
catList.Add(doc.Settings.Categories.Item(BuiltInCategory.OST_WallsDefault).Id)
catList.Add(doc.Settings.Categories.Item(BuiltInCategory.OST_WallsFinish1).Id)
catList.Add(doc.Settings.Categories.Item(BuiltInCategory.OST_WallsFinish2).Id)
Dim paramList As List(Of Autodesk.Revit.DB.ElementId) = Autodesk.Revit.DB.ParameterFilterUtilities.GetFilterableParametersInCommon(doc, catList).ToList()
Dim list1 As New List(Of BuiltInParameter)()
Dim list2 As New List(Of String)()
For Each id As Autodesk.Revit.DB.ElementId In paramList
If id.IntegerValue < 0 Then
list1.Add(DirectCast(id.IntegerValue, BuiltInParameter))
Else
list2.Add(doc.Element(id).Name)
End If
Next
Return New Object() {list1, list2}
End Function
Parameter Categorizer of RevitAddinCoder can create all the code automatically in no time.
Recent Comments