Skip to content

Instantly share code, notes, and snippets.

@teocomi
Created May 21, 2018 11:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save teocomi/dd1ccf7c40fea3b8851f09f6fadc6e38 to your computer and use it in GitHub Desktop.
Save teocomi/dd1ccf7c40fea3b8851f09f6fadc6e38 to your computer and use it in GitHub Desktop.
#Given an element Id or a list or elementIds, return the matching tags/s found
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
# Import DocumentManager and TransactionManager
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
# Import RevitAPI
clr.AddReference("RevitAPI")
import Autodesk
from Autodesk.Revit.DB import *
def getTagsByElementId(beamIds):
doc = DocumentManager.Instance.CurrentDBDocument
allTags = FilteredElementCollector(doc).OfClass(IndependentTag).ToElements()
return loopSublists(beamIds, allTags)
def loopSublists(data, allTags):
out = []
if type(data) is list:
for d in data:
out.append(loopSublists(d, allTags))
elif data != None:
matches = []
for i in allTags:
if str(i.TaggedElementId.HostElementId) == str(data):
matches.append(i)
# if multiple matches nest them
if len(matches) == 1:
out = matches[0]
elif len(matches) == 0:
out = None
else:
out = matches
return out
OUT = getTagsByElementId(IN[0])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment