Bounding Box of Tag

Is there a way to get a tags bounding box?

Thanks for any help you can provide,

Figured out a really bad way of doing it but I guess it works.

If you have a better way of doing this I am all ears. This really slows down my computer.

image

import clr
import math

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

clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.GeometryConversion)
clr.ImportExtensions(Revit.Elements)

clr.AddReference('RevitServices')
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument

tag = UnwrapElement(IN[0])
view = UnwrapElement(IN[1])
list = []
	
for i in tag:

	bbox = (i.BoundingBox[view])
	pt = (bbox.Min,bbox.Max)
	list.append(pt)
	
TransactionManager.Instance.TransactionTaskDone()

OUT = list
1 Like

What kind of tags are you working with?

Someone went through and hit tag all doors and walls in our overall plans. We have unites and do not want everyone to show these tags as they are called out on the enlarged typical unit plan. We do however want all door and wall tags outside the units. My goal was to delete all door and wall inside the units and leave all others.

I tried Elements in Room from Archi-lab but it errs out saying “‘Location’ object has not attribute”.

Room.IsInsideRoom will take a point but Element.BoundingBox returns null and Element.Geometry Empty List. This is why I wrote the code above because I can get the Revit BBox min and max points. The section after where I reassemble the points was because my lack of python and the time crunch I was in. It’s not pretty but it worked.

Do you have any suggestions @john_pierson?

2 Likes

Yeah, I thought about it a bit and it seems like you can use the following method to find where the tag resides in the model.

Here is the python for it:

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

# Import ToDSType(bool) extension method
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)
clr.ImportExtensions(Revit.GeometryConversion)
# Import DocumentManager and TransactionManager
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

from System.Collections.Generic import *

# Import RevitAPI
clr.AddReference("RevitAPI")
import Autodesk


#unwrap all elements to use with API
tags = UnwrapElement(IN[0])
#apply lineweight override to elements in an input list
tagHeadPosition = list()
for i in tags:
	try:
		tagHeadPosition.append(i.TagHeadPosition.ToPoint())
	except:
		tagHeadPosition.append(list())


#Assign your output to the OUT variable
OUT = tagHeadPosition

This could prove to not work on door tags “inside” the wall though.

That being said, I bet you could make a custom bounding box and intersect them against your rooms or something.

So this graph:


20180220-tagsIntersectingRoom.dyn (25.0 KB)

Would result in this.

Since I did not know the filtering you were using, I just filtered rooms out that started with “12” in the number.

-john

5 Likes

Thanks John,

Really helpful post and thanks for the python code as well. Since I am starting to learn code its helpful to see how to complete an idea.

Quick question: Is “try:” the task to get the head point and then “except:” will return the tag IN[0] if it cannot exquisite TagHeadPosition?

Thanks,
Steven

Yeah, what that will end up doing is outputting an empty list to filter against.

I actually picked up on this technique from @Andreas_Dieckmann’s awesome clockwork package. :slight_smile:

2 Likes
for i in tag:
    a=i.OwnerViewId
    view=doc.GetElement(a)
    bbox = (i.BoundingBox[view])

This code Showing Warning: IronPythonEvaluator.EvaluateIronPythonScript operation failed.
unexpected indent

How can i fix it.

Mechanical Equipment Tags
i have tags from multiple views and i want to get bounding box of them

@sandeep.kumawat
Geniusloci has it inside his package :wink:
Try this:

1 Like

Thanks for sharing
But using this making dynamo Crash
It runs only for single time.
If i am using bounding box minimum and maximum point to make a cuboid than it is giving error :

Warning: BoundingBox.ToCuboid operation failed.
Unable to create block : ACIS_EXCEPTION_ACCESS_VIOLATION – Access violation

HI Steven.
I have a question.
If I want to get only tag text bounding box exclude tag leader what must I do?
I try to set tag hide leader and get bounding box and show leader back but data is include leader.
Thankyou.

I would have to specifically look at your family but I would say no this will not get you what you want. The bounding box will get you a box around the whole family not just text. If you want the bounding box for just the text I would recommend figuring out the min/max points within the family relative to the insertion point. Once placed in the file, you can get the tag’s insertion point and do the math backward.

In any case, I would recommend giving something a try and starting a new post.

Morning @peerawit.ru
have a look at @sovitek post here, it may be of use.