Basically I want all generic annotations form a (drafting) view.
Found these and strung them together- but not seeing why this isn’t returning generic annotations. Sample file and DYN attached.
Lambda is some kind of magic I don’t fully grasp yet. and the system predicate- heck this whole line is a bit of a mystery but I adapted it to get all generic annotations in the project.:
filterAnnot = System.Predicate[System.Object](lambda x : x.Family.FamilyCategory.Name == "Generic Annotations")
Here is my little function:
import clr
import System
import System.Collections.Generic
from System.Collections.Generic import List
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
doc = DocumentManager.Instance.CurrentDBDocument
def GetDraftingViewID(strName):
##https://forums.autodesk.com/t5/revit-api-forum/view3d-collector/td-p/5277451
DraftingViewsList = FilteredElementCollector(doc).OfClass(ViewDrafting).ToElements()
##DraftingViewTemplates = [v.Id for v in DraftingViewsList if v.IsTemplate == True]
DraftingViewsList = [v for v in DraftingViewsList if v.IsTemplate == False and v.Name == strName]
#DraftingViewsList = [v for v in DraftingViewsList if v.Name == strName]
return DraftingViewsList[0]
viewDraft = GetDraftingViewID("bar")
##https://forum.dynamobim.com/t/how-to-get-all-annotation-elements-in-active-view-section-marks-elevation-tags-etc/18716/4
filterAnnot = System.Predicate[System.Object](lambda x : x.Family.FamilyCategory.Name == "Generic Annotations")
symbAnnot = List[Element](FilteredElementCollector(doc, viewDraft.Id).OfClass(FamilySymbol).ToElements()).FindAll(filterAnnot)
OUT = symbAnnot
DYN:
Sample-Generic-Annotation-Design-Bulletin-(GenericAnnos).dyn (4.9 KB)
Rvt:
Sample-Generic-Annotation-Design-Bulletin.rvt (472 KB)
Partly based on:
and the Lambda predicate from this post with @Nick_Boyts and @c.poupin