Get a Bounding Box from a Section Box

geometry
#1

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

#2

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

0 Likes

#3

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.

0 Likes

#4

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

#5

@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.

2 Likes

#6

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])]
3 Likes

#7

It is so cool!

0 Likes