Skip to content

Commit 9f37bb6

Browse files
committed
ran psf/black formatter
1 parent 3fabfa8 commit 9f37bb6

File tree

1 file changed

+46
-45
lines changed
  • extensions/pyRevitTools.extension/pyRevit.tab/Modify.panel/3D.pulldown/Orient Section Box To Face.pushbutton

1 file changed

+46
-45
lines changed

extensions/pyRevitTools.extension/pyRevit.tab/Modify.panel/3D.pulldown/Orient Section Box To Face.pushbutton/script.py

Lines changed: 46 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -4,59 +4,60 @@
44
from pyrevit import revit, DB, UI
55
from pyrevit import forms
66

7-
# import Autodesk.Revit
8-
97
import Autodesk.Revit.UI.Selection.ObjectType
108

119
curview = revit.active_view
1210

1311

1412
def orientsectionbox(view):
15-
try:
16-
# Pick face to align to using uidoc.Selection instead of revit.pick_face to get the reference instead of the face
17-
face = revit.uidoc.Selection.PickObject(UI.Selection.ObjectType.Face, 'Pick a face to align to:')
18-
19-
revit.pick_face
13+
try:
14+
# Pick face to align to using uidoc.Selection instead of revit.pick_face to get the reference instead of the face
15+
face = revit.uidoc.Selection.PickObject(
16+
UI.Selection.ObjectType.Face, "Pick a face to align to:"
17+
)
18+
19+
revit.pick_face
20+
21+
# Get the section box
22+
box = view.GetSectionBox()
23+
24+
# Get the geometry object of the reference
25+
element = revit.doc.GetElement(face)
26+
geometry_object = element.GetGeometryObjectFromReference(face)
2027

21-
# Get the section box
22-
box = view.GetSectionBox()
28+
# Check if the object might have a Transformation (by checking if it's Non-Instance)
29+
if isinstance(element, DB.FamilyInstance):
30+
# Get the transform of the family instance (converts local to world coordinates)
31+
transform = element.GetTransform()
32+
# Get the face normal in local coordinates
33+
local_normal = geometry_object.ComputeNormal(DB.UV(0, 0)).Normalize()
34+
# Apply the transform to convert normal to world coordinates
35+
world_normal = transform.OfVector(local_normal).Normalize()
36+
norm = world_normal
37+
else:
38+
norm = geometry_object.ComputeNormal(DB.UV(0, 0)).Normalize()
2339

24-
# Get the geometry object of the reference
25-
element = revit.doc.GetElement(face)
26-
geometry_object = element.GetGeometryObjectFromReference(face)
27-
28-
# Check if the object might have a Transformation (by checking if it's Non-Instance)
29-
if isinstance(element, DB.FamilyInstance):
30-
# Get the transform of the family instance (converts local to world coordinates)
31-
transform = element.GetTransform()
32-
# Get the face normal in local coordinates
33-
local_normal = geometry_object.ComputeNormal(DB.UV(0, 0)).Normalize()
34-
# Apply the transform to convert normal to world coordinates
35-
world_normal = transform.OfVector(local_normal).Normalize()
36-
norm = world_normal
37-
else:
38-
norm = geometry_object.ComputeNormal(DB.UV(0, 0)).Normalize()
39-
40-
# Orient the box
41-
boxNormal = box.Transform.Basis[0].Normalize()
42-
angle = norm.AngleTo(boxNormal)
43-
axis = DB.XYZ(0, 0, 1.0)
44-
origin = DB.XYZ(box.Min.X + (box.Max.X - box.Min.X) / 2,
45-
box.Min.Y + (box.Max.Y - box.Min.Y) / 2, 0.0)
46-
if norm.Y * boxNormal.X < 0:
47-
rotate = \
48-
DB.Transform.CreateRotationAtPoint(axis, Math.PI / 2 - angle,
49-
origin)
50-
else:
51-
rotate = DB.Transform.CreateRotationAtPoint(axis,
52-
angle,
53-
origin)
54-
box.Transform = box.Transform.Multiply(rotate)
55-
with revit.Transaction("Orient Section Box to Face"):
56-
view.SetSectionBox(box)
57-
revit.uidoc.RefreshActiveView()
58-
except Exception as ex:
59-
forms.alert('Error: {0}'.format(str(ex)))
40+
# Orient the box
41+
boxNormal = box.Transform.Basis[0].Normalize()
42+
angle = norm.AngleTo(boxNormal)
43+
axis = DB.XYZ(0, 0, 1.0)
44+
origin = DB.XYZ(
45+
box.Min.X + (box.Max.X - box.Min.X) / 2,
46+
box.Min.Y + (box.Max.Y - box.Min.Y) / 2,
47+
0.0,
48+
)
49+
if norm.Y * boxNormal.X < 0:
50+
rotate = DB.Transform.CreateRotationAtPoint(
51+
axis, Math.PI / 2 - angle, origin
52+
)
53+
else:
54+
rotate = DB.Transform.CreateRotationAtPoint(axis, angle, origin)
55+
box.Transform = box.Transform.Multiply(rotate)
56+
with revit.Transaction("Orient Section Box to Face"):
57+
view.SetSectionBox(box)
58+
revit.uidoc.RefreshActiveView()
59+
except Exception as ex:
60+
forms.alert("Error: {0}".format(str(ex)))
6061

6162

6263
if isinstance(curview, DB.View3D) and curview.IsSectionBoxActive:

0 commit comments

Comments
 (0)