- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I am trying to filter for detail items in a cropped dependent view, but the filtered element collector picks up the detail items from the parent view as well. I tried to use the ElementIntersectsSolidFilter but it doesn't work with detail items. I tried to use the outline of the dependent view, but if the crop area of the dependent view is rotated then it doesn't work correctly. Is there another way to do this?
I have some examples of my codes below. I also attached a Revit file with some macros that include this code so that the problem can be reproduced along with a video. The macros find and delete existing details in the active view, finds sprinklers in that active view, and places a detail item on top of the sprinklers.
This is the code that I started with but it does not filter correctly for dependent views (Macro Test1)
Dim foundTags = (From t As FamilyInstance In New FilteredElementCollector(m_rvtDoc, aView.Id).OfCategory(BuiltInCategory.OST_DetailComponents).OfClass(GetType(FamilyInstance))
Where t.LookupParameter("Family").AsValueString.StartsWith("HF Sprinkler Head"))
I tired this so that I could filter by the name afterwards but it has the same result
Dim foundTags = New FilteredElementCollector(m_rvtDoc, aView.Id).OfCategory(BuiltInCategory.OST_DetailComponents)
I tried the ElementIntersectsSolidFilter but it doesn't work with detail items (Macro Test2)
I am currently trying to use the outline but it does not work if the dependent view has a rotated crop box. (Macro Test3) The code for this is below and it also draws the outline in the view for testing purposes. When the crop box is rotated the drawn box does not match, similar to the problem to this article https://thebuildingcoder.typepad.com/blog/2018/04/bounding-box-filter-always-axis-aligned.html
Dim aView As View = m_rvtDoc.ActiveView
If TryCast(aView, ViewPlan) IsNot Nothing Then
Dim sprinklers = New FilteredElementCollector(m_rvtDoc, aView.Id).OfCategory(BuiltInCategory.OST_Sprinklers).OfClass(GetType(FamilyInstance)).Cast(Of FamilyInstance)()
Dim v As ViewPlan = TryCast(aView, ViewPlan)
Using trans As New Transaction(m_rvtDoc, "Place Sloped Sprinkler Symbols")
trans.Start()
'remove all existing symbols
Dim foundTags = (From t As FamilyInstance In New FilteredElementCollector(m_rvtDoc, aView.Id).OfCategory(BuiltInCategory.OST_DetailComponents).OfClass(GetType(FamilyInstance))
Where t.LookupParameter("Family").AsValueString.StartsWith("HF Sprinkler Head"))
If v.GetPrimaryViewId IsNot Nothing AndAlso v.CropBoxActive Then 'is a cropped dependent, filter for within the view
Dim getZ As Double = TryCast(foundTags(0).Location, LocationPoint).Point.Z
Dim bottomZ As Double = getZ - 1
Dim trf As autodesk.Revit.DB.Transform = v.CropBox.Transform.Inverse
Dim cbMax As XYZ = trf.OfPoint(v.CropBox.Max)
Dim cbMin As XYZ = trf.OfPoint(v.CropBox.Min)
Dim ol0 As New XYZ(cbMin.X, cbMin.Y, bottomZ)
Dim ol1 As New XYZ(cbMax.X, cbMax.Y, bottomZ + 2)
Dim ol As Outline = New Outline(ol0, ol1)
'draw outline for checking
Dim pt0 As New XYZ(cbMin.X, cbMin.Y, bottomZ)
Dim pt1 As New XYZ(cbMax.X, cbMin.Y, bottomZ)
Dim pt2 As New XYZ(cbMax.X, cbMax.Y, bottomZ)
Dim pt3 As New XYZ(cbMin.X, cbMax.Y, bottomZ)
Dim edge0 As Line = Line.CreateBound(pt0, pt1)
Dim edge1 As Line = Line.CreateBound(pt1, pt2)
Dim edge2 As Line = Line.CreateBound(pt2, pt3)
Dim edge3 As Line = Line.CreateBound(pt3, pt0)
m_rvtDoc.Create.NewDetailCurve(v, edge0)
m_rvtDoc.Create.NewDetailCurve(v, edge1)
m_rvtDoc.Create.NewDetailCurve(v, edge2)
m_rvtDoc.Create.NewDetailCurve(v, edge3)
Dim deleteIDS As New List(Of ElementId)
For Each t In foundTags
Dim pnt As LocationPoint = TryCast(t.Location, LocationPoint)
If ol.Contains(pnt.Point, 0) Then
deleteIDS.Add(t.Id)
End If
Next
TaskDialog.Show("Debug", "Active View - " & aView.Name & ", Sprinklers Found: " & sprinklers.Count & ", Symbols Found: " & deleteIDS.Count)
m_rvtDoc.Delete(deleteIDS)
Dim i = 0
Else
Dim deleteIDS As New List(Of ElementId)
For Each t In foundTags
Dim i = 0
deleteIDS.Add(t.Id)
Next
TaskDialog.Show("Debug", "Active View - " & aView.Name & ", Sprinklers Found: " & sprinklers.Count & ", Symbols Found: " & deleteIDS.Count)
m_rvtDoc.Delete(deleteIDS)
End If
PlaceNewSymbols(m_rvtDoc,sprinklers)
trans.Commit()
End Using
Else
TaskDialog.Show("Error", "Head symbols cannot be placed in this view - " & aView.Name)
End If
The article also mentions transforming the target elements to check and see if they are in an outline that has been rotated. I was able to get that to work a little bit better, but it is still picking up detail items that are not visible in the cropped view (Macro Test4)
Dim aView As View = m_rvtDoc.ActiveView
If TryCast(aView, ViewPlan) IsNot Nothing Then
Dim sprinklers = New FilteredElementCollector(m_rvtDoc, aView.Id).OfCategory(BuiltInCategory.OST_Sprinklers).OfClass(GetType(FamilyInstance)).Cast(Of FamilyInstance)()
Dim v As ViewPlan = TryCast(aView, ViewPlan)
Using trans As New Transaction(m_rvtDoc, "Place Sloped Sprinkler Symbols")
trans.Start()
'remove all existing symbols
Dim foundTags = (From t As FamilyInstance In New FilteredElementCollector(m_rvtDoc, aView.Id).OfCategory(BuiltInCategory.OST_DetailComponents).OfClass(GetType(FamilyInstance))
Where t.LookupParameter("Family").AsValueString.StartsWith("HF Sprinkler Head"))
If foundTags.Count > 0 Then
If v.GetPrimaryViewId IsNot Nothing AndAlso v.CropBoxActive Then 'is a cropped dependent, filter for within the view
Dim getZ As Double = TryCast(foundTags(0).Location, LocationPoint).Point.Z
Dim bottomZ As Double = getZ - 1
Dim trf As autodesk.Revit.DB.Transform = v.CropBox.Transform
Dim cbMax As XYZ = v.CropBox.Max
Dim cbMin As XYZ = v.CropBox.Min
Dim ol0 As New XYZ(cbMin.X, cbMin.Y, bottomZ)
Dim ol1 As New XYZ(cbMax.X, cbMax.Y, bottomZ + 2)
Dim ol As Outline = New Outline(ol0, ol1)
Dim deleteIDS As New List(Of ElementId)
For Each t In foundTags
Dim pnt As LocationPoint = TryCast(t.Location, LocationPoint)
Dim chkPnt As XYZ = trf.OfPoint(pnt.Point)
If ol.Contains(chkPnt, 0) Then
deleteIDS.Add(t.Id)
End If
Next
TaskDialog.Show("Debug", "Active View - " & aView.Name & ", Sprinklers Found: " & sprinklers.Count & ", Symbols Found: " & deleteIDS.Count)
m_rvtDoc.Delete(deleteIDS)
Dim i = 0
Else
Dim deleteIDS As New List(Of ElementId)
For Each t In foundTags
Dim i = 0
deleteIDS.Add(t.Id)
Next
TaskDialog.Show("Debug", "Active View - " & aView.Name & ", Sprinklers Found: " & sprinklers.Count & ", Symbols Found: " & deleteIDS.Count)
m_rvtDoc.Delete(deleteIDS)
End If
End If
PlaceNewSymbols(m_rvtDoc,sprinklers)
trans.Commit()
End Using
Else
TaskDialog.Show("Error", "Head symbols cannot be placed in this view - " & aView.Name)
End If
Solved! Go to Solution.