How to set section box equal to view range+crop region

How do you create a new 3d view equal to the 2d plan view in dynamo? I want to set the section box equal to the view range + the crop region but I cant find nodes for either one. Does anyone have any ideas? Thanks!

There’s a few ways to do this. The easiest way is to get the elements in the view and extract their extents. I like to use @Konrad_K_Sobon 's “New Section Box View By Elements” node from the archi-lab package. Tho the node was originally done back in 2014 and needs a few small changes to work in newer versions of Revit:

Here’s the updated code:

#Copyright(c) 2014, Konrad Sobon
# @arch_laboratory, http://archi-lab.net

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))
viewName = IN[1]
offset = float(IN[2])

#get ViewFamilyType for a 3D View
collector = FilteredElementCollector(doc)
viewTypeColl = collector.OfClass(ViewFamilyType)
for i in viewTypeColl:
    if i.ViewFamily == ViewFamily.ThreeDimensional:
        viewType = i
        break
    else:
        continue

#define bounding box enclosing all elements
bboxMin, bboxMax = [], []
for i in elements:
    bboxMin.append(i.get_BoundingBox(doc.ActiveView).Min)
    bboxMax.append(i.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
bbox = BoundingBoxXYZ()
bbox.Min = XYZ((bboxMinX - offset), (bboxMinY - offset), (bboxMinZ - offset))
bbox.Max = XYZ((bboxMaxX + offset), (bboxMaxY + offset), (bboxMaxZ + offset))
# "Start" the transaction
TransactionManager.Instance.EnsureInTransaction(doc)
#create 3d View
view = View3D.CreateIsometric(doc, viewType.Id)
view.Name = viewName
view.SetSectionBox(bbox)
# "End" the transaction
TransactionManager.Instance.TransactionTaskDone()
#Assign your output to the OUT variable
OUT = view.ToDSType(False)
1 Like

There’s a built-in tool in Revit :slight_smile:
Hover over the View Cube and little arrow to the bottom right will appear. From there select Orient to a View and choose the view

@Dimitar_Venkov, what code is that. Is that a macro in revit (C#) or python or what would I put that into? Can you be specific please? The dynamo way your wrote doesnt work. It created a new 3D view alright but the section box is not working

The above is a python script. You’ll need to double-click archi-lab’s custom node, then double-click the python script node inside and finally overwrite the content with the one I posted above.

@Daniel_Hurtubise Indeed. Unfortunately, it does not allow us to programmatically do the same for 10 views at the same time :slight_smile:

[quote=“Daniel_Hurtubise, post:3, topic:4982”]
There’s a built-in tool in Revit :slight_smile:Hover over the View Cube and little arrow to the bottom right will appear. From there select Orient to a View and choose the view
[/quote]Even better is to set a keyboard shortcut for Orient to a View. ( I use OV.) It gives a different dialog than the on-screen UI.

2 Likes

I’ve edited the Python code so top and bottom offset can be provided separately but there seems no way to add a code snippit to posts. Sorry I’d like to share but can’t (post interprets python syntax as HTML so it is a mess).

Select your code and click Ctrl+Shift+C or press the button preformatted text

Python code edited so top and bottom offset can be set separately:

#Copyright(c) 2014, Konrad Sobon - Edited by Dimitar Venkov & Antony McPhee
#https://forum.dynamobim.com/t/how-to-set-section-box-equal-to-view-range-crop-region/4982/2
# @arch_laboratory, http://archi-lab.net

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))
viewName = IN[1]
offset = float(IN[2])
offsetTop = float(IN[3])
offsetBottom = float(IN[4])

#get ViewFamilyType for a 3D View
collector = FilteredElementCollector(doc)
viewTypeColl = collector.OfClass(ViewFamilyType)
for i in viewTypeColl:
    if i.ViewFamily == ViewFamily.ThreeDimensional:
        viewType = i
        break
    else:
        continue

#define bounding box enclosing all elements
bboxMin, bboxMax = [], []
for i in elements:
    bboxMin.append(i.get_BoundingBox(doc.ActiveView).Min)
    bboxMax.append(i.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
bbox = BoundingBoxXYZ()
bbox.Min = XYZ((bboxMinX - offset), (bboxMinY - offset), (bboxMinZ - offsetBottom))
bbox.Max = XYZ((bboxMaxX + offset), (bboxMaxY + offset), (bboxMaxZ + offsetTop))
# "Start" the transaction
TransactionManager.Instance.EnsureInTransaction(doc)
#create 3d View
view = View3D.CreateIsometric(doc, viewType.Id)
view.Name = viewName
view.SetSectionBox(bbox)
# "End" the transaction
TransactionManager.Instance.TransactionTaskDone()
#Assign your output to the OUT variable
OUT = view.ToDSType(False)

This works fine for a single view but it can’t be fed a list to create multiple views. Does something have to be done to the python script to make it work with a list?