# Wall aligned bounding box

I’m trying to get wall aligned bounding box. There appears to be some mistake in the code that keeps the bounding box lying flat always at the global center. Any suggestions?

``````wall = UnwrapElement(IN[0])
bb = wall.get_BoundingBox(None)
min = bb.Min
max = bb.Max

wallLine = wall.Location.Curve
sPt = wallLine.GetEndPoint(0)
ePt = wallLine.GetEndPoint(1)
vectorPt = ePt - sPt
midPt = sPt + (0.5*vectorPt)

wt = wall.Width
wl = wallLine.Length

newMin = XYZ(-wl/2, -wt/2, min.Z)
newMax = XYZ(wl/2, wt/2, max.Z)

t = Transform.Identity
t.Origin = midPt
t.BasisX = vectorPt.Normalize()
t.BasisZ = t.BasisZ
t.BasisY = t.BasisZ.CrossProduct(t.BasisX)

transBB = BoundingBoxXYZ()
transBB.Transform = t
transBB.Min = newMin
transBB.Max = newMax

OUT =  transBB.ToProtoType().ToCuboid()
``````

hello, maybe change to this:

vectorPt = wallLine.Direction
midPt = wallLine.Evaluate(0.5, True)

1 Like

Getting the same result.

oh I misunderstood you problem

newMin = XYZ(-wl/2, -wt/2, min.Z) + midPt
newMax = XYZ(wl/2, wt/2, max.Z) + midPt

1 Like

Thanks, it shifts the bounding box but the bounding box doesn’t align/rotate.

As of now, bounding boxes cannot rotate off axis. You can build an object aligned cuboid as an alternative.

3 Likes

Thanks for the alternative.
I was referring to this article where a section is created parallel to the wall and to do so it uses a transformed bounding box. Is there anything different going on here with the bounding box?

You can create a transformed bounding box in the Revit API; in fact that is what was posted above. What you can’t do (now) is assume that the Revit bounding box can be sent back to Dynamo, as it’ll often be rotated by the transform.

Instead, plan on staying in the Revit API for the duration of the rotated bounding box.

1 Like

Thanks for the suggestion. I wanted to deconstruct the bounding boxes of walls into solid/surfaces for checking connections/gap with the slab.

Instead consider getting the wall’s location line, offsetting that, build a PolyCurve by joining the start and endpoints, and extruding that by the wall’s height.

1 Like