33from math import pi , atan , sqrt
44from pyrevit import HOST_APP , revit , forms , script
55from pyrevit import UI , DB
6- from pyrevit .framework import System
76from Autodesk .Revit .Exceptions import InvalidOperationException
87
98logger = script .get_logger ()
4241LINE_COLOR_DIAG = DB .ColorWithTransparency (200 , 200 , 0 , 0 ) # Dark Yellow
4342CUBE_COLOR = DB .ColorWithTransparency (255 , 165 , 0 , 50 ) # Orange
4443
45- WINDOW_POSITION = "measure_window_pos"
46-
4744
4845def calculate_distances (point1 , point2 ):
4946 """Calculate dx, dy, dz, diagonal distance, and slope angle between two points.
@@ -306,24 +303,7 @@ def __init__(self, xaml_file_name):
306303
307304 # Handle window close event
308305 self .Closed += self .window_closed
309-
310- try :
311- pos = script .load_data (WINDOW_POSITION , this_project = False )
312- all_bounds = [s .WorkingArea for s in System .Windows .Forms .Screen .AllScreens ]
313- x , y = pos ["Left" ], pos ["Top" ]
314- visible = any (
315- (b .Left <= x <= b .Right and b .Top <= y <= b .Bottom ) for b in all_bounds
316- )
317- if not visible :
318- raise Exception
319- self .WindowStartupLocation = System .Windows .WindowStartupLocation .Manual
320- self .Left = pos .get ("Left" , 200 )
321- self .Top = pos .get ("Top" , 150 )
322- except Exception :
323- self .WindowStartupLocation = (
324- System .Windows .WindowStartupLocation .CenterScreen
325- )
326-
306+ script .restore_window_position (self )
327307 self .Show ()
328308
329309 # Automatically start the first measurement
@@ -332,9 +312,7 @@ def __init__(self, xaml_file_name):
332312 def window_closed (self , sender , args ):
333313 """Handle window close event - copy history to clipboard, cleanup DC3D server and visual aids."""
334314 global dc3d_server
335- new_pos = {"Left" : self .Left , "Top" : self .Top }
336- script .store_data (WINDOW_POSITION , new_pos , this_project = False )
337-
315+ script .save_window_position (self )
338316 # Copy measurement history to clipboard before cleanup
339317 try :
340318 if measurement_history :
0 commit comments