Creating a new 3D view with section box aligned to 2D crob box and depth

Hi everyone,

I am building my first script for work and decided to build one that takes you straight to a 3D view of any 2D view that you are in at that moment.

Everything is working perfectly, except for the cropping of the section box on to the 2 view crop region.

I am using the SetSectionBox(my3Dview, boundingBoxXYZ) method, my problem is that I can’t seem to find anything that returns a boundingBoxXYZ that is usable in my script.

Please see my code below for reference:

"""Create 3D view from current view"""

from pyrevit import revit, DB, UI
from pyrevit import forms
from pyrevit import script

#Create new 3D view with name of current user, cropped to the active view
def new_view(view, user):
    if type(view) == revit.DB.View3D:
        forms.alert("Please use a 2D view")
        with script.revit.Transaction("Create View"):
            newThreeDee = revit.create.create_3d_view(user + " temp")
        revit.UI.UIDocument.RequestViewChange(revit.HOST_APP.uidoc, newThreeDee)

        revit.DB.View3D.SetSectionBox(newThreeDee, revit.DB.View.getBoundingBox(view, view))
        # print(type(revit.DB.View.GetCropRegionShapeManagerForReferenceCallout(revit.HOST_APP.doc, revit.DB.View.CropBox(newThreeDee))))

originalView = revit.active_view

#Check if active view is a 3D view
#Return false if view is 2D
get_view_type = type(originalView) == revit.DB.View3D

#Gets the name of the user currently active
get_current_user = revit.HOST_APP.username
new_view(originalView, get_current_user)```

Here’s a section from a similar script I’ve written.

elevation = view.GenLevel.LookupParameter('Elevation').AsDouble()
vCrop = list(view.GetCropRegionShapeManager().GetCropShape())[0]
vCropPointsX = []
vCropPointsY = []
for x in vCrop:
minX = min(vCropPointsX)
minY = min(vCropPointsY)
maxX = max(vCropPointsX)
maxY = max(vCropPointsY)           

new_box = BoundingBoxXYZ()
new_box.Min = XYZ(minX, minY, elevation - 10)
new_box.Max = XYZ(maxX, maxY, elevation + 10)
v_name = view.Name
new_iso = DB.View3D.CreateIsometric(doc,threeDTypes[0].Id)
name_param = new_iso.LookupParameter('View Name')
name_param.Set('{} ISOMETRIC'.format(v_name))

This creates a 3D view cropped to the maximum extents of the view. The section box is always orthogonal to project north in the above code, if you want to look into rotated section boxes, you can dive into BoundingBoxXYZ.Transform. · Revit · Transform Property


Yes, you have to create a new section box based on the view range of the view. In the example it has a fixed height, but it is better to use the actual view range.

1 Like

Thank you very much! I will give it a shot today!