Delete Empty Tags with Revit Python Shell from dp Stuff

Here is another task that might get time consuming but can be easily be overcome with a short Revit Python Shell script and Revit API that has to deal with empty and orphaned tags . Let me run it by you.
Lets take door tagging for example. There is a nice “out-of-the-box” Revit tool called TagAll. Say, you want to tag all the doors in a view, so you run the TagAll tool, pick the tag and tag all the doors that are not tagged. There are some other 3-d party plugins that can do it globally in multiple views. But sometimes some doors or some other elements don’t need to be tagged. For instance we have a custom project parameter for door numbers, and we don’t tag elevator doors, and maybe some other elements done with the door category that need not to be tagged, and once tagged will have and empty tag with no data in it. So TagAll function saves a lot of time, but then I end up chasing all these empty tags that need to be deleted. So again, thanks to Revit IronPython Shell with a little script you can delete all of the empty tags from the active view in one shot (see image for the option to delete empty tags in the whole document).

Download the script from here

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import clr
import math
clr.AddReference('RevitAPI')
clr.AddReference('RevitAPIUI')
from Autodesk.Revit.DB import *
 
app = __revit__.Application
doc = __revit__.ActiveUIDocument.Document
uidoc = __revit__.ActiveUIDocument
activeView = doc.ActiveView
#this script looks at tags only in the active view
collector1 = FilteredElementCollector(doc,activeView.Id)
#If you want to run it on the whole document - comment the line above and uncomment the line below
#collector1 = FilteredElementCollector(doc)
collector1.WhereElementIsNotElementType().OfClass(clr.GetClrType(IndependentTag))
elSet1 = collector1.ToElements()
print len(elSet1)
 
actDelete = True
knSet = list()
 
for el in elSet1:
	if el.TagText=='':
		knSet.append(el)
 
ct = len(knSet)
print 'Tags Found: ' +str(ct)
 
if actDelete:
	t = Transaction(doc, 'Tag Deleted')
 
	t.Start()
	for el in knSet:
		doc.Delete(el)
 
	t.Commit()
print str(ct)' empty tags removed'
Tagged with →  
Share →

Leave a Reply

Your email address will not be published. Required fields are marked *

* Copy This Password *

* Type Or Paste Password Here *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>