Skip to content

Commit 1968e1d

Browse files
committed
Handle toggle and hide for 2d views
1 parent c75d8f3 commit 1968e1d

File tree

1 file changed

+27
-11
lines changed

1 file changed

+27
-11
lines changed

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

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -968,28 +968,44 @@ def do_align_to_3d_view(self, params):
968968
return
969969

970970
def do_toggle(self):
971-
"""Toggle section box."""
972-
was_active = self.current_view.IsSectionBoxActive
973-
toggle(doc, DATAFILENAME)
974-
# Check new state
975-
is_now_active = self.current_view.IsSectionBoxActive
971+
"""Toggle section or crop box."""
972+
if isinstance(self.current_view, DB.View3D):
973+
was_active = self.current_view.IsSectionBoxActive
974+
toggle(doc, DATAFILENAME)
975+
is_now_active = self.current_view.IsSectionBoxActive
976+
elif is_2d_view(self.current_view):
977+
was_active = self.current_view.CropBoxActive
978+
with revit.Transaction("Toggle CropBox Active State"):
979+
self.current_view.CropBoxActive = not was_active
980+
is_now_active = self.current_view.CropBoxActive
981+
else:
982+
return
976983
if was_active != is_now_active:
977984
state = "activated" if is_now_active else "deactivated"
978-
self.show_status_message(3, "Section box {}".format(state), "success")
985+
self.show_status_message(3, "Box {}".format(state), "success")
979986
else:
980-
self.show_status_message(3, "Section box toggle failed", "error")
987+
self.show_status_message(3, "Box toggle failed", "error")
981988

982989
def do_hide(self):
983-
"""Hide or Unhide section box."""
990+
"""Hide or Unhide section or crop box."""
984991
try:
985-
was_hidden = hide(doc)
992+
if isinstance(self.current_view, DB.View3D):
993+
was_hidden = hide(doc)
994+
elif is_2d_view(self.current_view):
995+
was_hidden = self.current_view.CropBoxVisible
996+
with revit.Transaction("Toggle CropBox Visibility"):
997+
self.current_view.CropBoxVisible = not was_hidden
998+
else:
999+
return
9861000
state = "hidden" if not was_hidden else "unhidden"
987-
self.show_status_message(3, "Section box {}".format(state), "success")
1001+
self.show_status_message(3, "Box {}".format(state), "success")
9881002
except Exception:
989-
self.show_status_message(3, "Error in Section box visibility", "error")
1003+
self.show_status_message(3, "Error in Box visibility", "error")
9901004

9911005
def do_align_to_face(self):
9921006
"""Align to face"""
1007+
if not isinstance(self.current_view, DB.View3D):
1008+
return
9931009
try:
9941010
align_to_face(doc, uidoc)
9951011
self.show_status_message(3, "Section box aligned to face", "success")

0 commit comments

Comments
 (0)