✈ Pre-Flight checks
🐞 Describe the bug
Elements which have transformations applied won't get the section box rotated to match the orientation of the object.
See example screenshot of a rotated conveyor (Generic Model), section box isn't rotated.

⌨ Error/Debug Message
DEBUG [pyrevit.revit.selection] Picking elements: Face message: multiple: False world: False
DEBUG [pyrevit.revit.selection] Picked elements are: [<Autodesk.Revit.DB.Reference object at 0x00000000000020A1 [Autodesk.Revit.DB.Reference]>]
DEBUG [pyrevit.revit.selection] Processed return elements are: [<Autodesk.Revit.DB.PlanarFace object at 0x00000000000020A2 [Autodesk.Revit.DB.PlanarFace]>]
♻️ To Reproduce
No response
⏲️ Expected behavior
I managed to fix this with the help of ChatGPT for the section box, but there probably is a better way to implement this.
For the Orient view it would be great to have the option to not change the workplane.
solution that works for me:
def orientsectionbox(view):
try:
# Pick the first face to define the first workplane
with forms.WarningBar(title='Pick first reference face of an object:'):
reference1 = revit.uidoc.Selection.PickObject(UI.Selection.ObjectType.Face, "Pick the first face to define the first workplane")
# Get the geometry object from the reference (this gives us the face)
geometry_object1 = revit.doc.GetElement(reference1.ElementId).GetGeometryObjectFromReference(reference1)
# Get the section box
box = view.GetSectionBox()
# Check if the element is a family instance (like generic model)
element = revit.doc.GetElement(reference1.ElementId)
if isinstance(element, DB.FamilyInstance):
# Get the transform of the family instance (converts local to world coordinates)
transform = element.GetTransform()
# Get the face normal in local coordinates
local_normal = geometry_object1.ComputeNormal(DB.UV(0, 0)).Normalize()
# Apply the transform to convert normal to world coordinates
world_normal = transform.OfVector(local_normal).Normalize()
norm = world_normal
else:
# For non-family instances, just use the face normal directly
norm = geometry_object1.ComputeNormal(DB.UV(0, 0)).Normalize()
boxNormal = box.Transform.Basis[0].Normalize()
angle = norm.AngleTo(boxNormal)
axis = DB.XYZ(0, 0, 1.0)
origin = DB.XYZ(box.Min.X + (box.Max.X - box.Min.X) / 2,
box.Min.Y + (box.Max.Y - box.Min.Y) / 2, 0.0)
if norm.Y * boxNormal.X < 0:
rotate = DB.Transform.CreateRotationAtPoint(axis, Math.PI / 2 - angle, origin)
else:
rotate = DB.Transform.CreateRotationAtPoint(axis, angle, origin)
box.Transform = box.Transform.Multiply(rotate)
with revit.Transaction('Orient Section Box to Face'):
view.SetSectionBox(box)
revit.uidoc.RefreshActiveView()
except Exception as ex:
forms.alert('Error: {0}'.format(str(ex)))
🖥️ Hardware and Software Setup (please complete the following information)
==> Registered Clones (full git repos)
==> Registered Clones (deployed from archive/image)
master | Branch: "master" | Version: "5.0.1.25051+1239" | Path: "C:\Program Files\pyRevit-Master"
==> Attachments
master | Product: "2024.3.1" | Engine: DEFAULT (2712) | Path: "C:\Program Files\pyRevit-Master" | AllUsers
master | Product: "Autodesk Revit 2022" | Engine: DEFAULT (2712) | Path: "C:\Program Files\pyRevit-Master" | AllUsers
==> Installed Extensions
MyFirstExtension | Type: Unknown | Repo: "" | Installed: "C:\Users\XX\Documents\MyExtensions\MyFirstExtension.extension"
==> Default Extension Search Path
C:\Users\XX\AppData\Roaming\pyRevit\Extensions
==> Extension Search Paths
C:\Users\XX\Documents\MyExtensions
==> Extension Sources - Default
https://github.com/pyrevitlabs/pyRevit/raw/master/extensions/extensions.json
==> Extension Sources - Additional
==> Installed Revits
2024.3.1 | Version: 24.3.10.22 | Build: 20241105_1515(x64) | Language: 1033 | Path: "C:\Program Files\Autodesk\Revit 2024\"
Autodesk Revit 2022 | Version: 22.1.80.32 | Build: 20241107_1515(x64) | Language: 1033 | Path: "C:\Program Files\Autodesk\Revit 2022\"
==> Running Revit Instances
PID: 15788 | 2024.3.1 | Version: 24.3.10.22 | Build: 20241105_1515(x64) | Language: 0 | Path: "C:\Program Files\Autodesk\Revit 2024"
==> User Environment
Microsoft Windows 10 [Version 10.0.22631]
Executing User:
Active User:
Admin Access: No
%APPDATA%: "C:\Users\XX\AppData\Roaming"
Latest Installed .Net Framework: 8.0.3
No .Net Target Packs are installed.
No .Net-Core Target Packs are installed.
pyRevit CLI v5.0.1.25051+1239.a19f9a76cf00d7256cf522f5ec874fea9dd0baa8
Additional context
No response
✈ Pre-Flight checks
🐞 Describe the bug
Elements which have transformations applied won't get the section box rotated to match the orientation of the object.
See example screenshot of a rotated conveyor (Generic Model), section box isn't rotated.
⌨ Error/Debug Message
♻️ To Reproduce
No response
⏲️ Expected behavior
I managed to fix this with the help of ChatGPT for the section box, but there probably is a better way to implement this.
For the Orient view it would be great to have the option to not change the workplane.
solution that works for me:
🖥️ Hardware and Software Setup (please complete the following information)
Additional context
No response