Skip to content

Commit 43bba1d

Browse files
authored
Merge pull request #2936 from Wurschdhaud/chore-cleanup-sb
chore: cleanup sb navigator
2 parents a9a7fad + ca24489 commit 43bba1d

File tree

3 files changed

+19
-43
lines changed

3 files changed

+19
-43
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
22
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
3-
Title="Section Box Navigator" Height="670" Width="600"
3+
Title="Section Box Navigator" Height="635" Width="560"
44
ShowInTaskbar="False" Topmost="True"
55
ScrollViewer.VerticalScrollBarVisibility="Disabled">
66
<Window.Resources>
@@ -368,7 +368,7 @@
368368
<StackPanel Orientation="Horizontal" Margin="5">
369369
<CheckBox x:Name="chkPreview" Content="Show preview on hover"
370370
Margin="5" IsChecked="True"/>
371-
<CheckBox x:Name="chkAutoupdate" Content="Autoupdate UI on Events"
371+
<CheckBox x:Name="chkAutoupdate" Content="Update UI on Events"
372372
Margin="5" IsChecked="True"/>
373373
<CheckBox x:Name="chkIncludeLinks" Content="Include Linked Levels and Grids"
374374
Margin="5" IsChecked="False"

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

Lines changed: 16 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
from pyrevit.revit import events
88
from pyrevit.compat import get_elementid_value_func
99
from pyrevit import DB, UI
10-
from pyrevit import traceback
1110

1211
from sectionbox_navigation import (
1312
get_all_levels,
@@ -49,7 +48,6 @@
4948
length_unit_symbol_label = None
5049
if not length_unit_symbol.Empty():
5150
length_unit_symbol_label = DB.LabelUtils.GetLabelForSymbol(length_unit_symbol)
52-
ufu = DB.UnitFormatUtils
5351

5452
DEFAULT_NUDGE_VALUE_MM = 500.0
5553
default_nudge_value = DB.UnitUtils.Convert(
@@ -72,7 +70,7 @@ def create_preview_mesh(section_box, color):
7270
)
7371
return mesh
7472
except Exception:
75-
logger.error("Error creating preview mesh: {}".format(traceback.format_exc()))
73+
logger.exception("Error creating preview mesh.")
7674
return None
7775

7876

@@ -126,6 +124,10 @@ def create_adjusted_box(
126124
return new_box
127125

128126

127+
def format_length_value(value):
128+
return DB.UnitFormatUtils.Format(doc.GetUnits(), DB.SpecTypeId.Length, value, False)
129+
130+
129131
# --------------------
130132
# Event Handler
131133
# --------------------
@@ -266,13 +268,9 @@ def update_info(self):
266268
)
267269

268270
if top_level_elevation:
269-
top_level_elevation = ufu.Format(
270-
doc.GetUnits(), DB.SpecTypeId.Length, top_level_elevation, False
271-
)
271+
top_level_elevation = format_length_value(top_level_elevation)
272272
if bottom_level_elevation:
273-
bottom_level_elevation = ufu.Format(
274-
doc.GetUnits(), DB.SpecTypeId.Length, bottom_level_elevation, False
275-
)
273+
bottom_level_elevation = format_length_value(bottom_level_elevation)
276274

277275
# Update top info
278276
if top_level:
@@ -282,9 +280,7 @@ def update_info(self):
282280
else:
283281
self.txtTopLevel.Text = "Top: No level above"
284282

285-
top = ufu.Format(
286-
doc.GetUnits(), DB.SpecTypeId.Length, transformed_max.Z, False
287-
)
283+
top = format_length_value(transformed_max.Z)
288284
self.txtTopPosition.Text = "Position: {}".format(top)
289285

290286
# Update bottom info
@@ -295,13 +291,11 @@ def update_info(self):
295291
else:
296292
self.txtBottomLevel.Text = "Bottom: No level below"
297293

298-
bottom = ufu.Format(
299-
doc.GetUnits(), DB.SpecTypeId.Length, transformed_min.Z, False
300-
)
294+
bottom = format_length_value(transformed_min.Z)
301295
self.txtBottomPosition.Text = "Position: {}".format(bottom)
302296

303297
except Exception:
304-
logger.error("Error updating info: {}".format(traceback.format_exc()))
298+
logger.exception("Error updating info.")
305299

306300
def show_status_message(self, column, message, message_type="info"):
307301
"""
@@ -608,9 +602,8 @@ def do_level_move(self, params):
608602
)
609603
else:
610604
# Nudge mode - show nudge amount
611-
nudge_display = ufu.Format(
612-
doc.GetUnits(), DB.SpecTypeId.Length, abs(nudge_amount), False
613-
)
605+
nudge_display = format_length_value(abs(nudge_amount))
606+
614607
self.show_status_message(
615608
1,
616609
"Nudged {} by {} {}".format(target, nudge_display, movement),
@@ -634,9 +627,7 @@ def do_expand_shrink(self, params):
634627
max_z_change=adjustment,
635628
):
636629
# Success - show informative message
637-
amount_display = ufu.Format(
638-
doc.GetUnits(), DB.SpecTypeId.Length, amount, False
639-
)
630+
amount_display = format_length_value(amount)
640631
operation = "Expanded" if is_expand else "Shrunk"
641632
self.show_status_message(
642633
3,
@@ -806,9 +797,8 @@ def do_grid_move(self, params):
806797
)
807798
else:
808799
# Nudge mode
809-
nudge_display = ufu.Format(
810-
doc.GetUnits(), DB.SpecTypeId.Length, nudge_amount, False
811-
)
800+
nudge_display = format_length_value(nudge_amount)
801+
812802
direction_display = cardinal_dir.upper()
813803
self.show_status_message(
814804
2,
@@ -1365,20 +1355,6 @@ def btn_align_box_to_face_click(self, sender, e):
13651355
self.event_handler.parameters = self.pending_action
13661356
self.ext_event.Raise()
13671357

1368-
def btn_refresh_click(self, sender, e):
1369-
"""Manually refresh the information."""
1370-
self.all_levels = get_all_levels(doc, self.chkIncludeLinks.IsChecked)
1371-
self.all_grids = get_all_grids(doc, self.chkIncludeLinks.IsChecked)
1372-
self.update_info()
1373-
# Only update status if there's no current message (i.e., status is "Ready" or empty)
1374-
if self.txtGridStatus.Text == "..." or self.txtGridStatus.Text == "-":
1375-
self.update_grid_status()
1376-
if (
1377-
self.txtExpandActionsStatus.Text == "..."
1378-
or self.txtExpandActionsStatus.Text == "-"
1379-
):
1380-
self.update_expand_actions_status()
1381-
13821358
def chkIncludeLinks_checked(self, sender, e):
13831359
"""Refresh levels and grids when checkbox is toggled."""
13841360
self.all_levels = get_all_levels(doc, self.chkIncludeLinks.IsChecked)
@@ -1500,7 +1476,7 @@ def form_closed(self, sender, args):
15001476
logger.warning("Error refreshing view: {}".format(ex))
15011477

15021478
except Exception:
1503-
logger.error("Error during cleanup: {}".format(traceback.format_exc()))
1479+
logger.exception("Error during cleanup.")
15041480

15051481

15061482
# ---------

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ def find_next_grid_in_direction(start_point, direction_vector, grids, tolerance)
153153
else:
154154
# Regular DB.Grid - access Curve directly
155155
curve = grid.Curve
156-
156+
157157
if not curve or not isinstance(curve, DB.Line):
158158
continue
159159
except (AttributeError, Exception):

0 commit comments

Comments
 (0)