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


3 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:

hi there
I’m quite new to python+dynamo if you can give me more details :smiling_face_with_tear:

I believe in dynamo ‘py - tag all by category’ you put the code available, right?
but what do you put in ‘py - active view’?
I wanted him to run the script on all selected boards, is that possible?

Hi @otavioesteves1 Welcome to the Community :slight_smile:
The contents of the Py -Active View node are as follows:

# Load the Python Standard and DesignScript Libraries
import sys
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

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

doc = DocumentManager.Instance.CurrentDBDocument

OUT = doc.ActiveView

To clarify and provide the best assistance, what do you mean by ‘all selected boards’? All selected views? Or all selected elements? Or something else entirely?

1 Like

hey @ewan_opie thanks so much for answering me

I’m trying to make a script that does a tag all not tagged but in all sheets, it would be my biggest dream within revit :star_struck:, if you can give me any tips. I’m trying to adapt your script but I’m not succeeding.

I would like to do an extension in the future, but for now dynamo is my objetive
but thank you very much for the answer again

For the current error, try adding an extra ForceCloseTransaction before any code is executed.
image

1 Like

Don’t forget to check elevation, section and odd oblique views. Plans are always easy.
but then you go to elevation, and it is XZ or YZ or XY,Z. Or try an odd view looking down at an angle.
Just recently updated a bunch of my code to be indifferent to view orientation.

2 Likes

IT WORKED, THANK YOU SO MUCH!

Is there any way to make it work for other types of categories?
it worked only for walls tags. do i have to change the tagmode?

and another question, it’s working only in the active view, right? to make it look for sheets and consequently find the views, I just change the script, right?

thank you very much for your time, sorry for so many beginner questions :sweat_smile: