Maciej Główka
Blog Games Contact

← Return to Blog Index

tagGraph.png
Nov. 11, 2019

Tagging on multiple views with Dynamo

revit api dynamo

One of the most useful built-in automations in Revit is the “Tag All Not Tagged” command. However it tags elements in the active view only. In larger projects we often have dozens of views where we have to repeat the procedure. Therefore I have tried to create a Dynamo/Python script that can work on a view list and tag elements missing annotation.

The Dynamo definition is really simple here. We just have to collect a list of views, that we want to work on, category of the tagged elements and the tag itself.

tagGraph.png

The actual work is done inside of the Python node. First we have to convert given element category to a BuiltInCategory enum value. Then we will be able to use it as a filter for the FilteredElementCollector.

import System
bic = System.Enum.ToObject(BuiltInCategory,category.Id.IntegerValue) 

The FilteredElementCollector does actually most of the job in this script. We use two of them. First one collects all the elements in the view that potentially need to be tagged. Second collector gathers all tags present.

elementCollector = FilteredElementCollector(doc,v.Id).OfCategory(bic)
tagCollector = FilteredElementCollector(doc,v.Id).OfClass(IndependentTag)

Now, we just have to loop through the elements and check if they are not already tagged. We do that by comparing their id with ids of tag hosts.

notTagged = []
for e in elementCollector:
  tagged = False
  for t in tagCollector:
    if t.TaggedLocalElementId==e.Id:
      tagged = True
  if not tagged:
    notTagged.append(e)

Finally, we create new tags for elements that require them and set tag type to the one specified in the input.

for e in notTagged:
  t = IndependentTag.Create(doc,v.Id,Reference(e),False,
    TagMode.TM_ADDBY_CATEGORY,TagOrientation.Horizontal,e.Location.Point)
  t.ChangeTypeId(tag.Id)

The complete code can look like below. Also on the bottom of the post you can find a complete Dynamo file for download.

tagViews.dyn
← Auto-dimensioning rooms with Dynamo and Python Hosts from linked files→