Autodesk.Revit.DB.BoundingBoxXYZ to Boundingbox

Hi all,

I try to transform my Autodesk.Revit.DB.BoundingBoxXYZ to a dynamo Boundingbox.
What is the right way to do it?

I tried to use, ToDSType(), ToProtoType() but it doesn’t work.

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

# Import ToDSType(bool) extension method
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)

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

from System.Collections.Generic import *

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

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

#The inputs to this node will be stored as a list in the IN variable.
dataEnteringNode = IN

elements = []
for i in IN[0]:
	elements.append(UnwrapElement(i))
offset = float(0.01)
views = UnwrapElement(IN[1][1])

#get ViewFamilyType for a 3D View
collector = FilteredElementCollector(doc)
viewTypeColl = collector.OfClass(ViewFamilyType)
for i in viewTypeColl:
	if i.ViewFamily == ViewFamily.ThreeDimensional:
		viewType = i
	else:
		continue
# "Start" the transaction
TransactionManager.Instance.EnsureInTransaction(doc)

#define bounding box enclosing all elements
bboxMin, bboxMax = [], []
for i in elements:
	for b in i:
		bboxMin.append(b.get_BoundingBox(doc.ActiveView).Min)
		bboxMax.append(b.get_BoundingBox(doc.ActiveView).Max)
minX, minY, minZ, maxX, maxY, maxZ = [], [], [], [], [], []
for i, j in zip(bboxMin, bboxMax):
	minX.append(i.X)
	minY.append(i.Y)
	minZ.append(i.Z)
	maxX.append(j.X)
	maxY.append(j.Y)
	maxZ.append(j.Z)
bboxMinX = min(minX)
bboxMinY = min(minY)
bboxMinZ = min(minZ)
bboxMaxX = max(maxX)
bboxMaxY = max(maxY)
bboxMaxZ = max(maxZ)
#create a bounding box
boxen = []
for e in elements:
	bbox = BoundingBoxXYZ()
	bbox.Min = XYZ((bboxMinX - offset), (bboxMinY - offset), (bboxMinZ - offset))
	bbox.Max = XYZ((bboxMaxX + offset), (bboxMaxY + offset), (bboxMaxZ + offset))
	boxen.append(bbox)

sbox = []	
s = 0
for v in views:
	v.SetSectionBox(boxen[s])
	s += 1
	sbox.append(v.GetSectionBox())

	
# "End" the transaction
TransactionManager.Instance.TransactionTaskDone()


#Assign your output to the OUT variable
OUT = sbox

hi,

I think you have to access Dynamo API… … for any reason i can`t find a good documentation.

KR

Andreas

1 Like

Thanks @Draxl_Andreas , I have the solution.
ToProtoType() was at the wrong place:

I created a new python code and it works:

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

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

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

#The inputs to this node will be stored as a list in the IN variable.

bbox= UnwrapElement(IN[0])

dsbox = []
for b in bbox:
	dsbox.append(b.ToProtoType())

OUT = dsbox
1 Like