Cannot recall when the Revit .NET API provides the FindInserts method in the Wall class (precisely in its base class, HostObject). Before its introduction, in the old time, we had to use some pretty nasty means to sort out wall inserts, e.g. comparing geometry extents.
Now, with the Wall.FindInserts handy there, all these kind of tasks become so straightforward. Here we go.
Dim picked As Reference = CachedUiApp.ActiveUIDocument.Selection.PickObject(ObjectType.Element, "Pick a wall")
Dim w As Wall = DirectCast(CachedDoc.Element(picked.ElementId), Wall)
Dim ids As IList(Of ElementId) = w.FindInserts(True, True, True, True)
Dim info As String = String.Format("The wall has {0} inserts:" & vbCr & vbLf, ids.Count)
For Each id As ElementId In ids
Dim e As Element = CachedDoc.Element(id)
info += String.Format(" Element Id: {0}" & vbCr & vbLf, e.Id)
info += String.Format(" Unique Id: {0}" & vbCr & vbLf, e.UniqueId)
info += String.Format(" Type name: {0}" & vbCr & vbLf, e.[GetType]().Name)
info += String.Format(" Category name: {0}" & vbCr & vbLf, e.Category.Name)
info += String.Format(" Category Id: {0}" & vbCr & vbLf, e.Category.Id)
If TypeOf e Is FamilyInstance Then
Dim fi As FamilyInstance = TryCast(e, FamilyInstance)
info += String.Format(" Symbol name: {0}" & vbCr & vbLf, If(fi.Symbol Is Nothing, "N/A", fi.Symbol.Name))
info += String.Format(" Symbol Id: {0}" & vbCr & vbLf, If(fi.Symbol Is Nothing, "N/A", fi.Symbol.Id.ToString()))
End If
info += Environment.NewLine
Next
Using sw As New StreamWriter("c:\temp\WallInsertsInfo.txt", True)
sw.Write(info)
End Using
MessageBox.Show(info)
The same code works perfectly for curve walls as well. Here is some example output for a curve wall hosting a door and two windows.
The wall has 3 inserts:
Element Id: 3479
Unique Id: 2f293287-74f5-4b76-98c4-25e8e08f2a46-00000d97
Type name: FamilyInstance
Category name: Doors
Category Id: -2000023
Symbol name: 30" x 80"
Symbol Id: 2493
Element Id: 3491
Unique Id: 2f293287-74f5-4b76-98c4-25e8e08f2a46-00000da3
Type name: FamilyInstance
Category name: Windows
Category Id: -2000014
Symbol name: 24" x 72"
Symbol Id: 3097
Element Id: 3501
Unique Id: 2f293287-74f5-4b76-98c4-25e8e08f2a46-00000dad
Type name: FamilyInstance
Category name: Windows
Category Id: -2000014
Symbol name: 24" x 72"
Symbol Id: 3097
Revit Addin Wizard (RevitAddinWizard) provides various wizards, coders and widgets to help program Revit addins. It can be downloaded from the Download link at the bottom of the blog index page.
Posted by: |