The API provides the ElementSetIterator class. I used its method MoveNext in a While loop, and this takes us through each selected element, on which you can then test for type and act accordingly.
Public Sub LoopSelectedElements()
Dim activeDoc As Document = revitApp.ActiveDocument
Dim selectionIterator As Autodesk.Revit.ElementSetIterator
selectionIterator = revitApp.ActiveDocument.Selection.Elements.ForwardIterator
'loop through iterator
While selectionIterator.MoveNext
Dim currElement As Autodesk.Revit.Element = selectionIterator.Current
'see what elements we've found
Debug.Print(currElement.Name.ToString)
'check for type and make mods
If TypeOf currElement Is Autodesk.Revit.Elements.TextNote Then
Dim textNote As Autodesk.Revit.Elements.TextNote = currElement
textNote.AddLeader(Enums.TextNoteLeaderTypes.TNLT_STRAIGHT_R)
End If
End While
End Sub
I didn't really test the textNote.AddLeader part. Fred reports that it works but the new leader only becomes visible when you move the textnote. Something to look into when I've got a spare five mins :)
Probably because you didn't wrap it in a transaction.To trigger an update on the screen you need to use a transaction. There's little performance penalty but if there are a lot of textnotes you might want to wrap the loop in one transaction
ReplyDeletedoc.BeginTransaction()
textNote.AddLeader(Enums....)
doc.EndTransaction();
Guy