-
Notifications
You must be signed in to change notification settings - Fork 1
/
Launcher Main Routine.ahk
1081 lines (1000 loc) · 30.4 KB
/
Launcher Main Routine.ahk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
MainRoutine:
gosub, GetProjectInfo
if audit
gosub, GetAuditInfo
gosub, FindRevit
gosub, FindMonitor
gosub, LaunchSplash
gosub, ExploreLaunch
if detach
{
LaunchUpdate("Detaching the Revit " . pVersion . " Model")
gosub, OpenRevit
gosub, OpenDialog
gosub, SelectCentral
gosub, DetachClick
gosub, OpenProject
gosub, DetachWait
gosub, MainRoutineClose
}
else if workset
{
LaunchUpdate("Creating local...")
gosub, LocalBackup
gosub, LocalCreate
LaunchUpdate("Launching Revit " . pVersion . " with Specify")
gosub, OpenRevit
gosub, OpenDialog
gosub, SelectLocalWorkset
gosub, WorksetClick
gosub, OpenProject
gosub, WorksetWait
gosub, LocalWait
gosub, MainRoutineClose
}
else if (workset and detach)
{
LaunchUpdate("Launching Revit " . pVersion . " with Specify")
gosub, OpenRevit
gosub, OpenDialog
gosub, SelectLocalWorkset
gosub, WorksetClick
gosub, DetachClick
gosub, OpenProject
gosub, WorksetWait
gosub, DetachWait
gosub, MainRoutineClose
}
else if audit
{
LaunchUpdate("Creating central backup...")
gosub, AuditBackup
LaunchUpdate("Auditing a Revit " . pVersion . " Model")
gosub, OpenRevit
gosub, OpenDialog
gosub, SelectCentral
gosub, AuditClick
gosub, SelectCentral
gosub, OpenProject
gosub, CloseModel
gosub, SaveAsCentral
LaunchUpdate("Creating local...")
gosub, LocalCreate
LaunchUpdate("Launching the Revit " . pVersion . " Model")
gosub, SelectLocal
gosub, OpenProject
gosub, LocalWait
gosub, SyncRelease
gosub, CloseModel
gosub, MainRoutineClose
}
else
{
LaunchUpdate("Creating local...")
gosub, LocalBackup
gosub, LocalCreate
LaunchUpdate("Launching the Revit " . pVersion . " Model")
gosub, SelectLocal
gosub, OpenProject
gosub, LocalWait
gosub, CloseModel
}
return
GetProjectInfo:
DebugMe("GetProjectInfo")
iniCentral := class_EasyIni(iniPathCentral)
pNumber := iniCentral [projectID].Number
pName := iniCentral [projectID].Name
pNameShort := iniCentral [projectID].NameShort
pVersion := iniCentral [projectID].Version
pCentral := iniCentral [projectID].Central
workingFolder := iniCentral [projectID].WorkingFolder
IfNotExist, %pCentral% ;Check if project is setup correctly
{
PrettyMsg("The central file does not exist:`n`n" . pCentral . "`n`nPlease see " . bimGuy . " for assistance")
LogMe("Launcher", "Error", "Locating Central", projectID, pCentral)
ReloadMe()
}
revitUser = %A_Username% ;Users computer username
projectFolder = %localFolder%\%projectID% %pNameShort% ;Project folder name
localFile = %projectID% %pNameShort% LOCAL %revitUser% ;Local file name no extension
localPath = %projectFolder%\%localFile%.rvt ;Local file name & path
return
GetAuditInfo:
DebugMe("GetAuditInfo")
SplitPath, pCentral, centralFileName, centralFileDir, , centralBackupName
centralBackupName := centralBackupName . "_backup"
FormatTime, auditDate, , yyyy-MM-dd
auditArchiveDir := workingFolder . "\Archive\" . auditDate . " Pre-audit Backup"
centralFileBackupDir := centralFileDir . "\" . centralBackupName
auditError := 0
LogMe("Launcher", "Audit", pCentral)
return
FindRevit:
DebugMe("")
;Find the path to the correct Revit flavor depending on the version read from the ini file
if !detach
{
IfWinExist, %localFile%.rvt ;Check to see if the file is already open
{
WinActivate
WinMaximize
if audit
{
PrettyMsg("You have a local file open for the central model you are trying to audit. Please close """ . localFile . ".rvt"" and attempt the audit again.")
Gui, AuditModel:Show
Gui, Launch:Destroy
LogMe("Launcher", "Error", "Audit Fail", "Open Local File", localFile, pCentral)
return
}
PrettyMsg("Revit is already running with the specified local file:`n`n" . localFile . ".rvt")
ReloadMe()
}
}
IfWinExist, %CentralFileName%
{
WinActivate
WinMaximize
PrettyMsg("Open Central File!`n`n" . pCentral . " is currently open. Please close this file immediately and try again.", "alert")
if audit
{
Gui, AuditProject:Show
Gui, Launch:Destroy
LogMe("Launcher", "Error", "Audit Fail", "Open Central File", pCentral)
return
}
LogMe("Launcher", "Error", "Open Central File", pCentral)
ReloadMe()
}
IfEqual, pVersion, 2013
{
revitPath = %A_ProgramFiles%\AutoDesk\Revit 2013\Program\Revit.exe
revitTitle = Autodesk Revit 2013
IfNotExist %revitPath%
{
revitPath = %A_ProgramFiles%\Autodesk\Revit Architecture 2013\Program\Revit.exe
revitTitle = Autodesk Revit Architecture 2013
}
}
Else
{
revitPath = %A_ProgramFiles%\AutoDesk\Revit %pVersion%\Revit.exe
revitTitle = Autodesk Revit %pVersion%
IfNotExist %revitPath%
{
revitPath = %A_ProgramFiles%\Autodesk\ Revit Architecture %pVersion%\Revit.exe
revitTitle = Autodesk Revit Architecture %pVersion%
}
}
IfNotExist, %revitPath%
{
PrettyMsg("Revit " . pVersion . " cannot be found on this computer. Please see " . bimGuy . " for additional information.", , 1)
LogMe("Launcher", "Error", "FindRevit", revitPath, projectID, pVersion)
ReloadMe()
}
return
FindMonitor:
DebugMe("")
; Check for a Worksharing Monitor for the right version of Revit
; Because Workingshing monitor becomes 64bit with version 2015, we have to change folder locations
; ? in variable assignment is a Ternary operator to avoid complicated if/else statement
mon64 := pVersion >= 2015 ? "" : " (x86)"
adesk := pVersion >= 2015 ? "" : " Autodesk"
monitorPath = %A_ProgramFiles%%mon64%\Autodesk\Worksharing Monitor for%adesk% Revit %pVersion%\WorksharingMonitor.exe
monitorTitle = Worksharing Monitor for Autodesk Revit %pVersion%
IfNotExist, %monitorPath%
{
PrettyMsg("The Worksharing Monitor could not be found on your system. Please notify " . bimGuy . " so you can play well with others.")
monitorPath =
LogMe("Launcher", "Error", "FindMonitor", monitorPath, projectID, pVersion)
}
return
ExploreLaunch:
DebugMe("")
If exploreLaunch
{
If workingFolder
Run, "%workingFolder%"
}
return
LaunchSplash:
DebugMe("")
launchWidth := 500
SysGet, pMonitor, MonitorPrimary
SysGet, pMonitor, MonitorWorkArea, %pMonitor%
Gui, Launch:New
Gui, Launch:-Caption AlwaysOnTop
Gui, Launch:Margin, 50, 25
Gui, Launch:Color, DCDCDC
whaLogo(launchWidth, "Launch")
Gui, Launch:Font, cBlack s24, Arial
Gui, Launch:Add, Text, xm yp+45 center w%launchWidth% vLaunchText, Launching...
Gui, Launch:Font, c%guiColor1% s12, Arial
Gui, Launch:Add, Text, yp+40 center w%launchWidth% vLaunchSub, %pNumber% %pName%
Gui, Launch:Font, c%guiColor2% s18, Arial
launchHeight := 150
launchY := pMonitorBottom - launchHeight
Gui, Launch:Show, y%launchY% h%launchHeight%
return
LocalBackup:
DebugMe("")
;Create a backup of the last local created
IfExist, %projectFolder%\%localFile%.4.rvt
{
FileGetTime, backupFour, %projectFolder%\%localFile%.4.rvt, C
weekTwo := A_Now
weekTwo += -14, D
If backupFour > weekTwo
{
FileMove, %projectFolder%\%localFile%.3.rvt, %projectFolder%\%localFile%.4.rvt
}
}
Else
{
IfExist, %projectFolder%\%localFile%.3.rvt
FileMove, %projectFolder%\%localFile%.3.rvt, %projectFolder%\%localFile%.4.rvt
}
IfExist, %projectFolder%\%localFile%.3.rvt
{
FileGetTime, backupThree, %projectFolder%\%localFile%.3.rvt, C
weekOne := A_Now
weekOne += -7, D
If backupThree > weekOne
{
FileMove, %projectFolder%\%localFile%.2.rvt, %projectFolder%\%localFile%.3.rvt
FileSetTime,, %projectFolder%\%localFile%.3.rvt, C
}
}
Else
{
IfExist, %projectFolder%\%localFile%.2.rvt
{
FileMove, %projectFolder%\%localFile%.2.rvt, %projectFolder%\%localFile%.3.rvt
FileSetTime,, %projectFolder%\%localFile%.3.rvt, C
}
}
IfExist, %projectFolder%\%localFile%.1.rvt ;backup of a backup
fileMove, %projectFolder%\%localFile%.1.rvt, %projectFolder%\%localFile%.2.rvt, 1
IfExist, %localPath% ;backup of the local
fileMove, %localPath%, %projectFolder%\%localFile%.1.rvt, 1
return
LocalCreate:
DebugMe("LocalCreate")
FileCopy, %pCentral%, %localPath%, 1
if ErrorLevel ;Check to make sure everything copied correctly
{
LogMe("Launcher", "Error", "LocalCreate", projectID, localPath, pCentral)
PrettyMsg("The local file could not be copied to your computer. Please see your BIM manager for additional information.", "alert", 1)
ReloadMe()
}
AuditBackup:
DebugMe("")
auditArchiveDirTest := auditArchiveDir
n := 0
While FileExist(auditArchiveDirTest)
{
if A_Index > 999
break
n += 1
auditArchiveDirTest := auditArchiveDir . A_Index
}
if (n > 12)
{
if !PrettyMsg("Warning!`n`nThere have been at least " . n . " audit backup folders created already. It is not typical to need to audit your project this frequently. Press ""OK"" if you are sure you want to continue", "alert")
ReloadMe()
}
FileCreateDir, %auditArchiveDirTest%
If ErrorLevel
{
PrettyMsg("Error`n`nWe were unable to create the archive directory for the file being audited`n`n" . pCentral . "`n`nPlease check your project settings in the global project list and try again.", "alert", 1)
LogMe("Launcher", "Audit", "Error creating backup", auditArchiveDir)
}
FileCopy, %pCentral%, %auditArchiveDirTest%
auditError := If ErrorLevel ? auditError + ErrorLevel : auditError
FileCopyDir, %centralFileBackupDir%, %auditArchiveDirTest%\%centralBackupName%
auditError := If ErrorLevel ? auditError + ErrorLevel : auditError
if auditError
{
PrettyMsg("Error`n`nWe were unable to archive the file being audited`n`n" . pCentral . "Contact " . bimGuy . " for additional information", "alert", 1)
ReloadMe()
}
return
OpenRevit:
DebugMe("")
If monitorPath ;Open the worksharing monitor if it exists
Run, %monitorPath%
IfWinExist, ^%revitTitle% ;Check to see if Revit is already running
{
WinActivate
WinMaximize
}
Else
{
Run, %revitPath%, Max, %localPath%
WinWait, ^%revitTitle% - \[Recent Files\]
WinMaximize
}
WinActivate
return
OpenDialog:
DebugMe("OpenDialog")
; Check if Revit's open dialog is open already
IfWinExist, Open, &Detach from Central
WinActivate, Open, &Detach from Central
else
{
Send ^o
WinWait, Project Not Saved Recently,, 1
if !Errorlevel
{
Gui, Launch:Destroy
PrettyMsg("Save your work!`n`nPlease save your current project/family before launching a new one.")
LogMe("Launcher", "Error", "Project Not Saved Dialog", projectID, revitPath, revitTitle, localPath)
ReloadMe("noshow")
}
WinWait, Open, &Detach from Central, 30
If ErrorLevel
{
Gui, Launch:Destroy
PrettyMsg("There seems to be an issue launching your project. Check Revit for any opened dailog boxes and try launching again.`n`nThanks.")
LogMe("Launcher", "Error", "OpenWait", projectID, revitPath, revitTitle, localPath)
ReloadMe("noshow")
}
}
; check that we have focus on Revit's open dialog
openID := 0x0
While (openID = 0x0)
{
if !A_IsCompiled
GuiControl, Launch:, LaunchSub, OpenID Attempt #%attempt%
Sleep 100
WinActivate, Open, &Detach from Central
openID := WinActive("Open", "&Detach from Central")
if A_Index >= 5
{
PrettyMsg(programName . " could not correctly identify your session of Revit. Please try again.`n`nFeel free to contact " . bimGuy . " should this problem persist.")
LogMe("Launcher", "Error", "openID", "projectID", projectID, "revitPath", revitPath, "revitTitle", revitTitle, "localPath", localPath)
ReloadMe()
break
}
}
; get information about Revit's open dialog
ControlGet, fileHwnd, Hwnd,, Edit1, ahk_ID %openID%
ControlGet, folderHwnd, Hwnd,, SysListView321, ahk_ID %openID%
ControlGet, openHwnd, Hwnd,, Button1, ahk_ID %openID%
; Seperate out different routines for detach and audit and workset
;~ if (detach or audit)
;~ fName := pCentral
;~ Else
;~ fName := localPath
SelectLocalWorkset:
StringGetPos, fSplit, fName, `\, r1
fPath := SubStr(fName, 1, fSplit + 1)
fNameShort := SubStr(fName, fSplit + 2)
Control, EditPaste, %localPath%, , ahk_ID %fileHwnd%
ControlClick, Button1, ahk_ID %openID%,, L, 2, NA
Sleep 100
While fNameCheck != %fNameShort%
{
if !A_IsCompiled
GuiControl, Launch:, LaunchSub, Specify %fNameShort% Attempt #%attempt%
WinActivate, Open, &Detach from Central
ControlSend, SysListView321, %fNameShort%, ahk_ID %openID%
Sleep 100
ControlGet, fNameCheck, Line, 1, Edit1, ahk_ID %openID%
if A_Index >= 5
{
PrettyMsg("There was an error while trying to open the project with the specify worksets option. Please try launching your project again.`n`nContact " . bimGuy . " should this problem persist.")
LogMe("Launcher", "Error", "Specify worksets select project", "attempt " . attempt, fName, fNameShort, fNameCheck)
ReloadMe()
return
}
if fNameCheck != %fNameShort%
{
ControlSend, SysListView321, {Down}, Open, &Detach from Central
gosub, SpecifyCheck
}
}
ControlSend, Button1, {Down 6}{Enter}, ahk_ID %openID%
return
SelectLocal:
ControlSend, Edit1, {Ctrl Down}a{Ctrl Up}, ahk_ID %openID%
Control, EditPaste, %localPath%, Edit1, ahk_ID %openID%
return
SelectCentral:
ControlSend, Edit1, {Ctrl Down}a{Ctrl Up}, ahk_ID %openID%
Control, EditPaste, %pCentral%, Edit1, ahk_ID %openID%
return
WorksetWait:
LogMe("Launcher", "workset", projectID, fName, fPath)
WinWait, Opening Worksets,, 60
WinWaitClose, Opening Worksets
return
DetachWait:
WinWait, Detach Model from Central,, 30
LogMe("Launcher", "detach", projectID, fName)
WinWait, Detach Model from Central,, 30
dmcID := WinActive("Detach Model from Central")
If ErrorLevel
{
PrettyMsg("This project did not detach properly.`n`nPlease contact " . bimGuy . " should this problem persist.")
LogMe("Launcher", "Error", "detach", "projectID", projectID, "fName", fName)
ReloadMe("noshow")
}
ControlClick, Button1, ahk_id %dmcID%,, L
return
LocalWait:
LogMe("Launcher", "standard", projectID, fName)
WinWait, Copied Central Model,, 30
If !ErrorLevel
{
Sleep 300
ControlClick, Button1, Copied Central Model,, L, 2, NA
}
return
MainRoutineClose:
Gui, Launch:Destroy
WinActivate, ^%revitTitle%
; Set detach back to global setting
detach := iniLocal.Settings.Detach
ReloadMe("noshow")
return
DetachClick:
DebugMe("DetachClick")
; Click the detach button on the open dialog box
; Repeat until it is actually clicked
Button5State := 0
While !Button5State
{
if A_Index >= 5
{
PrettyMsg("Failed to Detach. This happens from time to time. Please try detaching your model again.")
ReloadMe()
break
}
WinActivate, Open, &Detach from Central
ControlClick, Button5, ahk_ID %openID%,, L
ControlGet, Button5State, Checked,, Button5, ahk_ID %openID%
}
return
AuditClick:
DebugMe("AuditClick")
While !Button4State
{
if A_Index >= 5
{
PrettyMsg("Failed to get into audit mode. Please try again. Should this probelm persist, make sure to notify " . bimGuy, "alert", 1)
ReloadMe()
break
}
WinActivate, Open, &Detach from Central
ControlClick, Button4, ahk_ID %openID%,, L
WinWait, Audit Warning,, 5
if ErrorlLevel
return
ControlClick, Button1, Audit Warning
ControlGet, Button4State, Checked,, Button4, ahk_ID %openID%
}
return
OpenProject:
openState := 0
While WinWai
{
if !A_IsCompiled
GuiControl, Launch:, LaunchSub, Open Attempt #%A_Index%
ControlClick, Button1, ahk_ID %openID%,, L, 2, NA
if A_Index >= 5
{
PrettyMsg("There was an issue opening your model.`n`nPlease contact " . bimGuy . " should this problem perist.")
LogMe("Launcher", "Error", "Open", "Could not click open button", "fName", fName)
ReloadMe()
break
}
WinWaitNotActive, ahk_ID %openID%,, 1
openState := ErrorLevel
}
return
; Main Routine Functions
LaunchUpdate(sText)
{
GuiControl, Launch:, LaunchText, %sText%
}
/*
; ### OLD MAIN ROUTINE ### ;
MainRoutine:
iniCentral := class_EasyIni(iniPathCentral)
pNumber := iniCentral [projectID].Number
pName := iniCentral [projectID].Name
pNameShort := iniCentral [projectID].NameShort
pVersion := iniCentral [projectID].Version
pCentral := iniCentral [projectID].Central
workingFolder := iniCentral [projectID].WorkingFolder
if audit
{
SplitPath, pCentral, centralFileName, centralFileDir, , centralBackupName
centralBackupName := centralBackupName . "_backup"
FormatTime, auditDate, , yyyy-MM-dd
auditArchiveDir := workingFolder . "\Archive\" . auditDate . " Pre-audit Backup"
centralFileBackupDir := centralFileDir . "\" . centralBackupName
auditError := 0
LogMe("Launcher", "Audit", pCentral)
}
IfNotExist, %pCentral% ;Check if project is setup correctly
{
PrettyMsg("The central file does not exist:`n`n" . pCentral . "`n`nPlease see " . bimGuy . " for assistance")
LogMe("Launcher", "Error", "Locating Central", projectID, pCentral)
ReloadMe()
}
revitUser = %A_Username% ;Users computer username
projectFolder = %localFolder%\%projectID% %pNameShort% ;Project folder name
localFile = %projectID% %pNameShort% LOCAL %revitUser% ;Local file name no extension
localPath = %projectFolder%\%localFile%.rvt ;Local file name & path
FindRevit:
;Find the path to the correct Revit flavor depending on the version read from the ini file
if !detach
{
IfWinExist, %localFile%.rvt ;Check to see if the file is already open
{
WinActivate
WinMaximize
if audit
{
PrettyMsg("You have a local file open for the central model you are trying to audit. Please close """ . localFile . ".rvt"" and attempt the audit again.")
Gui, AuditModel:Show
Gui, Launch:Destroy
LogMe("Launcher", "Error", "Audit Fail", "Open Local File", localFile, pCentral)
return
}
PrettyMsg("Revit is already running with the specified local file:`n`n" . localFile . ".rvt")
ReloadMe()
}
}
IfWinExist, %CentralFileName%
{
WinActivate
WinMaximize
PrettyMsg("Open Central File!`n`n" . pCentral . " is currently open. Please close this file immediately and try again.", "alert")
if audit
{
Gui, AuditProject:Show
Gui, Launch:Destroy
LogMe("Launcher", "Error", "Audit Fail", "Open Central File", pCentral)
return
}
LogMe("Launcher", "Error", "Open Central File", pCentral)
ReloadMe()
}
IfEqual, pVersion, 2013
{
revitPath = %A_ProgramFiles%\AutoDesk\Revit 2013\Program\Revit.exe
revitTitle = Autodesk Revit 2013
IfNotExist %revitPath%
{
revitPath = %A_ProgramFiles%\Autodesk\Revit Architecture 2013\Program\Revit.exe
revitTitle = Autodesk Revit Architecture 2013
}
}
Else
{
revitPath = %A_ProgramFiles%\AutoDesk\Revit %pVersion%\Revit.exe
revitTitle = Autodesk Revit %pVersion%
IfNotExist %revitPath%
{
revitPath = %A_ProgramFiles%\Autodesk\ Revit Architecture %pVersion%\Revit.exe
revitTitle = Autodesk Revit Architecture %pVersion%
}
}
IfNotExist, %revitPath%
{
PrettyMsg("Revit " . pVersion . " cannot be found on this computer. Please see " . bimGuy . " for additional information.", , 1)
LogMe("Launcher", "Error", "FindRevit", revitPath, projectID, pVersion)
ReloadMe()
}
FindMonitor:
; Check for a Worksharing Monitor for the right version of Revit
; Because Workingshing monitor becomes 64bit with version 2015, we have to change folder locations
; ? in variable assignment is a Ternary operator to avoid complicated if/else statement
mon64 := pVersion >= 2015 ? "" : " (x86)"
adesk := pVersion >= 2015 ? "" : " Autodesk"
monitorPath = %A_ProgramFiles%%mon64%\Autodesk\Worksharing Monitor for%adesk% Revit %pVersion%\WorksharingMonitor.exe
monitorTitle = Worksharing Monitor for Autodesk Revit %pVersion%
IfNotExist, %monitorPath%
{
PrettyMsg("The Worksharing Monitor could not be found on your system. Please notify " . bimGuy . " so you can play well with others.")
monitorPath =
LogMe("Launcher", "Error", "FindMonitor", monitorPath, projectID, pVersion)
}
DebugMe("LaunchSplash")
Gosub, LaunchSplash
DebugMe("exploreLaunch")
;If the user has the the setting turned on, open the working directory of the project.
If exploreLaunch
{
If workingFolder
Run, "%workingFolder%"
}
If (!detach and !audit)
{
launchStatus = Copying local...
GuiControl, Launch:, LaunchText, %launchStatus%
DebugMe("CreateDir")
;Check if Directory Exists
IfNotExist, %projectFolder%
{
DebugMe("project folder not exist")
if InStr(projectFolder, ".")
{
StringReplace, projectFolderReplace, projectFolder, ., -, All
FileCreateDir, %projectFolderReplace% ;Create a directory if it doesn't already exist
FileMoveDir, %projectFolderReplace%, %projectFolder%
}
else
FileCreateDir, %projectFolder% ;Create a directory if it doesn't already exist
If Errorlevel
{
PrettyMsg("A directory structure could not be created in " . localFolder ".`nPlease contact " . bimGuy, "alert", 1)
LogMe("Launcher", "Error", "Directory Structure Create", localFolder)
ReloadMe()
}
}
LocalBackup:
DebugMe("LocalBackup")
;Create a backup of the last local created
IfExist, %projectFolder%\%localFile%.4.rvt
{
FileGetTime, backupFour, %projectFolder%\%localFile%.4.rvt, C
weekTwo := A_Now
weekTwo += -14, D
If backupFour > weekTwo
{
FileMove, %projectFolder%\%localFile%.3.rvt, %projectFolder%\%localFile%.4.rvt
}
}
Else
{
IfExist, %projectFolder%\%localFile%.3.rvt
FileMove, %projectFolder%\%localFile%.3.rvt, %projectFolder%\%localFile%.4.rvt
}
IfExist, %projectFolder%\%localFile%.3.rvt
{
FileGetTime, backupThree, %projectFolder%\%localFile%.3.rvt, C
weekOne := A_Now
weekOne += -7, D
If backupThree > weekOne
{
FileMove, %projectFolder%\%localFile%.2.rvt, %projectFolder%\%localFile%.3.rvt
FileSetTime,, %projectFolder%\%localFile%.3.rvt, C
}
}
Else
{
IfExist, %projectFolder%\%localFile%.2.rvt
{
FileMove, %projectFolder%\%localFile%.2.rvt, %projectFolder%\%localFile%.3.rvt
FileSetTime,, %projectFolder%\%localFile%.3.rvt, C
}
}
IfExist, %projectFolder%\%localFile%.1.rvt ;backup of a backup
fileMove, %projectFolder%\%localFile%.1.rvt, %projectFolder%\%localFile%.2.rvt, 1
IfExist, %localPath% ;backup of the local
fileMove, %localPath%, %projectFolder%\%localFile%.1.rvt, 1
DebugMe("LocalCreate")
FileCopy, %pCentral%, %localPath%, 1
if ErrorLevel ;Check to make sure everything copied correctly
{
LogMe("Launcher", "Error", "LocalCreate", projectID, localPath, pCentral)
PrettyMsg("The local file could not be copied to your computer. Please see your BIM manager for additional information.", "alert", 1)
ReloadMe()
}
}
; Backup central if in audit mode
if audit
{
launchStatus = Audit: Backing Up Central...
GuiControl, Launch:, LaunchText, %launchStatus%
auditArchiveDirTest := auditArchiveDir
n := 0
While FileExist(auditArchiveDirTest)
{
n += 1
auditArchiveDirTest := auditArchiveDir . A_Index
}
if (n > 12)
{
if !PrettyMsg("Warning!`n`nThere have been at least " . n . " audit backup folders created already. It is not typical to need to audit your project this frequently. Press ""OK"" if you are sure you want to continue", "alert")
ReloadMe()
}
FileCreateDir, %auditArchiveDirTest%
If ErrorLevel
{
PrettyMsg("Error`n`nWe were unable to create the archive directory for the file being audited`n`n" . pCentral . "`n`nPlease check your project settings in the global project list and try again.", "alert", 1)
LogMe("Launcher", "Audit", "Error creating backup", auditArchiveDir)
}
FileCopy, %pCentral%, %auditArchiveDirTest%
auditError := If ErrorLevel ? auditError + ErrorLevel : auditError
FileCopyDir, %centralFileBackupDir%, %auditArchiveDirTest%\%centralBackupName%
auditError := If ErrorLevel ? auditError + ErrorLevel : auditError
if auditError
{
PrettyMsg("Error`n`nWe were unable to archive the file being audited`n`n" . pCentral . "Contact " . bimGuy . " for additional information", "alert", 1)
ReloadMe()
}
}
DebugMe("Launch")
if Detach
launchStatus = Detaching the Revit %pVersion% Model
else if workset
launchStatus = Launching Revit %pVersion% with Specify
else if Audit
launchStatus = Auditing a Revit %pVersion% Model
else
launchStatus = Launching the Revit %pVersion% Model
GuiControl, Launch:, LaunchText, %launchStatus%
;Open Revit with the correct version
If monitorPath ;Open the worksharing monitor if it exists
Run, %monitorPath%
IfWinExist, ^%revitTitle% ;Check to see if Revit is already running
{
WinActivate
WinMaximize
}
Else
{
Run, %revitPath%, Max, %localPath%
WinWait, ^%revitTitle% - \[Recent Files\]
WinMaximize
}
WinActivate
IfWinExist, Open, &Detach from Central
WinActivate, Open, &Detach from Central
else
{
Send ^o
WinWait, Project Not Saved Recently,, 1
if !Errorlevel
{
Gui, Launch:Destroy
PrettyMsg("Save your work!`n`nPlease save your current project/family before launching a new one.")
LogMe("Launcher", "Error", "Project Not Saved Dialog", projectID, revitPath, revitTitle, localPath)
ReloadMe("noshow")
}
WinWait, Open, &Detach from Central, 30
If ErrorLevel
{
Gui, Launch:Destroy
PrettyMsg("There seems to be an issue launching your project. Check Revit for any opened dailog boxes and try launching again.`n`nThanks.")
LogMe("Launcher", "Error", "OpenWait", projectID, revitPath, revitTitle, localPath)
ReloadMe("noshow")
}
}
attempt := 0
gosub, CheckOpenID
if attempt > 5
{
PrettyMsg(programName . " could not correctly identify your session of Revit. Please try again.`n`nFeel free to contact " . bimGuy . " should this problem persist.")
LogMe("Launcher", "Error", "openID", "projectID", projectID, "revitPath", revitPath, "revitTitle", revitTitle, "localPath", localPath)
ReloadMe()
return
}
if openID = 0x0
{
gosub, CheckOpenID
return
}
ControlGet, fileHwnd, Hwnd,, Edit1, ahk_ID %openID%
ControlGet, folderHwnd, Hwnd,, SysListView321, ahk_ID %openID%
ControlGet, openHwnd, Hwnd,, Button1, ahk_ID %openID%
if (detach or audit)
fName := pCentral
Else
fName := localPath
If workset
{
StringGetPos, fSplit, fName, `\, r1
fPath := SubStr(fName, 1, fSplit + 1)
fNameShort := SubStr(fName, fSplit + 2)
Control, EditPaste, %fPath%, , ahk_ID %fileHwnd%
ControlClick, Button1, ahk_ID %openID%,, L, 2, NA
Sleep 100
gosub, SpecifyCheck
ControlSend, Button1, {Down 6}{Enter}, ahk_ID %openID%
}
Else
{
ControlSend, Edit1, {Ctrl Down}a{Ctrl Up}, ahk_ID %openID%
Control, EditPaste, %fName%, Edit1, ahk_ID %openID%
}
If detach
{
attempt := 0
gosub, DetachRecheck
}
If audit
{
attempt := 0
gosub, AuditRecheck
}
attempt := 0
gosub, OpenProject
If workset
{
LogMe("Launcher", "workset", projectID, fName, fPath)
WinWait, Opening Worksets,, 60
WinWaitClose, Opening Worksets
If detach
{
WinWait, Detach Model from Central,, 30
If ErrorLevel
{
PrettyMsg("This project may not have detach properly. Please check to make sure you are not working in the central model.`n`nPlease contact " . bimGuy . " should this problem persist.", "alert", 1)
LogMe("Launcher", "Error", "detach", "specify", "detach message never found", "projectID", projectID, "fName", fName, "fPath", fPath)
ReloadMe("noshow")
}
else
{
WinActivate, Detach Model from Central
dmcID := WinActive("Detach Model from Central")
ControlClick, Button1, ahk_id %dmcID%,, L
IfWinExist, Detach Model from Central ; In case the first method doesn't work
{
ControlClick, Button1, Detach Model from Central,, L
}
}
}
else
{
WinWait, Copied Central Model,, 30
ControlClick, Button1, Copied Central Model,, L, 2, NA
}
Gui, Launch:Destroy
}
Else If detach
{
LogMe("Launcher", "detach", projectID, fName)
WinWait, Detach Model from Central,, 30
dmcID := WinActive("Detach Model from Central")
If ErrorLevel
{
PrettyMsg("This project did not detach properly.`n`nPlease contact " . bimGuy . " should this problem persist.")
LogMe("Launcher", "Error", "detach", "projectID", projectID, "fName", fName)
ReloadMe("noshow")
}
else
{
ControlClick, Button1, ahk_id %dmcID%,, L
}
Gui, Launch:Destroy
}
Else
{
LogMe("Launcher", "standard", projectID, fName)
WinWait, Copied Central Model,, 30
Sleep 300
If !ErrorLevel
ControlClick, Button1, Copied Central Model,, L, 2, NA
Gui, Launch:Destroy
}
WinActivate, ^%revitTitle%
; Set detach back to global setting
detach := iniLocal.Settings.Detach
ReloadMe("noshow")
return
CheckOpenID:
attempt += 1
if !A_IsCompiled
GuiControl, Launch:, LaunchSub, OpenID Attempt #%attempt%
Sleep 100
WinActivate, Open, &Detach from Central
openID := WinActive("Open", "&Detach from Central")
return
OpenProject:
attempt += 1
if !A_IsCompiled
GuiControl, Launch:, LaunchSub, Open Attempt #%attempt%
ControlClick, Button1, ahk_ID %openID%,, L, 2, NA
if attempt > 5
{
PrettyMsg("There was an issue opening your model.`n`nPlease contact " . bimGuy . " should this problem perist.")
LogMe("Launcher", "Error", "Open", "Could not click open button", "fName", fName)
ReloadMe()
return
}
WinWaitNotActive, ahk_ID %openID%,, 1
if ErrorLevel
{
gosub, OpenProject
return
}
return
DetachRecheck:
attempt += 1
if !A_IsCompiled
GuiControl, Launch:, LaunchSub, Detach Attempt #%attempt%
gosub, DetachClick
if attempt > 5
{
PrettyMsg("There was an issue detaching your model.`n`nPlease contact " . bimGuy . " should this problem perist.")
LogMe("Launcher", "Error", "Detach", "Could not check detach button", "fName", fName)
ReloadMe()
return
}
if !Button5State
{
gosub, DetachRecheck
return