Get a Bounding Box from a Section Box

Is there a way to get a bounding box from a section box in a 3D view?

I know that it is possible to go the other way around but I am having difficulty getting a bounding box. I want to be able to take an existing 3D view, duplicate it, and change the scope box of the new view.

The only way I can think do do this is to get a bounding box from an existing 3D view, modify it, and use View3D.SetSectionBox with a duplicated new view.

I’m really stuck here DynaFam, any help is appreciated.

Edit: I’ll be looking further into this, looks like it could have what I’m looking for.

https://forum.dynamobim.com/t/bounding-box-of-section-box-min-max-pts-z-values-dont-correspond-with-model-elevation/15776

I’ll be sure to post a clear solution for this problem when I find it.

1 Like

@dancleary can you post what you have done so far?

I can and I will tomorrow when I’m in the office.

The problem is I haven’t gotten anywhere. I’ve been trying to use existing nodes to accomplish this task but none seem to exist. The next step is to start looking into the API to see if I can come up with a python script to put in. I figured I’d see if the community knows about a node before I go down that road.

If you go the API route, the command on a 3d view is called .GetSectionBox() and returns a bounding box. This should be what you are asking for.

Keep in mind though that bounding boxes do not save orientation, they are always the same orientation. So if your scope box or sectionbox has been rotated, it won’t be kept over. If that is important, .GetCropRegionShapeManager() might work, but I haven’t tested it.

1 Like

@awilliams python code from her own solution HERE works for what I am trying to accomplish.

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

clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)

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

from System.Collections.Generic import *

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

clr.ImportExtensions(Revit.GeometryConversion)

doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
app = uiapp.Application


views = UnwrapElement(IN[0])

TransactionManager.Instance.EnsureInTransaction(doc)

viewlist = []
sectionboxes = []
floors = []
floorboxes = []

for view in views:
	viewlist.append(view)
	sectionbox = view.GetSectionBox()
	transform = sectionbox.Transform
	sboxoriginx = transform.Origin.X
	sboxoriginy = transform.Origin.Y
	sboxoriginz = transform.Origin.Z
	minx = sectionbox.Min.X + sboxoriginx
	maxx = sectionbox.Max.X + sboxoriginx
	miny = sectionbox.Min.Y + sboxoriginy
	maxy = sectionbox.Max.Y + sboxoriginy
	minz = sectionbox.Min.Z + sboxoriginz
	maxz = sectionbox.Max.Z + sboxoriginz
	bbox = BoundingBoxXYZ()
	bbox.Min = XYZ((minx), (miny), (minz))
	bbox.Max = XYZ((maxx), (maxy), (maxz))
	tsectionbox = bbox.ToProtoType()
	sectionboxes.append(tsectionbox)
	collector = FilteredElementCollector(doc, view.Id)
	floor = collector.OfClass(Floor).ToElements()
	floors.append(floor)

TransactionManager.Instance.TransactionTaskDone()

OUT = views, sectionboxes, floors

The python code only takes in a list so single views will not work. What I did is create a list of the same view and pull out one of the boundary boxes from the output. Its kinda jerry-rigged but it works. If I have extra time I will try to change it to single input, I could definitely could use the python practice.

5 Likes

To make it work for list and single items, you just need a simple if statement that turns single objects into a list containing only the single object. Something like this:

if isinstance(IN[0], list):
    views = UnwrapElement(IN[0])
else:
    views = [UnwrapElement(IN[0])]
5 Likes

It is so cool!

This python code doesn’t work for me. Can you show me how it works? I am not familiar with scripting in dynamo. I want to make a geometry of bounding box from the 3D section box.

@esmaeili.iraj1990
First, you’ll want to create a python node in dynamo.
Then plug in views to the input of the python node.

I recommend checking out the dynamo primer to learn about python and dynamo.

Thanks a lot for your guidance

Hi @dancleary
you wrote that, “I know that is possible to go the other way around”.
Can you tell me how?

To get section box from bounding box, in 3D?

Thanks,
Atharva

Using a View3D, you can set the section box from a bounding box by using the command View3D.SetSectionBox(BoundingBoxXYZ) in a python node.

I haven’t really kept up to date about any packages if they have that built in but it should be pretty easy to pass a 3d view and the bounding box in.

Thanks, @kennyb6
I’ll have a look at it!

I’m not very familiar with python. Is there a way to create a section box around two clashing elements using nodes?

or how to create a section box from bounding box?

Hey @parvir.mundi I think your question is a good question but a little off topic. Maybe make a new post?

Anyway, the method I would use to solve your question would be to first get the bounding boxes of each element. Then create a new bounding box using the largest max bound and the smallest min bound of the two bounding boxes. Not sure if it can be done with just nodes.

1 Like