Create View: Section

# -*- coding: utf-8 -*-
#⬇ IMPORTS
from Autodesk.Revit.DB import *

#📦 VARIABLES
doc          = __revit__.ActiveUIDocument.Document
active_view  = doc.ActiveView
active_level = doc.ActiveView.GenLevel

#🎴 ALL VIEW TYPES
view_types = FilteredElementCollector(doc).OfClass(ViewFamilyType).ToElements()

#🔎 FILTER VIEW TYPES
view_types_sections = [vt for vt in view_types if vt.ViewFamily == ViewFamily.Section]
view_type_section   = view_types_sections[0]

#🟦 BOUNDING BOX
origin   = XYZ(5,5,0)
pt_start = XYZ(0,0,0)
pt_end   = XYZ(10,10,0)
vector   = pt_end - pt_start

offset = 5
W = 5
H = 5
D = 5

# SECTION - DIRECTION
fc = -1
if pt_start.X > pt_end.X or (pt_start.X == pt_end.X and pt_start.Y < pt_end.Y):
    fc = 1

# SECTION - ORIENTATION
curvedir = fc * vector.Normalize()

t        = Transform.Identity
t.Origin = origin
t.BasisX = curvedir
t.BasisY = XYZ.BasisZ
t.BasisZ = curvedir.CrossProduct(XYZ.BasisZ)

# SECTION - CROPBOX
sectionBox           = BoundingBoxXYZ()
sectionBox.Transform = t                            #apply orientation
sectionBox.Min       = XYZ(W*-0.5 -offset, 0 -offset, D*-0.5 -offset)
sectionBox.Max       = XYZ(W* 0.5 +offset, H +offset, D* 0.5 +offset)


#🎯 Create Structural Plan
with Transaction(doc,'Create Structural Plan') as t:
    t.Start()
    view_section = ViewSection.CreateSection(doc, view_type_section.Id, sectionBox)
    t.Commit()

__author__ = '🙋‍♂️ Erik Frits'

⌨️ Happy Coding!
Erik Frits