from Autodesk.Revit.DB import *
doc = __revit__.ActiveUIDocument.Document
active_view = doc.ActiveView
active_level = doc.ActiveView.GenLevel
view_types = FilteredElementCollector(doc).OfClass(ViewFamilyType).ToElements()
view_types_sections = [vt for vt in view_types if vt.ViewFamily == ViewFamily.Section]
view_type_section = view_types_sections[0]
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
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
curvedir = fc * vector.Normalize()
t = Transform.Identity
t.Origin = origin
t.BasisX = curvedir
t.BasisY = XYZ.BasisZ
t.BasisZ = curvedir.CrossProduct(XYZ.BasisZ)
sectionBox = BoundingBoxXYZ()
sectionBox.Transform = t
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)
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'