Skip to content

Commit 8b9bbd8

Browse files
committed
Refactor Section Box Navigator scripts for improved error handling and code clarity. Updated UI elements to handle empty unit labels gracefully, optimized bounding box retrieval, and streamlined grid sorting logic.
Fixed button hovering
1 parent 70af06b commit 8b9bbd8

File tree

5 files changed

+23
-14
lines changed

5 files changed

+23
-14
lines changed

extensions/pyRevitTools.extension/pyRevit.tab/Modify.panel/3D.pulldown/Section Box Navigator.pushbutton/SectionBoxNavigator.xaml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,23 @@
77
<Style TargetType="Button">
88
<Setter Property="BorderThickness" Value="0"/>
99
<Setter Property="Height" Value="30"/>
10+
<Setter Property="Background" Value="#E0E0E0"/>
1011
<Setter Property="Template">
1112
<Setter.Value>
1213
<ControlTemplate TargetType="Button">
13-
<Border Background="{TemplateBinding Background}"
14+
<Border x:Name="border" Background="{TemplateBinding Background}"
1415
CornerRadius="5"
1516
Padding="{TemplateBinding Padding}">
1617
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/>
1718
</Border>
19+
<ControlTemplate.Triggers>
20+
<Trigger Property="IsMouseOver" Value="True">
21+
<Setter TargetName="border" Property="Background" Value="#B0D0FF"/>
22+
</Trigger>
23+
<Trigger Property="IsPressed" Value="True">
24+
<Setter TargetName="border" Property="Background" Value="#90B0E0"/>
25+
</Trigger>
26+
</ControlTemplate.Triggers>
1827
</ControlTemplate>
1928
</Setter.Value>
2029
</Setter>

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -203,11 +203,11 @@ def __init__(self, xaml_file_name):
203203
"Length Label (adjust in Project Units): \n" + length_unit_label
204204
)
205205
self.txtLevelNudgeAmount.Text = str(round(default_nudge_value, 3))
206-
self.txtLevelNudgeUnit.Text = length_unit_symbol_label
206+
self.txtLevelNudgeUnit.Text = length_unit_symbol_label or ""
207207
self.txtExpandAmount.Text = str(round(default_nudge_value, 3))
208-
self.txtExpandUnit.Text = length_unit_symbol_label
208+
self.txtExpandUnit.Text = length_unit_symbol_label or ""
209209
self.txtGridNudgeAmount.Text = str(round(default_nudge_value, 3))
210-
self.txtGridNudgeUnit.Text = length_unit_symbol_label
210+
self.txtGridNudgeUnit.Text = length_unit_symbol_label or ""
211211

212212
self.update_info()
213213
self.update_grid_status()
@@ -791,7 +791,7 @@ def do_align_to_view(self, params):
791791
if not elements:
792792
self.show_status_message(1, "No cropbox or elements found to extend scopebox to", "error")
793793
return
794-
boxes = [el.get_BoundingBox(source_view) for el in elements]
794+
boxes = [b for b in [el.get_BoundingBox(source_view) for el in elements] if b]
795795
min_x = min(b.Min.X for b in boxes if b)
796796
min_y = min(b.Min.Y for b in boxes if b)
797797
max_x = max(b.Max.X for b in boxes if b)

extensions/pyRevitTools.extension/pyRevit.tab/Modify.panel/3D.pulldown/Section Box Navigator.pushbutton/sectionbox_actions.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,6 @@ def align_to_face(doc, uidoc):
7474
if not isinstance(current_view, DB.View3D):
7575
return
7676
try:
77-
world_normal = None
78-
7977
with forms.WarningBar(title="Pick a face on a solid object"):
8078
reference = uidoc.Selection.PickObject(
8179
UI.Selection.ObjectType.PointOnElement,

extensions/pyRevitTools.extension/pyRevit.tab/Modify.panel/3D.pulldown/Section Box Navigator.pushbutton/sectionbox_geometry.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ def get_section_box_info(view, datafilename):
1414
view_boxes = script.load_data(datafilename)
1515
except Exception:
1616
return None
17-
view_id_value = get_elementid_value(view.Id)
18-
if view_id_value not in view_boxes:
19-
return None
20-
bbox_data = view_boxes[view_id_value]
17+
view_id_value = get_elementid_value(view.Id)
18+
bbox_data = view_boxes.get(view_id_value)
19+
if not bbox_data:
20+
return None
2121
section_box = revit.deserialize(bbox_data)
2222
else:
2323
section_box = view.GetSectionBox()

extensions/pyRevitTools.extension/pyRevit.tab/Modify.panel/3D.pulldown/Section Box Navigator.pushbutton/sectionbox_navigation.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def get_all_levels(doc, include_linked=False):
2525
levels.append(lvl_host_elev)
2626

2727
# Sort by elevation (transformed if linked)
28-
levels = sorted(levels, key=lambda x: getattr(x, 'Elevation', x.Elevation))
28+
levels = sorted(levels, key=lambda x: x.Elevation)
2929
return levels
3030

3131

@@ -144,13 +144,15 @@ def find_next_grid_in_direction(start_point, direction_vector, grids, tolerance)
144144

145145
for grid in grids:
146146
try:
147-
# Handle both regular Grid and LinkedGrid objects / Exception on multi segment grids
147+
# Handle LinkedGrid objects (has Curve attribute)
148148
if hasattr(grid, 'Curve'):
149149
curve = grid.Curve
150+
# Handle regular DB.Grid objects (has Element.Curve)
150151
elif hasattr(grid, 'Element'):
151152
curve = grid.Element.Curve
152153
else:
153-
curve = grid.Curve # Regular DB.Grid
154+
# Regular DB.Grid - access Curve directly
155+
curve = grid.Curve
154156

155157
if not curve or not isinstance(curve, DB.Line):
156158
continue

0 commit comments

Comments
 (0)