get_BoundingBox in subTransaction with RollBack

Hello guys,
is there any way to bypass this one?

Basically the idea is to

  • create an empty sheet

  • place viewports

  • get boundingBox of each viewport -> I need Points
    This way I can get whole BB with viewport title
    I don’t really need to create this sheet with all viewports so that’s why there is a rollback.
    But still can’t bypass
    .get_BoundingBox(view)

    TransactionManager.Instance.EnsureInTransaction(doc)
    trans = Autodesk.Revit.DB.SubTransaction(doc)
    trans.Start()

      	try:
      		if Viewport.CanAddViewToSheet(doc,sheet.Id,v.Id):
      			vp = Viewport.Create(doc,sheet.Id,v.Id,l.ToXyz())
      			bounding = vp.get_BoundingBox(vp)
      			minPoints.append(bounding.Min.ToPoint())
      			maxPoints.append(bounding.Max.ToPoint())
      			
      	except Exception, e:
      		outList.append(e.message)
      	trans.RollBack()
      	TransactionManager.Instance.ForceCloseTransaction()
    

I can get points using:
vp.GetBoxOutline().MinimumPoint.ToPoint()
but these points don’t take into account viewport title ;/

Thanks :slight_smile:

Full Code

import clr

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

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

clr.AddReference("RevitAPI")
import Autodesk

doc = DocumentManager.Instance.CurrentDBDocument

def tolist(obj1):
if hasattr(obj1,"__iter__"): return obj1
else: return [obj1]

titleBlock = UnwrapElement(IN[1])
views = tolist(UnwrapElement(IN[2]))
locs = IN[3]

outList = []
minPoints = []
maxPoints = []

if IN[0]:
for v in views:
TransactionManager.Instance.EnsureInTransaction(doc)
trans = Autodesk.Revit.DB.SubTransaction(doc)
trans.Start()
try:
if Viewport.CanAddViewToSheet(doc,sheet.Id,v.Id):
vp = Viewport.Create(doc,sheet.Id,v.Id,locs.ToXyz())
bounding = vp.get_BoundingBox(None)
minPoints.append(bounding.Min.ToPoint())
maxPoints.append(bounding.Max.ToPoint())

except Exception, e:
outList.append(e.message)
trans.RollBack()
TransactionManager.Instance.ForceCloseTransaction()
OUT = (minPoints,maxPoints)

else:
OUT = "Set Run to True"

GetBoxOutline() & GetLabelOutline() methods did the trick (without BoundingBox).
Still, it would be nice to know how to do this using BB :slight_smile:

2 Likes