Issue
When I assign a profile to a Mullion in Revit, the drop-down list only includes profiles made using the Profile-Mullion.rft Imperial Template, plus a few system families. I want to create a similar drop-down list of mullion profiles but I'm not sure how to determine if a profile is a mullion profile or something else. When I look at all the profiles in the API I see that all their categories are OST_ProfileFamilies.
How can I filter out just the mullion profiles like Revit does?
Solution
A profile family has profile Usage property in its definition. Mullion is the integer value "8", and generic one is "0". You can use it to determine if the given profile is for mullion or not. The sample code is attached below:
One thing to note, however, is that the system profiles isn't in the elements list. This is something Revit handles internally as a special case. Let us know if you wish to access to the system profile. We'll log a wish.
<Transaction(TransactionMode.Automatic)> _
Public Class RvtCmd_Test
Implements IExternalCommand
Public Function Execute(ByVal commandData As ExternalCommandData, _
ByRef message As String, _
ByVal elements As ElementSet) _
As Result Implements IExternalCommand.Execute
Dim rvtDoc As Document = commandData.Application.ActiveUIDocument.Document
'' get the list of profile families
'' we can only pick up standard family, however.
Dim collector As FilteredElementCollector = New FilteredElementCollector(rvtDoc)
'' this picks up only standard family types, however.
collector.OfCategory(BuiltInCategory.OST_ProfileFamilies)
Dim elems As List(Of Element) = collector.ToElements
'' check the usage parameter from the loaded family.
'' mullion profile = 8 & Generic profile = 0
Dim elems2 = New List(Of Element)
For Each elem As Element In elems
Dim aType As FamilySymbol = CType(elem, FamilySymbol)
Dim paraUsage As Parameter = aType.Family.Parameter(BuiltInParameter.FAM_PROFILE_USAGE)
If (paraUsage.AsInteger = 8) Or (paraUsage.AsInteger = 0) Then
elems2.Add(elem)
End If
Next
'' show it
ShowElementList(elems2, "mullion profile families")
Return Result.Succeeded
End Function
'' Helper function to display info from a list of elements passed onto.
'' (Same as Revit Intro Lab3.)
Sub ShowElementList(ByVal elems As IList(Of Element), ByVal header As String)
Dim s As String = header + "(" + elems.Count.ToString + ")" + vbCr + vbCr
s = s + " - Class - Category - Name (or Family: Type Name) - Id - " + vbCr
For Each elem As Element In elems
s = s + ElementToString(elem)
Next
TaskDialog.Show("Revit UI Lab", s)
End Sub
'' Helper Funtion: summarize an element information as a line of text,
'' which is composed of: class, category, name and id.
'' name will be "Family: Type" if a given element is ElementType.
'' Intended for quick viewing of list of element, for example.
'' (Same as Revit Intro Lab3.)
Function ElementToString(ByVal elem As Element) As String
If elem Is Nothing Then
Return "none"
End If
Dim name As String = ""
If TypeOf elem Is ElementType Then
Dim param As Parameter = _
elem.Parameter(BuiltInParameter.SYMBOL_FAMILY_AND_TYPE_NAMES_PARAM)
If param IsNot Nothing Then
name = param.AsString
End If
Else
name = elem.Name
End If
Return elem.GetType.Name + "; " + elem.Category.Name + "; " _
+ name + "; " + elem.Id.IntegerValue.ToString + vbCr
End Function
End Class