Tagging All Elements of Category In View

Hi All,

Just a quick share on tagging all elements of a category in views, as I have seen this request more than once in the forum recently @vanman :sweat_smile:


Result of running once for each category below.

## Import Reference Examples
import clr
clr.AddReference('RevitAPI')
import Autodesk
from Autodesk.Revit.DB import *

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

clr.AddReference('RevitAPIUI')
from  Autodesk.Revit.UI import *

clr.AddReference("RevitNodes")
import Revit
from Autodesk.Revit.DB import *
clr.ImportExtensions(Revit.GeometryConversion)

clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

doc = DocumentManager.Instance.CurrentDBDocument

elems = UnwrapElement(IN[0])
v = IN[1]

count = 0

for e in elems:
	ep = e.Location
	try:
		# Element Defined By Point
		elemPoint = ep.Point
		startpoint = (elemPoint.X, elemPoint.Y, elemPoint.Z)
	except:
		try:
			# Eleemnt Defined By Curve
			crv = ep.Curve
			pt1 = crv.GetEndPoint(0) 
			pt2 = crv.GetEndPoint(1) 
			x1 = (pt1.X + pt2.X)/2
			y1 = (pt1.Y + pt2.Y)/2
			z1 = (pt1.Z + pt2.Z)/2
			elemPoint = Point.ByCoordinates(x1,y1,z1)
			startpoint = (elemPoint.X, elemPoint.Y, elemPoint.Z)
		except:
			# Havent tested anything else...
			# Force Stop
			TransactionManager.Instance.ForceCloseTransaction()
			break
	
	shiftPoint = XYZ(elemPoint.X, elemPoint.Y, elemPoint.Z)
	R = Reference(e)
	
	# Create  Tags
	tx = Transaction(doc)
	tx.Start('Tag Category')
	IT = IndependentTag.Create(doc, ElementId(v.Id), R, False, TagMode.TM_ADDBY_CATEGORY, TagOrientation.Horizontal, shiftPoint)
	count = + 1
	tx.Commit()

OUT = count


2 Likes

Another nice one kiwi :slight_smile:

1 Like

Thanks @Marcel_Rijsmus :+1:
There is plenty of scope for making this code better such as looping through categories and views, but I thought it best to get the bones out there to be used.

2 Likes

Any plans for the Skeleton Package? :slight_smile:

:thinking: perhaps, sounds like something I’d do :laughing:
Though to be fair, I am needing to overhaul the Sastrugi Package with API changes and code improvements. Perhaps some new nodes…

Just tricky to find the time :alarm_clock:

2 Likes

haha he does it again! caught me whining all over the forms :rofl: Thanks Ewan, very greatful :grin:

No worries @vanman :+1:

It would be great to hear the performance difference between using your other workflow and this one, which hopefully gives you some speed improvements.

cool beans will let you know. Got a few mad scientist ideas in my head and I think the nodes are there to implement it with this :partying_face: