Revit Bounding Boxes are aligned with global axes (AABB), so the bounding box solution will only work with doors in walls that are aligned with global axes and not walls that are diagonal in plan.
A better approach would be to get the position of the door, it’s orientation and dimensions and recreate the box. You can find code for this below with annotations explaining what is happening…
Door.AsDSBox (Py)
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript import Geometry as geom
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
doc = DocumentManager.Instance.CurrentDBDocument
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)
clr.ImportExtensions(Revit.GeometryConversion)
clr.AddReference("RevitAPI")
from Autodesk.Revit.DB import *
"""
Ensures list of objects.
"""
def tolist(obj1):
if hasattr(obj1,"__iter__"): return obj1
else: return [obj1]
"""
Converts doors to dynamo boxes with correct orientation and size...
"""
def DoorToBox(door):
# Get door location Revit API Object...
loc = door.Location
# If there is no Location for this element, then return null...
if loc == None:
return None
# Get the Position of the door and cast to Dynamo Type...
pos = door.Location.Point.ToPoint()
# Get the Orientation of the door and cast to Dynamo Type...
orient = d.FacingOrientation.ToVector()
# Here we flip the orientation vector if dot product to Y-Axis is less than 0. This ensures that the angle calculation is correct...
if geom.Vector.Dot(geom.Vector.YAxis(), orient) < 0:
orient = orient.Reverse()
# Get door Type. We need this to get Type Width/Height values as these are Type Params...
dType = doc.GetElement(door.GetTypeId())
# Get door dimensions...
thk = door.Host.Width * ft2mm
w = dType.get_Parameter(BuiltInParameter.DOOR_WIDTH).AsDouble() * ft2mm
h = dType.get_Parameter(BuiltInParameter.DOOR_HEIGHT).AsDouble() * ft2mm
# Height Adjust as box is placed centre height...
hAdj = geom.Vector.ByCoordinates(0,0,h/2)
# Create a coordinate system that matches the door...
cs = geom.CoordinateSystem.ByOriginVectors(pos + hAdj, orient, geom.Vector.Cross(geom.Vector.ZAxis(), orient))
# Create a box at the origin of the Coordinate System and with the dimensions we got earlier...
box = geom.Cuboid.ByLengths(cs, thk, w, h)
return box
# Unit conversion helper value...
ft2mm = 304.8
# Doors that are passed via node input...
doors = tolist(UnwrapElement(IN[0]))
# If no doors, then get ALL doors in the project...
if IN[0] == None:
doors = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Doors).WhereElementIsNotElementType().ToElements()
# Apply DoorToBox method to all doors and return boxes...
OUT = [DoorToBox(d) for d in doors]
You could also do this purely with nodes if you preferred. Just follow the code in the DoorToBox definition.