Tag rooms in multiple views

So recently in the comments below post on tagging through multiple views some questions have been asked about doing same for rooms. For some reason room tags in Revit are a different kind of element than other tags.

Anyways, I have tried to give an answer in the comments section but it didn’t seem to work. So I have tried one more time and now it works! (at least in Revit 2019). Here is the Python code:

import clr

clr.AddReference("RevitAPI")
from Autodesk.Revit.DB import *

clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

doc = DocumentManager.Instance.CurrentDBDocument

#The inputs to this node will be stored as a list in the IN variables.
views = UnwrapElement(IN[0])
tag = UnwrapElement(IN[1])

output = []

TransactionManager.Instance.EnsureInTransaction(doc)

for v in views:
  if not v.IsTemplate:
    elementCollector = FilteredElementCollector(doc,v.Id).OfCategory(BuiltInCategory.OST_Rooms)
    tagCollector = FilteredElementCollector(doc,v.Id).OfClass(SpatialElementTag)
    notTagged = []
    for r in elementCollector:
      tagged = False
      for t in tagCollector:
        if t.Room==r:
          tagged = True
      if not tagged:
        notTagged.append(r)
        
    for r in notTagged:
      rId = LinkElementId(r.Id)
      t = doc.Create.NewRoomTag(rId, UV(r.Location.Point.X,r.Location.Point.Y), v.Id)
      t.ChangeTypeId(tag.Id)
      output.append(t)
    
TransactionManager.Instance.TransactionTaskDone()
      
#Assign your output to the OUT variable.
OUT = output

The main difference is of course doc.Create.NewRoomTag function, which is room tag specific. One tricky part – as an argument you have to pass LinkElementId of the room – regardless if it is located in the current or linked model. The conversion from regular element Id is done through:

rId = LinkElementId(r.Id)

You can also download a .dyn file below. For simplicity I have used some archilab nodes to collect the views – but it is not necessary for the script to work.

If Python is not your thing you can always try our Onion Nodes. Element.FindNotTagged node can help you achieve same result easily.

Posts created 42

Leave a Reply

Your email address will not be published.

Related Posts

Begin typing your search term above and press enter to search. Press ESC to cancel.

Back To Top