-
Notifications
You must be signed in to change notification settings - Fork 5
/
JavaScripts.xml
2201 lines (2201 loc) · 349 KB
/
JavaScripts.xml
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
<?xml version="1.0" encoding="windows-1252"?>
<RefData version="1.0" exporter="EA.25">
<DataSet name="Automation Scripts" table="t_script" filter="ScriptName='#ScriptName#' and ScriptCategory='#ScriptCategory#'" stoplist=";ScriptID;">
<DataRow>
<Column name="ScriptID" value="1"/>
<Column name="ScriptCategory" value="3955A83E-9E54-4810-8053-FACC68CD4782"/>
<Column name="ScriptName" value="{6F2AAA79-A828-415b-8FCF-6C374FC7F45B}"/>
<Column name="Notes" value="<Group Type="NORMAL" Notes=""/>
"/>
<Column name="Script" value="JavaScriptLib"/>
</DataRow>
<DataRow>
<Column name="ScriptID" value="2"/>
<Column name="ScriptCategory" value="605A62F7-BCD0-4845-A8D0-7DC45B4D2E3F"/>
<Column name="ScriptName" value="{FE229079-B2C7-4348-AD84-48384C15754E}"/>
<Column name="ScriptAuthor" value="{6F2AAA79-A828-415b-8FCF-6C374FC7F45B}"/>
<Column name="Notes" value="<Script Name="JavaScript-EAConstants" Type="Internal" Language="JavaScript"/>
"/>
<Column name="Script" value="/*
 * Script Name: JavaScript-EAConstants.js
 * Author: Sparx Systems
 * Purpose:Provides constant values for the Enterprise Architect automation API. 
 * Date: 2010-05-31
 */

// =================================================================================================
// ObjectType
// See https://www.sparxsystems.com/enterprise_architect_user_guide/15.1/automation/objecttypeenum.html
// =================================================================================================
var otNone = 0;
var otProject = 1;
var otRepository = 2;
var otCollection = 3;
var otElement = 4;
var otPackage = 5;
var otModel = 6;
var otConnector = 7;
var otDiagram = 8;
var otRequirement = 9;
var otScenario = 10;
var otConstraint = 11;
var otTaggedValue = 12;
var otFile = 13;
var otEffort = 14;
var otMetric = 15;
var otIssue = 16;
var otRisk = 17;
var otTest = 18;
var otDiagramObject = 19;
var otDiagramLink = 20;
var otResource = 21;
var otConnectorEnd = 22;
var otAttribute = 23;
var otMethod = 24;
var otParameter = 25;
var otClient = 26;
var otAuthor = 27;
var otDatatype = 28;
var otStereotype = 29;
var otTask = 30;
var otTerm = 31;
var otProjectIssues = 32;
var otAttributeConstraint = 33;
var otAttributeTag = 34;
var otMethodConstraint = 35;
var otMethodTag = 36;
var otConnectorConstraint = 37;
var otConnectorTag = 38;
var otProjectResource = 39;
var otReference = 40;
var otRoleTag = 41;
var otCustomProperty = 42;
var otPartition = 43;
var otTransition = 44;
var otEventProperty = 45;
var otEventProperties = 46;
var otPropertyType = 47;
var otProperties = 48;
var otProperty = 49;
var otSwimlaneDef = 50;
var otSwimlanes = 51;
var otSwimlane = 52;
var otModelWatcher = 53;
var otScenarioStep = 54;
var otScenarioExtension = 55;
var otParamTag = 56;
var otProjectRole = 57;
var otDocumentGenerator = 58;
var otMailInterface = 59;

// =================================================================================================
// MDGMenus
// See http://www.sparxsystems.com/uml_tool_guide/sdk_for_enterprise_architect/mdgmenusenum.htm
// =================================================================================================
var mgMerge = 1;
var mgBuildProject = 2;
var mgRun = 4;

// =================================================================================================
// EnumXMIType
// See http://www.sparxsystems.com/uml_tool_guide/sdk_for_enterprise_architect/xmitypeenum.htm
// =================================================================================================
var xmiEADefault = 0;
var xmiRoseDefault = 1;
var xmiEA10 = 2;
var xmiEA11 = 3;
var xmiEA12 = 4;
var xmiRose10 = 5;
var xmiRose11 = 6;
var xmiRose12 = 7;
var xmiMOF13 = 8;
var xmiMOF14 = 9;
var xmiEA20 = 10;
var xmiEA21 = 11;
var xmiEA211 = 12;
var xmiEA212 = 13;
var xmiEA22 = 14;
var xmiEA23 = 15;
var xmiEA24 = 16;
var xmiEA241 = 17;
var xmiEA242 = 18;
var xmiEcore = 19;
var xmiBPMN20 = 20;
var xmiXPDL22 = 21;

// =================================================================================================
// EnumMVErrorType
// See http://www.sparxsystems.com/uml_tool_guide/sdk_for_enterprise_architect/project_2.htm
// =================================================================================================
var mvError = 0;
var mvWarning = 1;
var mvInformation = 2;
var mvErrorCritical = 3;

// =================================================================================================
// CreateModelType
// See http://www.sparxsystems.com/uml_tool_guide/sdk_for_enterprise_architect/createmodelitype_enum.htm
// =================================================================================================
var cmEAPFromBase = 0;
var cmEAPFromSQLRepository = 1;

// =================================================================================================
// EAEditionTypes
// See http://www.sparxsystems.com/uml_tool_guide/sdk_for_enterprise_architect/eaeditiontypes_enum.htm
// =================================================================================================
var piLite = -1;
var piDesktop = 0;
var piProfessional = 1;
var piCorporate = 2;
var piBusiness = 3;
var piSystemEng = 4;
var piUltimate = 5;

// =================================================================================================
// ScenarioStepType
// See http://www.sparxsystems.com/uml_tool_guide/sdk_for_enterprise_architect/scenariosteptype.htm
// =================================================================================================
var stSystem = 0;
var stActor = 1;

// =================================================================================================
// ExportPackageXMIFlag
// See http://www.sparxsystems.com/uml_tool_guide/sdk_for_enterprise_architect/exportpackagexmiflag.htm
// =================================================================================================
var epSaveToStub = 1;
var epExcludeEAExtensions = 2;

// =================================================================================================
// CreateBaselineFlag
// See http://www.sparxsystems.com/uml_tool_guide/sdk_for_enterprise_architect/createbaselineflag.htm
// =================================================================================================
var cbSaveToStub = 1;

// =================================================================================================
// EnumScenarioDiagramType
// See http://www.sparxsystems.com/uml_tool_guide/sdk_for_enterprise_architect/project_2.htm
// =================================================================================================
var sdActivity = 0;
var sdActivityWithActivityParameter = 1;
var sdActivityWithAction = 2;
var sdActivityhWithActionPin = 3;
var sdRuleFlow = 4;
var sdState = 5;
var sdSequence = 6;
var sdRobustness = 7;

// =================================================================================================
// EnumScenarioTestType
// See http://www.sparxsystems.com/uml_tool_guide/sdk_for_enterprise_architect/project_2.htm
// =================================================================================================
var stInternal = 0;
var stExternal = 1;
var stHorizontalTestSuite = 2;
var stVerticalTestSuite = 3;

// =================================================================================================
// EnumCodeSection
// =================================================================================================
var cpWhole = 0;
var cpNotes = 1;
var cpText = 2;

// =================================================================================================
// EnumRelationSetType
// See http://www.sparxsystems.com/uml_tool_guide/sdk_for_enterprise_architect/enumrelationsettypeenum.htm
// =================================================================================================
var rsGeneralizeStart = 0;
var rsGeneralizeEnd = 1;
var rsRealizeStart = 2;
var rsRealizeEnd = 3;
var rsDependStart = 4;
var rsDependEnd = 5;
var rsParents = 6;

// =================================================================================================
// EnumCodeElementType
// =================================================================================================
var ctInvalid = 0;
var ctNamespace = 1;
var ctClass = 2;
var ctAttribute = 3;
var ctOperation = 4;
var ctOperationParam = 5;

// =================================================================================================
// PropType
// See http://www.sparxsystems.com/uml_tool_guide/sdk_for_enterprise_architect/proptype_enum.htm
// =================================================================================================
var ptString = 0;
var ptInteger = 1;
var ptFloatingPoint = 2;
var ptBoolean = 3;
var ptEnum = 4;
var ptArray = 5;

// =================================================================================================
// SwimlaneOrientationType
// =================================================================================================
var soVertical = 0;
var soHorizontal = 1;

// =================================================================================================
// ReloadType
// See http://www.sparxsystems.com/uml_tool_guide/sdk_for_enterprise_architect/reloadtype_enum.htm
// =================================================================================================
var rtNone = 0;
var rtEntireModel = 1;
var rtPackage = 2;
var rtElement = 3;

// =================================================================================================
// ConstLayoutStyles
// See http://www.sparxsystems.com/uml_tool_guide/sdk_for_enterprise_architect/constlayoutstylesenum.htm
// =================================================================================================
var lsDiagramDefault = 0x00000000;
var lsProgramDefault = 0xFFFFFFFF;
var lsCycleRemoveGreedy = 0x80000000;
var lsCycleRemoveDFS = 0x40000000;
var lsLayeringLongestPathSink = 0x30000000;
var lsLayeringLongestPathSource = 0x20000000;
var lsLayeringOptimalLinkLength = 0x10000000;
var lsInitializeNaive = 0x08000000;
var lsInitializeDFSOut = 0x04000000;
var lsInitializeDFSIn = 0x0C000000;
var lsCrossReduceAggressive = 0x02000000;
var lsLayoutDirectionUp = 0x00010000;
var lsLayoutDirectionDown = 0x00020000;
var lsLayoutDirectionLeft = 0x00040000;
var lsLayoutDirectionRight = 0x00080000;

// =================================================================================================
// WorkFlowConstants
// =================================================================================================
var MaxWorkFlowUsers = 50;
var MaxWorkFlowItems = 100;

// =================================================================================================
// PromptType
// =================================================================================================
var promptOK = 1;
var promptYESNO = 2;
var promptYESNOCANCEL = 3;
var promptOKCANCEL = 4;

// =================================================================================================
// PromptResult
// =================================================================================================
var resultOK = 1;
var resultCancel = 2;
var resultYes = 3;
var resultNo = 4;

// =================================================================================================
// WorkFlowResult
// =================================================================================================
var WorkFlowSucceeded = 1;
var WorkFlowError = 2;
var WorkFlowExists = 3;
var WorkFlowNotFound = 4;
var WorkFlowLimitReached = 5;
var WorkFlowDenied = 6;
var WorkFlowPermitted = 7;
var WorkFlowIsMember = 8;
var WorkFlowIsNotMember = 9;
var WorkFlowBadParam = 10;

// =================================================================================================
// DocumentType
// =================================================================================================
var dtRTF = 0;
var dtHTML = 1;
var dtPDF = 2;
var dtDOCX = 3;

// =================================================================================================
// DocumentBreak
// =================================================================================================
var breakPage = 0;
var breakSection = 1;

// =================================================================================================
// TextAlignment
// =================================================================================================
var alignLeft = 0;
var alignCenter = 1;
var alignRight = 2;
var alignJustify = 3;

// =================================================================================================
// MessageFlag
// =================================================================================================
var mfNone = 0;
var mfComplete = 1;
var mfPurple = 2;
var mfOrange = 3;
var mfGreen = 4;
var mfYellow = 5;
var mfBlue = 6;
var mfRed = 7;
"/>
</DataRow>
<DataRow>
<Column name="ScriptID" value="3"/>
<Column name="ScriptCategory" value="605A62F7-BCD0-4845-A8D0-7DC45B4D2E3F"/>
<Column name="ScriptName" value="{22E7D5FB-E147-4598-B7FA-2EB8A5078586}"/>
<Column name="ScriptAuthor" value="{6F2AAA79-A828-415b-8FCF-6C374FC7F45B}"/>
<Column name="Notes" value="<Script Name="JavaScript-CSV" Type="Internal" Language="JavaScript"/>"/>
<Column name="Script" value="!INC JavaScriptLib.JavaScript-DateTime
!INC JavaScriptLib.JavaScript-Logging
//!INC EAScriptLib.JavaScript-Logging

/**
 * @file JavaScript-CSV
 * This script library contains helper functions to assist with CSV Import and Export of
 * Enterprise Architect elements. 
 * 
 * Functions in this library are split into two parts: Import and Export. Functions that assist with 
 * CSV Import are prefixed with CSVI, whereas functions that assist with CSV Export are prefixed 
 * with CSVE.
 *
 * CSV Import can be performed by calling the function CSVIImportFile(). CSVIImportFile() requires
 * that the function OnRowImported() be defined in the user's script to be used as a callback
 * whenever row data is read from the CSV file. The user defined OnRowImported() can query for 
 * information about the current row through the functions CSVIContainsColumn(), 
 * CSVIGetColumnValueByName() and CSVIGetColumnValueByNumber().
 *
 * To perform a CSV export, the user must firstly call CSVEExportInitialize() which starts an export 
 * session. The call to CSVEExportInitialize() specifies the file name to export to, and the set of 
 * columns that will be exported. Once the session has been initialized with a call to 
 * CSVEExportInitialize(), the user may continually call CSVEExportRow() to export a row to file. 
 * Once all rows have been added, the export session is closed by calling CSVEExportFinalize(). 
 *
 * @author Sparx Systems
 * @date 2020-07-21
 */
 
var CSV_DELIMITER = ",";

////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////
//// ////
//// CSV IMPORT ////
//// ////
////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////
var importColumnMap; // : Map
var importColumnList; // : Array
var importCurrentRow; // : Array
var importIsImporting = false;
const FSREAD = 1;

/**
 * Imports the provided CSV file. The user function OnRowImported() is called to notify the user
 * script that row data is available. The user script may then call CSVIContainsColumn() to see
 * if the current row contains a particular named column, and CSVIGetColumnValueByName() or
 * CSVIGetColumnValueByNumber() to obtain the field value of a particular column.
 *
 * @param[in] fileName (string) The path to the CSV file to import.
 * 
 * @param[in] firstRowContainsHeadings (boolean) If set to true, the values of the first row will be parsed
 * as column headings. CSVIContainsColumn() and CSVIGetColumnValueByName() will only work if 
 * firstRowContainsHeadings is set to true.
 */
function CSVIImportFile( fileName /* : String */, firstRowContainsHeadings /* : boolean */ ) /* : void */
{
 if ( !importIsImporting )
 {
 importIsImporting = true;
 
 // Setup file objects
 var fsObject = new COMObject( "Scripting.FileSystemObject" );
 var file = fsObject.GetFile( fileName );
 var inputStream = file.OpenAsTextStream( FSREAD, 0 );
 
 // Set up row/column caching
 var lineCounter = 0;
 importCurrentRow = null;
 importColumnMap = new Map();
 importColumnList = [];
 
 // Read the file a row at a time
 while ( !inputStream.AtEndOfStream )
 {
 // Get the curnet line and split it into segments based on the CSV_DELIMITER
 var currentLine = inputStream.ReadLine();
 var currentLineTokens = currentLine.split( CSV_DELIMITER );
 
 if ( currentLineTokens.length > 0 )
 {
 for ( var i = 0 ; i < currentLineTokens.length ; i++ )
 {
 // Strip leading/trailing quotation marks
 var quotationLeadRegEx = new RegExp( "^\"+?|^'+?", "gm" );
 var quotationTrailRegEx = new RegExp( "\"+?$|'+?$", "gm" );
 
 currentLineTokens[i] = currentLineTokens[i].replace( quotationLeadRegEx, "" );
 currentLineTokens[i] = currentLineTokens[i].replace( quotationTrailRegEx, "" );
 }
 
 if ( lineCounter == 0 && firstRowContainsHeadings )
 {
 // Cache column heading positions
 for ( var i = 0 ; i < currentLineTokens.length ; i++ )
 {
 importColumnMap.set( currentLineTokens[i], i );
 importColumnList.push( currentLineTokens[i] );
 }
 }
 else
 {
 // Hold a reference to the current row data
 importCurrentRow = currentLineTokens;
 
 // Invoke the user script callback
 OnRowImported();
 }
 
 ++lineCounter;
 }
 }
 
 // Clean up
 importColumnMap = null;
 importColumnList = null;
 inputStream.Close();
 importIsImporting = false;
 }
 else
 {
 LOGWarning( "Reentrant call made to CSVIImportFile(). CSVIImportFile() should not be called from within OnRowImported()" );
 }
}

/**
 * Advises whether the current import row contains a field value for the specified column name.
 *
 * NOTE: The function only works if CSVImportFile() was called with the firstRowContainsHeadings
 * paremeter set to true.
 *
 * @param[in] (String) The name of the column to check for
 *
 * @return A boolean indicating whether the current import row contains a field value for the 
 * specified column name.
 */
function CSVIContainsColumn( columnName /* : String */ ) /* : boolean */
{
 var result = false;
 
 if ( importIsImporting )
 {
 // Get the column number of the specified named column
 var columnNumber = __CSVIGetColumnNumber( columnName );
 
 // If the column is in range then it exists!
 if ( columnNumber >= 0 && importCurrentRow != null && columnNumber < importCurrentRow.length )
 result = true;
 }
 else
 {
 LOGWarning( "No import currently running. CSVIContainsColumn() should only be called from within OnImportRow()" );
 }
 
 return result;
}

/**
 * Returns the value of the field in the current import row with the specified column name
 *
 * NOTE: The function only works if CSVImportFile() was called with the firstRowContainsHeadings
 * paremeter set to true.
 *
 * @param[in] columnName (String) The name of the column whose value will be retrieved.
 *
 * @return The current import row's field value for the specified column
 */
function CSVIGetColumnValueByName( columnName /* : String */ ) /* : variant */
{ 
 var result;
 
 if ( importIsImporting )
 {
 var columnNumber = __CSVIGetColumnNumber( columnName );
 result = CSVIGetColumnValueByNumber( columnNumber );
 }
 else
 {
 LOGWarning( "No import currently running. CSVIGetColumnValueByName() should only be called from within OnImportRow()" );
 }
 
 return result;
}

/**
 * Returns the value of the field in the current import row with the specified column number
 *
 * @param[in] columnNumber (number) The index of the column whose value will be retrieved.
 *
 * @return The current import row's field value for the specified column
 */
function CSVIGetColumnValueByNumber( columnNumber /* : number */ ) /* : variant */
{
 var result;
 
 if ( importIsImporting )
 {
 if ( columnNumber >= 0 && importCurrentRow != null && columnNumber < importCurrentRow.length )
 result = importCurrentRow[columnNumber];
 }
 else
 {
 LOGWarning( "No import currently running. CSVIGetColumnValueByNumber() should only be called from within OnImportRow()" );
 }
 
 return result;
}

/**
 * Returns all column names that are not considered standard as an array of Strings.
 */
function CSVIGetNonStandardElementColumns() /* : Array */
{
 var result = []; 
 var standardColumns = new String(";Abstract;Alias;Author;ClassifierName;Complexity;Created");
 standardColumns += ";Difficulty;GenFile;GenType;Header1;Header2;IsActive;IsLeaf";
 standardColumns += ";IsNew;IsSpec;Locked;Multiplicity;Name;Notes;Persistence;Phase;Priority";
 standardColumns += ";RunState;Status;Stereotype;Subtype;Tablespace;Tag;TreePos;Type;Version";
 standardColumns += ";Visibility;";
 
 if ( importIsImporting )
 {
 for ( var i = 0 ; i < importCurrentRow.length ; i++ )
 {
 if ( i < importColumnList.length )
 {
 var columnName = importColumnList[i];
 if ( standardColumns.indexOf( ";" + columnName + ";" ) == -1 )
 {
 result.push( columnName );
 }
 }
 
 }
 }
 else
 {
 LOGWarning( "No import currently running. CSVIGetNonStandardElementColumns() should only be called from within OnImportRow()" );
 }
 
 return result;
}

/**
 * Sets the properties on the specified Element if there is a corresponding value for them in the 
 * current row.
 *
 * Element properties that are not set by this function include:
 * - Read only properties
 * - Collection properties
 * - Properties that contain relational information (eg IDs/GUIDs of other elements, connectors 
 * or packages.
 * - Modified Date property (this is property is automatically overwritten by the automation 
 * interface when the element is saved)
 * - Properties that are themselves a comma separated list
 *
 * @param[in] elementForRow (EA.Element) The element whose properties will be set with the current row's 
 * values
 */
function CSVISetStandardElementFieldValues( elementForRow /* : EA.Element */ ) /* : void */
{
 if ( importIsImporting )
 {
 var theElement as EA.Element;
 theElement = elementForRow;
 
 if ( theElement != null )
 {
 if ( CSVIContainsColumn("Abstract") )
 theElement.Abstract = CSVIGetColumnValueByName("Abstract");
 
 // ActionFlags - Not included (Comma Separated)
 
 if ( CSVIContainsColumn("Alias") )
 theElement.Alias = CSVIGetColumnValueByName("Alias");
 
 // Attributes - Not included (Collection)
 // AttributesEx - Not included (Collection)
 
 if ( CSVIContainsColumn("Author") )
 theElement.Author = CSVIGetColumnValueByName("Author");
 
 // BaseClasses - Not included (Collection)
 // ClassifierID - Not included (Relational)
 
 if ( CSVIContainsColumn("ClassifierName") )
 theElement.ClassifierName = CSVIGetColumnValueByName("ClassifierName");
 
 // ClassifierType - Not included (Read Only)
 
 if ( CSVIContainsColumn("Complexity") )
 theElement.Complexity = CSVIGetColumnValueByName("Complexity");
 
 // CompositeDiagram - Not included (Relational)
 // Connectors - Not included (Collection)
 // Constraints - Not included (Collection)
 // ConstraintsEx - Not included (Collection)
 
 if ( CSVIContainsColumn("Created") )
 {
 var dateString = CSVIGetColumnValueByName("Created");
 var asEADate = DTParseEADate( dateString );
 theElement.Created = asEADate;
 }
 
 // CustomProperties - Not included (Collection)
 // Diagrams - Not included (Collection)
 
 if ( CSVIContainsColumn("Difficulty") )
 theElement.Difficulty = CSVIGetColumnValueByName("Difficulty");
 
 // Efforts - Not included (Collection)
 // ElementGUID - Not included (Read Only)
 // ElementID - Not included (Read Only)
 // Elements - Not included (Collection)
 // EmbeddedElements - Not included (Read Only)
 // EventFlags - Not included (Comma Separated) 
 // ExtensionPoints - Not included (Comma Separated)
 // Files - Not included (Collection)
 
 if ( CSVIContainsColumn("GenFile") )
 theElement.Genfile = CSVIGetColumnValueByName("GenFile");
 
 // Genlinks - Not included (Relational)
 
 if ( CSVIContainsColumn("GenType") )
 theElement.Gentype = CSVIGetColumnValueByName("GenType");
 
 if ( CSVIContainsColumn("Header1") )
 theElement.Header1 = CSVIGetColumnValueByName("Header1");
 
 if ( CSVIContainsColumn("Header2") )
 theElement.Header1 = CSVIGetColumnValueByName("Header2");
 
 if ( CSVIContainsColumn("IsActive") )
 theElement.IsActive = CSVIGetColumnValueByName("IsActive");
 
 if ( CSVIContainsColumn("IsLeaf") )
 theElement.IsLeaf = CSVIGetColumnValueByName("IsLeaf");
 
 if ( CSVIContainsColumn("IsNew") )
 theElement.IsNew = CSVIGetColumnValueByName("IsNew");
 
 if ( CSVIContainsColumn("IsSpec") )
 theElement.IsSpec = CSVIGetColumnValueByName("IsSpec");
 
 // Issues - Not included (Collection)
 
 if ( CSVIContainsColumn("Locked") )
 theElement.Locked = CSVIGetColumnValueByName("Locked");
 
 // MetaType - Not included (Read Only)
 // Methods - Not included (Collection)
 // Metrics - Not included (Collection)
 // MiscData - Not included (Read Only)
 // Modified - Not included (Overwritten)
 
 if ( CSVIContainsColumn("Multiplicity") )
 theElement.Multiplicity = CSVIGetColumnValueByName("Multiplicity");
 
 if ( CSVIContainsColumn("Name") )
 {
 theElement.Name = CSVIGetColumnValueByName("Name");
 }
 
 if ( CSVIContainsColumn("Notes") )
 theElement.Notes = CSVIGetColumnValueByName("Notes");
 
 // ObjectType - Not included (Read Only)
 // PackageID - Not included (Relational)
 // ParentID - Not included (Relational)
 // Partitions - Not included (Collection)
 
 if ( CSVIContainsColumn("Persistence") )
 theElement.Persistence = CSVIGetColumnValueByName("Persistence");
 
 if ( CSVIContainsColumn("Phase") )
 theElement.Persistence = CSVIGetColumnValueByName("Phase");
 
 if ( CSVIContainsColumn("Priority") )
 theElement.Persistence = CSVIGetColumnValueByName("Priority");
 
 // Properties - Not included (Collection)
 // PropertyType - Not included (Relational)
 // Realizes - Not included (Collection)
 // Requirements - Not included (Collection)
 // RequirementsEx - Not included (Collection)
 // Resources - Not included (Collection)
 // Risks - Not included (Collection)
 
 if ( CSVIContainsColumn("RunState") )
 theElement.Persistence = CSVIGetColumnValueByName("RunState");
 
 // Scenarios - Not included (Collection)
 // State Transitions - Not included (Collection)
 
 if ( CSVIContainsColumn("Status") )
 theElement.Status = CSVIGetColumnValueByName("Status");
 
 if ( CSVIContainsColumn("Stereotype") )
 theElement.Stereotype = CSVIGetColumnValueByName("Stereotype");
 
 // StereotypeEx - Not included (Comma Separated)
 
 if ( CSVIContainsColumn("Subtype") )
 theElement.Subtype = CSVIGetColumnValueByName("Subtype");
 
 if ( CSVIContainsColumn("Tablespace") )
 theElement.Tablespace = CSVIGetColumnValueByName("Tablespace");
 
 if ( CSVIContainsColumn("Tag") )
 theElement.Tag = CSVIGetColumnValueByName("Tag");
 
 // TaggedValues - Not included (Collection)
 // TaggedValuesEx - Not included (Collection)
 // Tests - Not included (Collection)
 
 if (CSVIContainsColumn("TreePos") )
 theElement.TreePos = CSVIGetColumnValueByName("TreePos");
 
 if ( CSVIContainsColumn("Type") )
 theElement.Type = CSVIGetColumnValueByName("Type");
 
 if ( CSVIContainsColumn("Version") )
 {
 theElement.Version = CSVIGetColumnValueByName("Version");
 }
 
 if ( CSVIContainsColumn("Visibility") )
 {
 theElement.Visibility = CSVIGetColumnValueByName("Visibility");
 }
 }
 }
 else
 {
 LOGWarning( "No import currently running. CSVSetStandardElementFieldValues() should only be called from within OnImportRow()" ); 
 }
}

/**
 * @private
 * Returns the index of the column with the specified name
 *
 * @param[in] columnName (String) The name of the column whose index will be retrieved
 *
 * @return The index of the column with the specified name
 */
function __CSVIGetColumnNumber( columnName /* : String */ ) /* : number */
{
 var result = -1;
 if ( importColumnMap != null && importColumnMap.has(columnName) )
 result = importColumnMap.get(columnName);
 
 return result;
}

////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////
//// ////
//// CSV EXPORT ////
//// ////
////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////
var exportFile; // : FileSystemObject
var exportColumns; // : Array
var exportIsExporting = false;

/**
 * Initialises a CSV Export session. This must be called before calls to CSVEExportRow() are made. 
 * Once all rows have been exported, a corresponding call to CSVEExportFinalize() should be made.
 *
 * @param[in] fileName (String) the path to saving the resulting CSV file as.
 * @param[in] columns (Array) an array of column names that will be exported
 * @param[in] exportColumnHeadings (boolean) Specifies whether the first row should contain the column 
 * headings
 */
function CSVEExportInitialize( fileName /* : String */, columns /* : Array */, 
 exportColumnHeadings /* : boolean */ ) /* : void */
{
 if ( !exportIsExporting )
 {
 // Switch into exporting mode
 exportIsExporting = true;

 // Setup file object and column array
 var fsObject = new COMObject( "Scripting.FileSystemObject" );
 exportFile = fsObject.CreateTextFile( fileName, true );

 exportColumns = columns;

 // Check if file successfully opened for writing
 if (exportFile === undefined)
 {
 LOGError("CSVEExportInitialize: Unable to open file - " + fileName);
 return;
 }
 
 if ( exportColumnHeadings )
 {
 // Export column headings if the option was enabled
 var headingString = "";
 
 for ( var i = 0 ; i < exportColumns.length ; i++ )
 {
 if ( i == 0 )
 headingString += exportColumns[i];
 else
 headingString += CSV_DELIMITER + exportColumns[i];
 }
 
 
 exportFile.WriteLine( headingString );
 }
 }
 else
 {
 LOGWarning( "CSV Export is already in progress" );
 }
}

/**
 * Finalizes a CSV Export session, closing file system resources required for the export. After this
 * function has been executed, further calls to CSVEExportRow() will fail until another CSV Export
 * session is initialized via CSVEExportInitialize()
 */
function CSVEExportFinalize() /* : void */
{
 if ( exportIsExporting )
 {
 // Clean up file object and column array
 exportFile.Close();
 exportFile = null;
 exportColumns = null;
 
 // Switch out of exporting mode
 exportIsExporting = false;
 }
 else
 {
 LOGWarning( "CSV Export is not currently in progress" );
 }
}

/**
 * Exports a row to the CSV file. The valueMap parameter is used to lookup field values for the
 * columns specified when CSVEExportInitialize() was called. Values in valueMap that do not 
 * correspond to a valid column will not be exported.
 *
 * @param[in] valueMap (Map) A Map of field values where key=Column Name, value=Field Value
 */

function CSVEExportRow( valueMap /* : Map */ ) /* : void */
{
 if ( exportIsExporting )
 {
 if ( exportColumns.length > 0 )
 {
 // Build a string for the row
 var rowString = "";
 
 // Iterate over all columns specified in CSVEExportInitialize()
 for ( var i = 0 ; i < exportColumns.length ; i++ )
 {
 // Get the column name
 var currentColumn = exportColumns[i];
 
 // Get the corresponding field value from valueMap
 var fieldValue = valueMap.get(currentColumn);
 
 // If the fieldValue is null/undefined, output an empty string
 if ( fieldValue == null )
 fieldValue = "";
 
 if ( i == 0 )
 rowString += __CSVEToSafeCSVString(fieldValue);
 else
 rowString += CSV_DELIMITER + __CSVEToSafeCSVString(fieldValue);
 }
 
 // Output to file
 exportFile.WriteLine( rowString );
 }
 }
 else
 {
 LOGWarning( "CSV Export is not currently in progress. Call CSVEExportInitialize() to start a CSV Export" );
 }
}

/**
 * Creates and returns an empty Value Map.
 */
function CSVECreateEmptyValueMap() /* : Map */
{
 var valueMap = new Map();
 return valueMap;
}

/**
 * Returns an array of column names considered standard for EA elements. This array can be used
 * as the columns parameter when calling CSVEExportInitialize()
 *
 * @param[in] includeGUID (boolean) Advises whether the elementGUID field should be included
 *
 * @return an array of column names 
 */
function CSVEGetStandardElementColumns( includeGUID /* : boolean */ ) /* : Array */
{
 var columnArray = [];
 
 columnArray.push( "Abstract" );
 // ActionFlags - Not included (Comma Separated) 
 columnArray.push( "Alias" );
 // Attributes - Not included (Collection)
 // AttributesEx - Not included (Collection)
 columnArray.push( "Author" );
 // BaseClasses - Not included (Collection)
 // ClassifierID - Not included (Relational)
 columnArray.push( "ClassifierName" );
 // ClassifierType - Not included (Read Only)
 columnArray.push( "Complexity" );
 // CompositeDiagram - Not included (Relational)
 // Connectors - Not included (Collection)
 // Constraints - Not included (Collection)
 // ConstraintsEx - Not included (Collection)
 columnArray.push( "Created" );
 // CustomProperties - Not included (Collection)
 // Diagrams - Not included (Collection)
 columnArray.push( "Difficulty" );
 // Efforts - Not included (Collection)
 
 if ( includeGUID )
 columnArray.push( "ElementGUID" );
 
 // Elements - Not included (Collection)
 // EmbeddedElements - Not included (Collection)
 // EventFlags - Not included (Comma Separated)
 // ExtensionPoints - Not included (Comma Separated)
 // Files - Not included (Collection)
 columnArray.push( "GenFile" );
 // Genlinks - Not included (Relational)
 columnArray.push( "GenType" );
 columnArray.push( "Header1" );
 columnArray.push( "Header2" );
 columnArray.push( "IsActive" );
 columnArray.push( "IsLeaf" );
 columnArray.push( "IsNew" );
 columnArray.push( "IsSpec" );
 // Issues - Not included (Collection)
 columnArray.push( "Locked" );
 // MetaType - Not included (Read Only)
 // Methods - Not included (Collection)
 // Metrics - Not included (Collection)
 // MiscData - Not included (Read Only)
 // Modified - Not included (Overwritten)
 columnArray.push( "Multiplicity" );
 columnArray.push( "Name" );
 columnArray.push( "Notes" );
 // ObjectType - Not included (Read Only)
 // PackageID - Not included (Relational)
 // ParentID - Not included (Relational)
 // Partitions - Not included (Collection)
 columnArray.push( "Persistence" );
 columnArray.push( "Phase" );
 columnArray.push( "Priority" );
 // Properties - Not included (Collection)
 // PropertyType - Not included (Relational)
 // Realizes - Not included (Collection)
 // Requirements - Not included (Collection)
 // RequirementsEx - Not included (Collection)
 // Resources - Not included (Collection)
 // Risks - Not included (Collection)
 columnArray.push( "RunState" );
 // Scenarios - Not included (Collection)
 // State Transitions - Not included (Collection)
 columnArray.push( "Status" );
 columnArray.push( "Stereotype" );
 // StereotypeEx - Not included (Comma Separated) 
 columnArray.push( "Subtype" );
 columnArray.push( "Tablespace" );
 columnArray.push( "Tag" );
 // TaggedValues - Not included (Collection)
 // TaggedValuesEx - Not included (Collection)
 // Tests - Not included (Collection)
 columnArray.push( "TreePos" );
 columnArray.push( "Type" );
 columnArray.push( "Version" );
 columnArray.push( "Visibility" );
 
 return columnArray;
}

/**
 * Creates a Value Map of standard property names/values for the specified element. This Value Map 
 * can be used as the valueMap parameter when calling the ExportRow() function.
 *
 * @param[in] element (EA.Element) The element to compile the Value Map for
 *
 * @return A Value Map populated with the provided element's values.
 */
function CSVEGetStandardElementFieldValues( element /* : EA.Element */ ) /* : Map */
{
 var theElement as EA.Element;
 theElement = element;
 
 var valueMap = CSVECreateEmptyValueMap();
 
 valueMap.set( "Abstract", theElement.Abstract );
 // ActionFlags - Not included (Comma Separated)
 valueMap.set( "Alias", theElement.Alias );
 // Attributes - Not included (Collection)
 // AttributesEx - Not included (Collection)
 valueMap.set( "Author", theElement.Author );
 // BaseClasses - Not included (Collection)
 // ClassifierID - Not included (Relational)
 valueMap.set( "ClassifierName", theElement.ClassifierName );
 // ClassifierType - Not included (Read Only)
 valueMap.set( "Complexity", theElement.Complexity);
 // CompositeDiagram - Not included (Relational)
 // Connectors - Not included (Collection)
 // Constraints - Not included (Collection)
 // ConstraintsEx - Not included (Collection)
 valueMap.set( "Created", theElement.Created );
 // CustomProperties - Not included (Collection)
 // Diagrams - Not included (Collection)
 valueMap.set( "Difficulty", theElement.Difficulty );
 // Efforts - Not included (Collection)
 valueMap.set( "ElementGUID", theElement.ElementGUID );
 // Elements - Not included (Collection)
 // EmbeddedElements - Not included (Read Only)
 // Event Flags - Not included (Comma Separated) 
 // ExtensionPoints - Not included (Comma Separated)
 // Files - Not included (Collection)
 valueMap.set( "GenFile", theElement.Genfile );
 // Genlinks - Not included (Relational)
 valueMap.set( "GenType", theElement.Gentype );
 valueMap.set( "Header1", theElement.Header1 );
 valueMap.set( "Header2", theElement.Header2 );
 valueMap.set( "IsActive", theElement.IsActive );
 valueMap.set( "IsLeaf", theElement.IsLeaf );
 valueMap.set( "IsNew", theElement.IsNew );
 valueMap.set( "IsSpec", theElement.IsSpec );
 // Issues - Not included (Collection)
 valueMap.set( "Locked", theElement.Locked );
 // MetaType - Not included (Read Only)
 // Methods - Not included (Collection)
 // Metrics - Not included (Collection)
 // MiscData - Not included (Read Only)
 // Modified - Not included (Overwritten)
 valueMap.set( "Multiplicity", theElement.Multiplicity );
 valueMap.set( "Name", theElement.Name );
 valueMap.set( "Notes", theElement.Notes );
 // ObjectType - Not included (Read Only)
 // PackageID - Not included (Relational)
 // ParentID - Not included (Relational)
 // Partitions - Not included (Collection)
 valueMap.set( "Persistence", theElement.Persistence );
 valueMap.set( "Phase", theElement.Phase );
 valueMap.set( "Priority", theElement.Priority );
 // Properties - Not included (Collection)
 // PropertyType - Not included (Relational)
 // Realizes - Not included (Collection)
 // Requirements - Not included (Collection)
 // RequirementsEx - Not included (Collection)
 // Resources - Not included (Collection)
 // Risks - Not included (Collection)
 valueMap.set( "RunState", theElement.RunState );
 // Scenarios - Not included (Collection)
 // State Transitions - Not included (Collection)
 valueMap.set( "Status", theElement.Status );
 valueMap.set( "Stereotype", theElement.Stereotype );
 // StereotypeEx - Not included (Comma Separated) 
 valueMap.set( "Subtype", theElement.Subtype );
 valueMap.set( "Tablespace", theElement.Tablespace );
 valueMap.set( "Tag", theElement.Tag );
 // TaggedValues - Not included (Collection)
 // TaggedValuesEx - Not included (Collection)
 // Tests - Not included (Collection)
 valueMap.set( "TreePos", theElement.TreePos );
 valueMap.set( "Type", theElement.Type );
 valueMap.set( "Version", theElement.Version );
 valueMap.set( "Visibility", theElement.Visibility );
 
 return valueMap;
}

/**
 * @private
 * Returns a copy of the string that is safe for inclusion in a CSV file.
 *
 * @param[in] originalString (String) The string to convert
 *
 * @return a copy of the string modified for inclusion in a CSV file
 */
function __CSVEToSafeCSVString( originalString /* : String */ ) /* : String */
{
 var returnString = new String(originalString);
 
 // Strip out delimiters
 var delimiterRegExp = new RegExp( CSV_DELIMITER, "gm" );
 returnString = returnString.replace( delimiterRegExp, "" );
 
 // Strip out newline chars
 var newlineRegExp = new RegExp( "\r\n?", "gm" );
 returnString = returnString.replace( newlineRegExp, " " );
 
 return returnString;
}
"/>
</DataRow>
<DataRow>
<Column name="ScriptID" value="4"/>
<Column name="ScriptCategory" value="605A62F7-BCD0-4845-A8D0-7DC45B4D2E3F"/>
<Column name="ScriptName" value="{255CF97F-B6AE-46bd-B9C6-5BA481559DFA}"/>
<Column name="ScriptAuthor" value="{6F2AAA79-A828-415b-8FCF-6C374FC7F45B}"/>
<Column name="Notes" value="<Script Name="JavaScript-Database" Type="Internal" Language="JavaScript"/>"/>
<Column name="Script" value="!INC JavaScriptLib.JavaScript-XML
//!INC EAScriptLib.JavaScript-XML

/**
 * @file JavaScript-Database
 * This script library contains helper functions to assist with querying the underlying database
 * fields of an EA project.
 *
 * Some functions will behave differently according to the value of the script variable DBTYPE.
 * You should ensure that this value reflects the corresponding database repository type that you
 * are currently using.
 *
 * @author Sparx Systems
 * @date 2020-07-21
 */
var DBTYPE_EAP = 0;
var DBTYPE_MYSQL = 1;
var DBTYPE = DBTYPE_EAP;

/**
 * Queries the repository database for the first field value whose corresponding row matches the
 * specified WHERE clause.
 *
 * @param[in] columnName (string) The column name whose field value will be queried for
 * @param[in] table (string) The table that the column resides in
 * @param[in] whereClause (string) The SQL where clause that the query will use to select the
 * appropriate row
 *
 * @return A String representing the requested field value
 */
function DBGetFieldValueString( columnName /* : String */, table /* : String */, whereClause /* : String */ ) /* : String */
{
 var stringValue = "";
 
 // Construct and execute the query
 var sql = "SELECT " + columnName + " FROM " + table + " WHERE " + whereClause;
 var queryResult = Repository.SQLQuery( sql );
 
 if ( queryResult.length > 0 )
 {
 var resultDOM = XMLParseXML( queryResult );
 if ( resultDOM )
 stringValue = XMLGetNodeText( resultDOM, "//EADATA//Dataset_0//Data//Row//" + columnName );
 }
 
 return stringValue;
}

/**
 * Queries the repository database for the first field value whose corresponding row matches the
 * specified WHERE clause.
 *
 * @param[in] columnName (string) The column name whose field value will be queried for
 * @param[in] table (string) The table that the column resides in
 * @param[in] whereClause (string) The SQL where clause that the query will use to select the
 * appropriate row
 *
 * @return A Number representing the requested field value
 */
function DBGetFieldValueNumber( columnName /* : String */, table /* : String */, whereClause /* : String */ ) /* : Number */
{
 // Get the field value as a String
 var numberValue = 0;
 var valueAsString = DBGetFieldValueString( columnName, table, whereClause );
 
 // Conver to number
 if ( valueAsString.length > 0 )
 numberValue = new Number( valueAsString );
 
 return numberValue;
}

/**
 * Queries the repository database for all field values whose corresponding row match the specified
 * WHERE clause.
 *
 * @param[in] columnName (string) The column name whose values will be queried for
 * @param[in] table (string) The table that the column resides in
 * @param[in] whereClause (string) The SQL where clause that the query will use to select the
 * appropriate rows
 *
 * @return An array of Strings representing the requested field values
 */
function DBGetFieldValueArrayString( columnName /* : String */, table /* : String */, 
 whereClause /* : String */ ) /* : Array */
{
 var resultArray = new Array();
 
 // Construct and execute the query
 var sql = "SELECT " + columnName + " FROM " + table;
 if ( typeof(whereClause) != "undefined" && whereClause.length > 0 )
 sql += " WHERE " + whereClause;
 
 var queryResult = Repository.SQLQuery( sql );
 if ( queryResult.length > 0 )
 {
 var resultDOM = XMLParseXML( queryResult );
 resultArray = XMLGetNodeTextArray( resultDOM, "//EADATA//Dataset_0//Data//Row//" 
 + columnName );
 }
 
 return resultArray;
}

/**
 * Returns an escaped copy of the provided String that may be safely included in an SQL query.
 * NOTE: This function automatically adds single quotation marks around the string value.
 *
 * @param[in] originalString The String to escape
 *
 * @return A String representing the SQL escaped version of the provided string
 */
function DBSafeSQLString( originalString /* : String */ ) /* : String */
{
 // Replace single quotation marks with 2x single quotation marks
 var quotationRegEx = new RegExp( "\'", "gm" );
 var modifiedContents = originalString.replace( quotationRegEx, "\'\'" );
 
 return "\'" + modifiedContents + "\'";
}

/**
 * Returns a string representation of the provided Date which may be used in SQL queries
 * NOTE: The output of this function depends on the value of the script variable DBTYPE.
 *
 * @param[in] scriptingDate The Date to the format
 *
 * @return A String representing the SQL formatted version of the provided Date
 */
function DBGetSQLDate( scriptingDate /* : Date */ ) /* : String */
{
 var dateDelimiter = "#";
 
 if ( DBTYPE == DBTYPE_MYSQL )
 dateDelimiter = "\'";
 
 var sqlDate = dateDelimiter;
 sqlDate += scriptingDate.getFullYear() + "-" + (scriptingDate.getMonth() + 1) + "-" + scriptingDate.getDate();
 sqlDate += " " + scriptingDate.getHours() + ":" + scriptingDate.getMinutes() + ":" + scriptingDate.getSeconds();
 sqlDate += dateDelimiter;
 
 return sqlDate;
}

/**
 * Run SQL and return the ResultSet as a JSON object
 *
 * @param[in] sql (string) The SQL SELECT statement to be executed
 *
 * @return A JSON object with three properties: SQL (string), Rows (Array) and Columns (Array).
 * SQL will contain a copy of the sql statement that was passed to this function. Columns will
 * contain an Array of the unique column names returned by the query. Rows will contain an Array
 * of JSON objects, the properties of each object are based on the columns returned by the SQL Query.
 */
function DBSQLQueryToJSON( sql /* : String */ ) /* : Object */
{
 // Create a new JSON object to represent the result set. Object has three properties: SQL (string), Columns (Array) and Rows (Array)
 var resultSet = {
 "SQL" : sql,
 "Columns" : [],
 "Rows" : []
 };
 
 var xml = Repository.SQLQuery(sql);
 var xmlDOM = XMLParseXML(xml);
 var rowCount = 0;

 var xmlRows = xmlDOM.documentElement.selectNodes( "//EADATA//Dataset_0//Data//Row" );
 if (xmlRows != null)
 {
 // Loop each Row node in the xml
 var xmlRow = xmlRows.nextNode();
 while (xmlRow != null)
 {
 // Create a new JSON Object for each row
 var row = {};
 
 // Loop each node which is a child of the current row (i.e. the columns)
 var xmlColumns = xmlRow.childNodes;
 var xmlColumn = xmlColumns.nextNode();
 while (xmlColumn != null)
 {
 // Create a property on the row object with the same name and value as the node found in the xml
 row[xmlColumn.nodeName] = xmlColumn.text;

 // For first row only, add all unique column names to the Columns array
 if (rowCount == 0 && !resultSet.Columns.includes(xmlColumn.nodeName))
 resultSet.Columns.push(xmlColumn.nodeName);
 
 // Next column
 xmlColumn = xmlColumns.nextNode();
 }
 
 // Append new row to ResultSet.Rows
 resultSet.Rows.push(row);
 rowCount++;
 
 // Next row
 xmlRow = xmlRows.nextNode();
 }
 }
 
 return resultSet;
}
"/>
</DataRow>
<DataRow>
<Column name="ScriptID" value="5"/>
<Column name="ScriptCategory" value="605A62F7-BCD0-4845-A8D0-7DC45B4D2E3F"/>
<Column name="ScriptName" value="{61638C6D-687F-49a0-81A6-773A40614308}"/>
<Column name="ScriptAuthor" value="{6F2AAA79-A828-415b-8FCF-6C374FC7F45B}"/>
<Column name="Notes" value="<Script Name="JavaScript-DateTime" Type="Internal" Language="JavaScript"/>
"/>
<Column name="Script" value="/**
 * @Status: NOT TESTED
 * @file JavaScript-DateTime
 * This script library contains helper functions for working with Date/Time structures in
 * the automation interface. Functions provided by this module are identified by the prefix DT.
 *
 * @author Sparx Systems
 * @date 2010-09-01
 */
 
/**
 * Converts a scripting Date object to a variant date object that EA's automation interface accepts
 *
 * @param[in] scriptingDate (Date) The scripting Date object to convert
 *
 * @return the provided scripting Date in variant date form
 */
function DTToEADate( scriptingDate /* : Date */ ) /* : variant */
{
 var eaDate = scriptingDate.getVarDate();
 return eaDate;
}

/**
 * Parses the provided date string into a variant date object that EA's automation interface accepts
 *
 * @param[in] dateString (String) A string representing a date
 *
 * @return The provided string parsed in variant date form
 */
function DTParseEADate( dateString /* : String */ ) /* : variant */
{
 // As JScript mimics Javascript, parse() returns a long
 var asLong = Date.parse( dateString );
 
 // Create a JScript date from the long
 var asJScriptDate = new Date( asLong );
 
 // Convert to EA Date
 var asEADate = DTToEADate( asJScriptDate );
 
 return asEADate;
}"/>
</DataRow>
<DataRow>
<Column name="ScriptID" value="6"/>
<Column name="ScriptCategory" value="605A62F7-BCD0-4845-A8D0-7DC45B4D2E3F"/>
<Column name="ScriptName" value="{13C73AFF-93F2-4d59-B80F-C9E5A65D83BB}"/>
<Column name="ScriptAuthor" value="{6F2AAA79-A828-415b-8FCF-6C374FC7F45B}"/>
<Column name="Notes" value="<Script Name="JavaScript-Dialog" Type="Internal" Language="JavaScript"/>"/>
<Column name="Script" value="/**
 * @file JavaScript-Dialog
 * This script library contains helper functions for common dialogs. Functions provided by this 
 * module are identified by the prefix DLG.
 *
 * @author Sparx Systems
 * @date 2020-07-21
 */

var DLG_MAXFILESIZE = 260;
var OF_FILEMUSTEXIST = 0x1000;
var OF_OVERWRITEPROMPT = 0x2;

/**
 * Displays an Input dialog and returns the text that the user typed in.
 *
 * @param[in] promptText (String) The text prompt that will be displayed on the input dialog.
 * @param[in] title (String) The text that will appear in the input dialog's title.
 * @param[in] defaultText (String) The initial text that will appear in the input field of the dialog.
 *
 * @return A String value representing the text the user typed into the input field
 */
function DLGInputBox( promptText /* : String */, title /* : String */, defaultText /* : String */ ) /* : String */
{
 // JavaScript has no intrinsic InputBox method, therefore we have to steal VBs
 var vbe = new COMObject("ScriptControl");
 vbe.Language = "VBScript";
 
 return vbe.eval( "InputBox(\"" + promptText + "\",\"" + title + "\",\"" + defaultText + "\")");
}

/**
 * Displays an Open File dialog and returns the file name that the user selected.
 *
 * @param[in] filterString (String) A filter string that lists the sets of filename filters that 
 * can be applied in the dialog. Each filter is a string pair delimited by the pipe symbol (|), 
 * with the first string containing a description of the filter (eg "Documents") and the second
 * string containing a semicolon delimited list of file patterns to filter on (eg 
 * "*.doc;*.xml;*.odt"). Multiple filters can be provided in filterString, delimited also by the 
 * pipe symbol (eg "All Files |*.*|Documents|*.doc;*.xml;*.odt")
 * @param[in] defaultFilterIndex (Number) The filter index that will be selected by default (starts 
 * at 1)
 *
 * @return A String value representing the file name that the user selected
 */
function DLGOpenFile( filterString /* : String */, defaultFilterIndex /* : Number */ ) /* : String */
{
 if ( filterString == null || filterString == "" )
 {
 filterString = "All Files (*.*)|*.*";
 defaultFilterIndex = 1;
 }

 var filename = "";
 var flags = OF_FILEMUSTEXIST;
 var initialDirectory = "";
 var openOrSave = 0;
 
 // Show the dialog and return the selected file name
 return Repository.GetProjectInterface().GetFileNameDialog(filename, filterString, defaultFilterIndex, flags, initialDirectory, openOrSave);
}

/**
 * Displays a Save File dialog and returns the file name that the user selected.
 *
 * @param[in] filterString (String) A filter string that lists the sets of filename filters that 
 * can be applied in the dialog. Each filter is a string pair delimited by the pipe symbol (|), 
 * with the first string containing a description of the filter (eg "Documents") and the second
 * string containing a semicolon delimited list of file patterns to filter on (eg 
 * "*.doc;*.xml;*.odt"). Multiple filters can be provided in filterString, delimited also by the 
 * pipe symbol (eg "All Files |*.*|Documents|*.doc;*.xml;*.odt")
 * @param[in] defaultFilterIndex (Number) The filter index that will be selected by default (starts 
 * at 1)
 *
 * @return A String value representing the file name that the user selected.
 */
function DLGSaveFile( filterString /* : String */, defaultFilterIndex /* : Number */ ) /* : String */
{
 if ( filterString == null || filterString == "" )
 {
 filterString = "All Files (*.*)|*.*";
 defaultFilterIndex = 1;
 }
 
 var filename = "";
 var flags = OF_OVERWRITEPROMPT;
 var initialDirectory = "";
 var openOrSave = 1;
 
 // Show the dialog and return the selected file name
 return Repository.GetProjectInterface().GetFileNameDialog(filename, filterString, defaultFilterIndex, flags, initialDirectory, openOrSave);
}"/>
</DataRow>
<DataRow>
<Column name="ScriptID" value="7"/>
<Column name="ScriptCategory" value="605A62F7-BCD0-4845-A8D0-7DC45B4D2E3F"/>
<Column name="ScriptName" value="{78A126B5-774E-4c72-AE95-3FE387C5BF60}"/>
<Column name="ScriptAuthor" value="{6F2AAA79-A828-415b-8FCF-6C374FC7F45B}"/>
<Column name="Notes" value="<Script Name="JavaScript-GUID" Type="Internal" Language="JavaScript"/>"/>
<Column name="Script" value="/**
 * @file JavaScript-GUID
 * This script library contains helper functions to assist with the generation and manipulation
 * of Globally Unique Identifiers (GUIDs)
 *
 * @author Sparx Systems
 * @date 2020-07-21
 */

/**
 * Generates and returns a Globally Unique Identifier in string form
 *
 * @return A string representing a new globally unique identifier
 */
function GUIDGenerateGUID() /* : String */
{
 var typeLib = new COMObject( "Scriptlet.TypeLib" );
 
 // GUID returned from typeLib has 2 unprintable characters at the end which stuff up string
 // manipulation later on
 return typeLib.GUID.substr(0, 38);
}"/>
</DataRow>
<DataRow>
<Column name="ScriptID" value="8"/>
<Column name="ScriptCategory" value="605A62F7-BCD0-4845-A8D0-7DC45B4D2E3F"/>
<Column name="ScriptName" value="{F030ED9C-0E06-4165-8DD5-95B3968CA747}"/>
<Column name="ScriptAuthor" value="{6F2AAA79-A828-415b-8FCF-6C374FC7F45B}"/>
<Column name="Notes" value="<Script Name="JavaScript-Logging" Type="Internal" Language="JavaScript"/>"/>
<Column name="Script" value="/**
 * @file JavaScript-Logging
 * This script library contains helper functions to assist with logging. Log messages can be 
 * submitted to the various functions in this module, and will be filtered according to the value
 * of LOGLEVEL.
 *
 * Valid values for LOGLEVEL are:
 * - LOGLEVEL_ERROR
 * - LOGLEVEL_WARNING
 * - LOGLEVEL_INFO
 * - LOGLEVEL_DEBUG
 * - LOGLEVEL_TRACE
 *
 * You can change the log level at any time during execution by setting the LOGLEVEL variable to the
 * desired value.
 *
 * Functions provided by this module are identified by the prefix LOG
 *
 * @author Sparx Systems
 * @date 2020-07-21
 */

// LOGLEVEL values
var LOGLEVEL_ERROR = 0;
var LOGLEVEL_WARNING = 1;
var LOGLEVEL_INFO = 2;
var LOGLEVEL_DEBUG = 3;
var LOGLEVEL_TRACE = 4;

// The level to log at
var LOGLEVEL = LOGLEVEL_INFO;

/**
 * Logs a message at the ERROR level. The message will be displayed if LOGLEVEL is set to 
 * LOGLEVEL_ERROR or above.
 *
 * @param[in] message (String) The message to log
 */
function LOGError( message /* : String */ ) /* : void */
{
 if ( LOGLEVEL >= LOGLEVEL_ERROR )
 Session.Output( _LOGGetDisplayDate() + " [ERROR]: " + message );
}

/**
 * Logs a message at the INFO level. The message will be displayed if LOGLEVEL is set to 
 * LOGLEVEL_INFO or above.
 *
 * @param[in] message (String) The message to log
 */
function LOGInfo( message /* : String */ ) /* : void */
{
 if ( LOGLEVEL >= LOGLEVEL_INFO )
 Session.Output( _LOGGetDisplayDate() + " [INFO]: " + message );
}

/**
 * Logs a message at the WARNING level. The message will be displayed if LOGLEVEL is set to 
 * LOGLEVEL_WARNING or above.
 *
 * @param[in] message (String) The message to log
 */
function LOGWarning( message /* : String */ ) /* : void */
{
 if ( LOGLEVEL >= LOGLEVEL_WARNING )
 Session.Output( _LOGGetDisplayDate() + " [WARNING]: " + message );
}

/**
 * Logs a message at the DEBUG level. The message will be displayed if LOGLEVEL is set to 
 * LOGLEVEL_DEBUG or above.
 *
 * @param[in] message (String) The message to log
 */
function LOGDebug( message /* : String */ ) /* : void */
{
 if ( LOGLEVEL >= LOGLEVEL_DEBUG )
 Session.Output( _LOGGetDisplayDate() + " [DEBUG]: " + message );
}

/**
 * Logs a message at the TRACE level. The message will be displayed if LOGLEVEL is set to 
 * LOGLEVEL_TRACE or above.
 *
 * @param[in] message (String) The message to log
 */
function LOGTrace( message /* : String */ ) /* : void */
{
 if ( LOGLEVEL >= LOGLEVEL_TRACE )
 Session.Output( _LOGGetDisplayDate() + " [TRACE]: " + message );
}

/**
 * Returns the current date/time in a format suitable for logging.
 *
 * @return A String representing the current date/time
 */
function _LOGGetDisplayDate() /* : String */
{
 var now = new Date();
 
 // Pad hour value
 var hours = now.getHours();
 if ( hours < 10 )
 hours = "0" + hours;
 
 // Pad minute value
 var minutes = now.getMinutes();
 if ( minutes < 10 )
 minutes = "0" + minutes;
 
 // Pad second value
 var seconds = now.getSeconds();
 if ( seconds < 10 )
 seconds = "0" + seconds;
 
 var displayDate = now.getFullYear() + "-" + (now.getMonth() + 1) + "-" + now.getDate();
 displayDate += " " + hours + ":" + minutes + ":" + seconds;

 return displayDate;
}"/>
</DataRow>
<DataRow>
<Column name="ScriptID" value="9"/>
<Column name="ScriptCategory" value="605A62F7-BCD0-4845-A8D0-7DC45B4D2E3F"/>
<Column name="ScriptName" value="{8D11EF31-440F-4183-A176-717524074B12}"/>
<Column name="ScriptAuthor" value="{6F2AAA79-A828-415b-8FCF-6C374FC7F45B}"/>
<Column name="Notes" value="<Script Name="JavaScript-String" Type="Internal" Language="JavaScript"/>"/>
<Column name="Script" value="/**
 * @file JavaScript-String
 * This script library contains helper functions to assist with String manipulation
 *
 * Functions provided by this module are identified by the prefix STR
 *
 * @author Sparx Systems
 * @date 2020-07-21
 */
 
function STRTrim( original /* : String */ ) /* : String */
{
 return original.replace( /^\s+|\s+$/g, "" );
}

function STRLTrim( original /* : String */ ) /* : String */
{
 return original.replace( /^\s+/, "" );
}

function STRRTrim( original /* : String */ ) /* : String */
{
 return original.replace( /\s+$/, "" );
}

function STRTrimQuote( original /* : String */ ) /* : String */
{
 return original.replace( /^\"+|\"+$/g, "" );
}

function STRLTrimQuote( original /* : String */ ) /* : String */
{
 return original.replace( /^\"+/, "" );
}

function STRRTrimQuote( original /* : String */ ) /* : String */
{
 return original.replace( /\"+$/, "" );
}


/**
 * Generate spaces based on a specified indent level.
 *
 * @param[in] (Integer) Depth of the indent to generate
 *
 * @return A string of space characters. 4 spaces per indent level will be generated.
 */
function STRIndent(num /* : Integer */) /* : String */
{
 return new Array(num + 1).join(" ");
}

/**
 * Tests the provided string to determine if it appears to be a valid GUID format.
 *
 * @param[in] (String) The string value to be tested
 *
 * @return A boolean indicating if the provided string appears to be a guid.
 */
function STRIsGUID(s /* : String */) /* : Boolean */
{
 var regexGUID = /^\{?[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}\}?$/
 return regexGUID.test(s);
}

/**
 * Insert contents of array into the original message by index like {0}, {1}, etc. Similar to String.Format method in C#.
 *
 * @param[in] (String) The string to be formatted. Should contain placeholders like {0}, {1}, etc which correspond to index of item to be inserted from params array
 * @param[in] (Array) The values to be inserted into original string. E.g. [1, "Hello", "World!"]
 *
 * @return A formatted message string after performing replacements.
 */
function STRFormat(message /* : String */, params /* : Array */)
{
 var result = message;
 for (var p=0; p < params.length; p++)
 {
 //use regular expression to ensure all matching instances are replaced
 result = result.replace(new RegExp("\\{" + p + "\\}", "g"), params[p]);
 }
 return result;
}

/**
 * Get a specific name/value pair from within a Style string.
 *
 * @param[in] (String) The full EA Style field
 * @param[in] (String) The name of the option to get from this field
 * @param[in] (String) The delimiter used to split the options in this Style string (E.g. ";")
 *
 * @return String containing a name/value pair from a standard EA Style field.
 */
function STRGetOption(styleString /* : String */, optionName /* : String */, delimiter /* : String */)
{
 var index = styleString.indexOf( optionName );
 var s = "";
 if (index >= 0)
 {
 var delimiterIndex = styleString.indexOf( delimiter, index );
 s = styleString.substring(index, delimiterIndex);
 }
 return s;
}

/**
 * Get the value part from a name/value pair (i.e. anything after the equals sign)
 *
 * @param[in] (String) The name/value pair retrieved from an EA Style field.
 *
 * @return The value part of a name/value pair.
 */

function STRGetValue(option /* : String */) /* : String */
{
 var s = "";
 var index = option.indexOf( "=" );
 s = option.substring(index+1);

 return s;
}


/**
 * Set a specific option within a style string. Replaces existing value if found or appends to end of the style string if option not found.
 *
 * @param[in] (String) The original EA Style field
 * @param[in] (String) The name of the option to set in this field
 * @param[in] (String) The value of the option to set in this field
 * @param[in] (String) The delimiter used to split the options in this Style string (E.g. ";")
 *
 * @return The complete Style string after adding or updating the specified option.
 */
function STRSetOption(styleString /* : String */, optionName /* : String */, newValue /* : String */, delimiter /* : String */) /* : String */
{
 var newOption = optionName + "=" + newValue;

 //check for existing option
 var currentOption = STRGetOption( styleString, optionName, delimiter );

 if (currentOption.length > 0)
 {
 //if the option already exists, replace with the new value
 styleString = styleString.replace(currentOption, newOption);
 }
 else
 {
 //if option not found, append new option to the style string
 styleString += newOption + delimiter;
 }
 
 return styleString;
}
"/>
</DataRow>
<DataRow>
<Column name="ScriptID" value="10"/>
<Column name="ScriptCategory" value="605A62F7-BCD0-4845-A8D0-7DC45B4D2E3F"/>
<Column name="ScriptName" value="{FEFD3D98-190A-46f5-BD57-1914626A117C}"/>
<Column name="ScriptAuthor" value="{6F2AAA79-A828-415b-8FCF-6C374FC7F45B}"/>
<Column name="Notes" value="<Script Name="JavaScript-TaggedValue" Type="Internal" Language="JavaScript"/>"/>
<Column name="Script" value="/**
 * @file JavaScript-TaggedValue 
 * This script library contains helper functions for working with Tagged Values. Functions 
 * provided by this module are identified by the prefix TV.
 *
 * @author Sparx Systems
 * @date 2020-07-21
 */
 
 /**
 * Retrieves the TaggedValue value from the provided element whose name matches the specified name.
 * If the element does not exist, or does not contain a TaggedValue with the specified name, null
 * is returned.
 *
 * @param[in] theElement (EA.Element) The element to retrieve the TaggedValue value from
 * @param[in] taggedValueName (String) The name of the TaggedValue whose value will be retrieved
 *
 * @return The value of the requested TaggedValue in variant form
 */
function TVGetElementTaggedValue( theElement /* : EA.Element */, taggedValueName /* : String */, defaultValue /* : String */ ) /* : variant */
{
 var result = defaultValue;
 
 if ( theElement != null && taggedValueName.length > 0 )
 {
 var taggedValue as EA.TaggedValue;
 taggedValue = theElement.TaggedValues.GetByName( taggedValueName );
 
 if ( taggedValue != null )
 result = taggedValue.Value;
 }
 
 return result; 
}

/**
 * Sets the specified TaggedValue on the provided element. If the provided element does not already
 * contain a TaggedValue with the specified name, a new TaggedValue is created with the requested
 * name and value. If a TaggedValue already exists with the specified name then action to take is
 * determined by the replaceExisting variable. If replaceExisting is set to true, the existing value
 * is replaced with the specified value, if not, a new TaggedValue is created with the new value.
 *
 * @param[in] theElement (EA.Element) The element to set the TaggedValue value on
 * @param[in] taggedValueName (String) The name of the TaggedValue to set
 * @param[in] taggedValueValue (variant) The value of the TaggedValue to set
 * @param[in] replaceExisting (boolean) If a TaggedValue of the same name already exists, specifies 
 * whether to replace it, or create a new TaggedValue.
 */
function TVSetElementTaggedValue( theElement /* : EA.Element */, taggedValueName /* : String */, taggedValueValue /* : variant */, replaceExisting /* : boolean */ ) /* : void */
{
 if ( theElement != null && taggedValueName.length > 0 )
 {
 var taggedValue as EA.TaggedValue;
 taggedValue = null;
 
 // If replace existing was specified then attempt to get a tagged value from the element
 // with the provided name
 if ( replaceExisting )
 taggedValue = theElement.TaggedValues.GetByName( taggedValueName );
 
 if ( taggedValue == null )
 {
 taggedValue = theElement.TaggedValues.AddNew( taggedValueName, taggedValueValue );
 }
 else
 {
 taggedValue.Value = taggedValueValue;
 }
 
 taggedValue.Update();
 }
}"/>
</DataRow>
<DataRow>
<Column name="ScriptID" value="11"/>
<Column name="ScriptCategory" value="605A62F7-BCD0-4845-A8D0-7DC45B4D2E3F"/>
<Column name="ScriptName" value="{46034E94-998A-46b9-9441-96341C1F9A72}"/>
<Column name="ScriptAuthor" value="{6F2AAA79-A828-415b-8FCF-6C374FC7F45B}"/>
<Column name="Notes" value="<Script Name="JavaScript-XML" Type="Internal" Language="JavaScript"/>"/>
<Column name="Script" value="!INC JavaScriptLib.JavaScript-Logging
//!INC EAScriptLib.JavaScript-Logging

/**
 * @file JavaScript-XML
 * This script library contains helper functions to assist with reading and writing XML. Functions 
 * provided by this module are identified by the prefix XML
 * 
 * @author Sparx Systems
 * @date 2020-07-21
 */

//Set by XMLCreateXMLObject depending on which version of the DOM Object is successfully created.
var XMLDOMDocumentVersion = "";

/**
 * Attempts to create an MSXML2.DOMDocument object, depending upon the versions of MSXML available
 * on the current system. It will try to create in order of preference: 6.0, 3.0 or 4.0.
 *
 * @return A new XML DOMDocument object ready for processing. If the object could not be 
 * created, the function will return null. Errors will be logged at the WARNING level.
 * Success will be logged at the TRACE level.
 */
function XMLCreateXMLObject() /* : MSXML2.DOMDocument */
{
 var xmlDOM = null;
 var ProgId = "";
 var attempt = 0;
 
 while (xmlDOM == null)
 {
 switch (attempt++)
 {
 case 0: ProgId = "MSXML2.DOMDocument.6.0"; break; //MSXML 6.0
 case 1: ProgId = "MSXML2.DOMDocument.3.0"; break; //MSXML 3.0
 case 2: ProgId = "MSXML2.DOMDocument"; break; //MSXML 3.0
 case 3: ProgId = "MSXML2.DOMDocument.4.0"; break; //MSXML 4.0
 default: LOGWarning("Could not create DOMDocument."); return;
 }
 try { xmlDOM = new COMObject( ProgId ); LOGTrace("DOMDocument object created: " + ProgId); } catch (err) { xmlDOM = null; }
 }
 
 if (xmlDOM != null)
 {
 xmlDOM.validateOnParse = false;
 xmlDOM.async = false;
 XMLDOMDocumentVersion = ProgId;
 }
 
 return xmlDOM;
}

/**
 * Parses a string containing an XML document into an XML DOMDocument object.
 *
 * @param[in] xmlDocument (String) A String value containing an XML document.
 *
 * @return An XML DOMDocument representing the parsed XML Document. If the document could not be 
 * parsed, the function will return null. Parse errors will be logged at the WARNING level
 */
function XMLParseXML( xmlDocument /* : String */ ) /* : MSXML2.DOMDocument */
{
 // Create a new DOM object
 var xmlDOM = XMLCreateXMLObject();
 
 // Parse the string into the DOM
 var parsed = xmlDOM.loadXML( xmlDocument );
 if ( !parsed )
 {
 // A parse error occured, so log the last error and set the return value to null
 LOGWarning( _XMLDescribeParseError(xmlDOM.parseError) );
 xmlDOM = null;
 }
 
 return xmlDOM;
}

/**
 * Parses an XML file into an XML DOMDocument object.
 *
 * @param[in] xmlPath (String) A String value containing the path name to the XML file to parse.
 *
 * @return An XML DOMDocument representing the parsed XML File. If the document could not be 
 * parsed, the function will return null. Parse errors will be logged at the WARNING level
 */
function XMLReadXMLFromFile( xmlPath /* : String */ ) /* : MSXML2.DOMDocument */
{
 var xmlDOM = XMLCreateXMLObject();
 xmlDOM.validateOnParse = true;
 xmlDOM.async = true;

 var loaded = xmlDOM.load( xmlPath );
 if ( !loaded )
 {
 LOGWarning( _XMLDescribeParseError(xmlDOM.parseError) );
 xmlDOM = null;
 }
 
 return xmlDOM;
}

/**
 * Saves the provided DOMDocument to the specified file path.
 *
 * @parameter[in] xmlDOM (MSXML2.DOMDocument) The XML DOMDocument to save
 * @parameter[in] filePath (String) The path to save the file to
 * @parameter[in] xmlDeclaration (Boolean) Whether the XML declaration should be included in the 
 * output file
 * @parameter[in] indent (Boolean) Whether the output should be formatted with indents
 */
function XMLSaveXMLToFile( xmlDOM /* : MSXML2.DOMDocument */, filePath /* : String */ , 
 xmlDeclaration /* : Boolean */, indent /* : Boolean */ ) /* : void */
{
 // Create the file to write out to
 var fileIOObject = new COMObject( "Scripting.FileSystemObject" );
 var outFile = fileIOObject.CreateTextFile( filePath, true );
 
 // Create the formatted writer
 var xmlWriter = new COMObject( "MSXML2.MXXMLWriter" );
 xmlWriter.omitXMLDeclaration = !xmlDeclaration;
 xmlWriter.indent = indent;
 
 // Create the sax reader and assign the formatted writer as its content handler
 var xmlReader = new COMObject( "MSXML2.SAXXMLReader" );
 xmlReader.contentHandler = xmlWriter;
 
 // Parse and write the output
 xmlReader.parse( xmlDOM );
 outFile.Write( xmlWriter.output );
 outFile.Close();
}

/**
 * Retrieves the value of the named attribute that belongs to the node at nodePath.
 *
 * @param[in] xmlDOM (MSXML2.DOMDocument) The XML document that the node resides in
 * @param[in] nodePath (String) The XPath path to the node that contains the desired attribute
 * @param[in] attributeName (String) The name of the attribute whose value will be retrieved
 *
 * @return A String representing the value of the requested attribute
 */
function XMLGetAttributeValue( xmlDOM /* : MSXML2.DOMDocument */, nodePath /* : String */, 
 attributeName /* : String */ ) /* : String */
{
 var value = "";
 
 // Get the node at the specified path
 var node = xmlDOM.selectSingleNode( nodePath );
 if ( node )
 {
 // Get the node's attributes
 var attributeMap = node.attributes;
 if ( attributeMap != null )
 {
 // Get the specified attribute
 var attribute = attributeMap.getNamedItem( attributeName )
 if ( attribute != null )
 {
 // Get the attribute's value
 value = attribute.value;
 }
 else
 {
 // Specified attribute not found
 LOGWarning( "Node at path " + nodePath + 
 " does not contain an attribute named: " + attributeName );
 }
 }
 else
 {
 // Node cannot contain attributes
 LOGWarning( "Node at path " + nodePath + " does not contain attributes" );
 }
 }
 else
 {
 // Specified node not found
 LOGWarning( "Node not found at path: " + nodePath );
 }
 
 return value;
}

/**
 * Returns the text value of the XML node at nodePath
 *
 * @param[in] xmlDOM (MSXML2.DOMDocument) The XML document that the node resides in
 * @param[in] nodePath (String) The XPath path to the desired node
 *
 * @return A String representing the desired node's text value
 */
function XMLGetNodeText( xmlDOM /* : MSXML2.DOMDocument */, nodePath /* : String */ ) /* : String */
{
 var value = "";
 
 // Get the node at the specified path
 var node = xmlDOM.selectSingleNode( nodePath );
 if ( node != null )
 {
 value = node.text;
 }
 else
 {
 // Specified node not found
 LOGWarning( "Node not found at path: " + nodePath ); 
 }
 
 return value;
}

/**
 * Returns an array populated with the text values of the XML nodes at nodePath
 *
 * @param[in] xmlDOM (MSXML2.DOMDocument) The XML document that the nodes reside in
 * @param[in] nodePath (String) The XPath path to the desired nodes
 *
 * @return An array of Strings representing the text values of the desired nodes
 */
function XMLGetNodeTextArray( xmlDOM /* : MSXML2.DOMDocument */, nodePath /* : String */ ) /* : Array */
{
 var nodeList = xmlDOM.documentElement.selectNodes( nodePath );
 var textArray = [];
 
 for ( var i = 0 ; i < nodeList.length ; i++ )
 {
 var currentNode = nodeList.nextNode();
 if (currentNode != null)
 {
 textArray.push(currentNode.text);
 }
 }
 
 return textArray;
}

/**
 * Returns a string containing the value of the named attribute owned by the provided DOM Node.
 * Empty string is returned if named node not found.
 *
 * @param[in] node (IXMLDOMNode) The XML document node being queried
 * @param[in] attName (String) The name of the attribute
 *
 * @return String representing the text value of the named attribute
 */
function XMLGetNamedAttribute( node /* : IXMLDOMNode */, attName /* : String */ ) /* : String */
{
 var value = "";
 
 var attrib = node.attributes.getNamedItem( attName );
 if (attrib != null)
 {
 value = attrib.value;
 }
 else
 {
 LOGWarning( "Attribute not found: " + attName );
 }
 
 return value;
}

/**
 * Returns a description of the provided parse error
 *
 * @return A String description of the last parse error that occured
 */
function _XMLDescribeParseError( parseError )
{
 var reason = "Unknown Error";
 
 // If we have an error
 if ( typeof(parseError) != "undefined" )
 {
 // Format a description of the error
 reason = "XML Parse Error at [line: " + parseError.line + ", pos: " + 
 parseError.linepos + "] " + parseError.reason;
 }
 
 return reason;
}
"/>
</DataRow>
<DataRow>
<Column name="ScriptID" value="12"/>
<Column name="ScriptCategory" value="605A62F7-BCD0-4845-A8D0-7DC45B4D2E3F"/>
<Column name="ScriptName" value="{5CDD3755-801D-4f21-BE9F-CE37021E049F}"/>
<Column name="ScriptAuthor" value="{9BB70D4F-3874-4116-8185-AB0730F25791}"/>
<Column name="Notes" value="<Script Name="JavaScript-Recursive Model Dump Example" Type="Internal" Language="JavaScript"/>
"/>
<Column name="Script" value="!INC JavaScriptLib.JavaScript-EAConstants
!INC JavaScriptLib.JavaScript-Enumerator

// Iterates through an EAP file using recursion.
// 
// Related APIs
// =================================================================================
// Repository API - http://www.sparxsystems.com/uml_tool_guide/index.html?repository3.htm
//
function RecursiveModelDumpExample()
{
 Session.Output( "JavaScript RECURSIVE MODEL DUMP EXAMPLE" );
 Session.Output( "=======================================" );
 
 // Iterate through all models in the project
 var modelEnumerator = new Enumerator( Models );
 while ( !modelEnumerator.atEnd() )
 {
 var currentModel as EA.Package;
 currentModel = modelEnumerator.item();
 
 // Recursively process this package
 DumpPackage( "", currentModel );
 
 modelEnumerator.moveNext();
 }
 
 Session.Output( "Done!" );
}

//
// Outputs the packages name and elements, and then recursively processes any child 
// packages
//
// Parameters:
// - indent A string representing the current level of indentation
// - thePackage The package object to be processed
//
function DumpPackage( indent, thePackage )
{
 // Cast thePackage to EA.Package so we get intellisense
 var currentPackage as EA.Package;
 currentPackage = thePackage;
 
 // Add the current package's name to the list
 Session.Output( indent + currentPackage.Name + " (PackageID=" + 
 currentPackage.PackageID + ")" );
 
 // Dump the elements this package contains
 DumpElements( indent + " ", currentPackage );
 
 // Recursively process any child packages
 var childPackageEnumerator = new Enumerator( currentPackage.Packages );
 while ( !childPackageEnumerator.atEnd() )
 {
 var childPackage as EA.Package;
 childPackage = childPackageEnumerator.item();
 
 DumpPackage( indent + " ", childPackage );
 
 childPackageEnumerator.moveNext();
 }
}

//
// Outputs the elements of the provided package to the Script output window
//
// Parameters:
// - indent A string representing the current level of indentation
// - thePackage The package object to be processed
//
function DumpElements( indent, thePackage )
{
 // Cast thePackage to EA.Package so we get intellisense
 var currentPackage as EA.Package;
 currentPackage = thePackage;
 
 // Iterate through all elements and add them to the list
 var elementEnumerator = new Enumerator( currentPackage.Elements );
 while ( !elementEnumerator.atEnd() )
 {
 var currentElement as EA.Element;
 currentElement = elementEnumerator.item();
 
 Session.Output( indent + "::" + currentElement.Name +
 " (" + currentElement.Type +
 ", ID=" + currentElement.ElementID + ")" );
 
 elementEnumerator.moveNext();
 }
}

RecursiveModelDumpExample();
"/>
</DataRow>
<DataRow>
<Column name="ScriptID" value="13"/>
<Column name="ScriptCategory" value="605A62F7-BCD0-4845-A8D0-7DC45B4D2E3F"/>
<Column name="ScriptName" value="{2C598093-9E99-40f6-9765-BDAC70F7AD1C}"/>
<Column name="ScriptAuthor" value="{9BB70D4F-3874-4116-8185-AB0730F25791}"/>
<Column name="Notes" value="<Script Name="JavaScript-Restore Baselines" Type="Internal" Language="JavaScript"/>
"/>
<Column name="Script" value="!INC Local JavaScriptLib.JavaScript-EAConstants

// The Project interface is what is required to work with baselines.
var project as EA.Project;
project = GetProjectInterface();

// The simplest possible merge instruction. Restore everything from baseline.
var mergeInstructions;
mergeInstructions = "<Merge><MergeItem guid=\"RestoreAll\" /></Merge>";

function CreateXMLObject()
{
 var xmlDOM;
 try
 {
 xmlDOM = new ActiveXObject( "MSXML2.DOMDocument.4.0" );
 }
 catch(e)
 {
 xmlDOM = new ActiveXObject( "MSXML2.DOMDocument.6.0" );
 }
 
 xmlDOM.validateOnParse = false;
 xmlDOM.async = false;
 
 return xmlDOM;
}

// Iterate over a collection of packages to find any packages
// that need the baseline restored.
function RestoreBaselinesInCollection(collection)
{
 var package as EA.Package;
 for(var idx = 0; idx < collection.Count; idx++)
 {
 package = collection.GetAt(idx);
 RestoreBaselinesInPackage(package);
 }
}

function RestoreBaselinesInPackage(package)
{
 // There's no point doing children if we've just
 // restored a top level package, so don't process
 // children to save time.
 var processChildren = true;
 
 // We're only intersted in restoring baselines
 // from packages with the stereotype "test data".
 var PkgElement as EA.Element;
 PkgElement = package.Element;
 if(PkgElement != null)
 {
 // Look at each stereotype, if any match then continue.
 var stereotypes = PkgElement.StereotypeEx.split(",");
 for(id in stereotypes)
 {
 if(stereotypes[id] == "test data")
 {
 RestoreBaselines(package);
 processChildren = false;
 }
 }
 }
 
 // Now process child packages.
 if(processChildren)
 RestoreBaselinesInCollection(package.Packages);
}

function RestoreBaselines(package)
{
 // EA returns the list of baselines as xml. So we need
 // to load the XML and get the guid of a baseline.
 var sXML = project.GetBaselines(package.PackageGUID, "");
 var xml = CreateXMLObject();
 if(xml.loadXML(sXML))
 {
 var node;
 var baselineGUID;
 // We can't distinguish which baseline is the latest
 // so we are naively only getting a single node.
 node = xml.selectSingleNode("//EA.BaseLines//Baseline");
 if(node)
 {
 baselineGUID = node.getAttribute("guid");
 }

 if(baselineGUID == "")
 {
 Session.Output("Failed to find baseline for package: " + package.Name);
 }

 // Restore all from the baseline.
 Session.Output("Restoring from baseline for package " + package.Name);
 project.DoBaselineMerge(package.PackageGUID, baselineGUID, mergeInstructions, "");
 }
 else
 {
 Session.Output("Failed to load baseline list for package: " + package.Name);
 }
}

// This is a long operation and running it while testing is being done
// may have unexpected consequences. So prompt the user before beginning.
if(Session.Prompt("Are you sure you want to restore all test data to baseline?", promptYESNO) == resultYes)
{
 Repository.ClearOutput("Script");
 RestoreBaselinesInCollection(Models);
}"/>
</DataRow>
<DataRow>
<Column name="ScriptID" value="14"/>
<Column name="ScriptCategory" value="605A62F7-BCD0-4845-A8D0-7DC45B4D2E3F"/>
<Column name="ScriptName" value="{AD72DEB1-850D-4c54-96D3-72F7CDA21AC8}"/>
<Column name="ScriptAuthor" value="{9BB70D4F-3874-4116-8185-AB0730F25791}"/>
<Column name="Notes" value="<Script Name="JavaScript-Attribute Lifecycle Example" Type="Internal" Language="JavaScript"/>
"/>
<Column name="Script" value="!INC JavaScriptLib.JavaScript-EAConstants

/*
 * An example of working with attributes.
 *
 * NOTE: Requires an element to be selected in the Project Browser
 * Related APIs
 * =================================================================================
 * Attribute API - http://www.sparxsystems.com/enterprise_architect_user_guide/14.1/automation_and_scripting/attribute.html
 */
function AttributeLifeCycleExample()
{
 // Show the script output window
 Repository.EnsureOutputVisible( "Script" );

 // Get the currently selected element in the tree to work on
 var theElement as EA.Element;
 theElement = Repository.GetTreeSelectedObject();
 
 if ( theElement != null && theElement.ObjectType == otElement )
 {
 var addedAttributeID = 0;

 Session.Output( "JavaScript ATTRIBUTE LIFE CYCLE EXAMPLE" );
 Session.Output( "=======================================" );
 Session.Output( "Working on element '" + theElement.Name + "' (Type=" + theElement.Type +
 ", ID=" + theElement.ElementID + ")" );
 
 // ==================================================
 // ADD AN ATTRIBUTE
 // ==================================================
 // Create an attribute to work on
 var attributes as EA.Collection;
 attributes = theElement.Attributes;
 
 var newAttribute as EA.Attribute;
 newAttribute = attributes.AddNew( "m_number", "int" );
 newAttribute.Update();
 attributes.Refresh();
 
 addedAttributeID = newAttribute.AttributeID;
 
 Session.Output( "Added attribute: " + newAttribute.Name +
 "(Type=" + newAttribute.Type +
 ", ID=" + addedAttributeID + ")" );
 
 // ==================================================
 // MANAGE ATTRIBUTE CONSTRAINTS
 // ==================================================
 // Add an attribute constraint
 var constraints as EA.Collection;
 constraints = newAttribute.Constraints;
 
 var newConstraint as EA.AttributeConstraint;
 newConstraint = constraints.AddNew( "> 123", "Precision" );
 newConstraint.Update();
 constraints.Refresh();
 
 Session.Output( "Added constraint: " + newConstraint.Name );
 
 // Search the constraint collection for the added constraint and delete it
 for ( var i = 0; i < constraints.Count ; i++ )
 {
 var currentConstraint as EA.AttributeConstraint;
 currentConstraint = constraints.GetAt( i );
 
 Session.Output( "Attribute Constraint: " + currentConstraint.Name );
 
 // Delete the constraint we just added
 if ( currentConstraint.Name == "> 123" )
 {
 constraints.DeleteAt( i, false );
 Session.Output( "Deleted Constraint: " + currentConstraint.Name );
 }
 }
 
 constraints = null;
 
 // ==================================================
 // MANAGE ATTRIBUTE TAGGED VALUES
 // ==================================================
 // Add a tagged value
 var tags as EA.Collection;
 tags = newAttribute.TaggedValues;
 
 var newTag as EA.AttributeTag;
 newTag = tags.AddNew( "MyAttributeTag", "Number" );
 newTag.Update();
 tags.Refresh();
 
 var newTagID = newTag.TagID;
 Session.Output( "Added tag: " + newTag.Name + " (ID=" + newTagID + ")" );
 
 newTag = null;
 
 // Search the tag collection for the added tag and delete it
 for ( var i = 0; i < tags.Count ; i++ )
 {
 var currentTag as EA.AttributeTag;
 currentTag = tags.GetAt( i );
 
 Session.Output( "Attribute Tag: " + currentTag.Name );
 
 // Delete the tag we just added
 if ( currentTag.Name == "MyAttributeTag" )
 {
 tags.DeleteAt( i, false );
 Session.Output( "Deleted Tag: " + currentTag.Name + 
 " (ID=" + currentTag.TagID + ")" );
 }
 }
 
 tags = null;
 
 // ==================================================
 // LIST AND DELETE ATTRIBUTES
 // ==================================================
 newAttribute = null;
 
 // List attributes
 for ( var i = 0 ; i < attributes.Count ; i++ )
 {
 var currentAttribute as EA.Attribute;
 currentAttribute = attributes.GetAt( i );
 
 Session.Output( "Attribute: " + currentAttribute.Name );
 
 // Delete the attribute we added
 if ( currentAttribute.AttributeID == addedAttributeID )
 {
 attributes.DeleteAt( i, true );
 Session.Output( "Deleted Attribute: " + currentAttribute.Name +
 " (Type=" + currentAttribute.Type +
 ", ID=" + currentAttribute.AttributeID + ")" );
 }
 }
 
 Session.Output( "Done!" );
 }
 else
 {
 // No item selected in the tree, or the item selected was not an element
 Session.Prompt( "This script requires an element be selected in the Project Browser.\n" +
 "Please select an element in the Project Browser and try again.", promptOK );
 }
}

AttributeLifeCycleExample();
"/>
</DataRow>
<DataRow>
<Column name="ScriptID" value="15"/>
<Column name="ScriptCategory" value="605A62F7-BCD0-4845-A8D0-7DC45B4D2E3F"/>
<Column name="ScriptName" value="{AECFD02B-B6EB-403e-BCA9-E5D5F7FAD152}"/>
<Column name="ScriptAuthor" value="{9BB70D4F-3874-4116-8185-AB0730F25791}"/>
<Column name="Notes" value="<Script Name="JavaScript-Dictionary Example" Type="Internal" Language="JavaScript"/>
"/>
<Column name="Script" value="!INC JavaScriptLib.JavaScript-EAConstants

/*
 * @Status: Successfully converted to JavaScript and tested
 * An example of working with JScript dictionaries. A Dictionary object is the 
 * equivalent of a PERL associative array. Items can be any form of data, and 
 * are stored in the array. Each item is associated with a unique key. The key 
 * is used to retrieve an individual item and is usually an integer or a string, 
 * but can be anything except an array.
 * 
 * Related APIs
 * ============================================================================= 
 * Dictionary Object - https://docs.microsoft.com/en-us/office/vba/language/reference/user-interface-help/dictionary-object
 */
 
function DictionaryExample()
{
 // Show the script output window
 Repository.EnsureOutputVisible( "Script" );

 Session.Output( "==============================" );
 Session.Output( "JavaScript Dictionary Example" );
 Session.Output( "==============================" );
 
 // Instantiate an object of class Scripting.Dictionary
 //var theDictionary = new ActiveXObject("Scripting.Dictionary");
 //var theDictionary = getActiveXObject("Scripting.Dictionary");
 var theDictionary = new COMObject('Scripting.Dictionary');
 
 // Add items to the Dictionary. Keys are usually strings or integers, but can be any type
 // except for an array.
 theDictionary.Add( "a", "Alpha" );
 theDictionary.Add( "b", "Bravo" );
 theDictionary.Add( "c", "Charlie" );
 theDictionary.Add( "d", "Delta" );
 theDictionary.Add( "e", "Echo" );
 
 // The Count property can be used to determine the amount of items in the Dictionary
 var itemCount = theDictionary.Count;
 Session.Output( "The dictionary has " + itemCount + " item(s) in it." );
 
 // The Exists method can be used to determine if there is an entry in the Dictionary mapped
 // against the provided key:
 if ( theDictionary.Exists("a") )
 Session.Output( "There is an entry for 'a' in the Dictionary" );
 else
 Session.Output( "There is no entry for 'a' in the Dictionary" );
 
 if ( theDictionary.Exists("f") )
 Session.Output( "There is an entry for 'f' in the Dictionary" );
 else
 Session.Output( "There is no entry for 'f' in the Dictionary" );
 
 
 // The Item property can be used to retrieve an item mapped against a provided key
 var theItem = theDictionary.Item( "d","aaa" );
 Session.Output( "The entry for 'd' is: '" + theItem + "'" );
 
 // The Items method returns all items in the map. The Items collection is returned
 // as a VB type array which must be wrapped with a VBArray object to be accessed from
 // JScript.
 Session.Output( "A dump of the entire dictionary:");
// var allItems = theDictionary.Items();
// var allItems = new VBArray( allItemsVB );
// var allItemsArray = allItemsVB.toArray();
 var allItemsArray = theDictionary.Items();
 
 // Iterate through all items in the dictionary and display them
 for ( var i = 0 ; i < itemCount ; i++ )
 Session.Output( "Item " + i + ": " + allItemsArray[i] );
 
 // The Remove method removes the item mapped to the provided key
 theDictionary.Remove( "c" );
 Session.Output( "The dictionary has " + theDictionary.Count + " item(s) in it." );
 
 // The RemoveAll method removes all items in the dictionary
 Session.Output( "Removing items from the dictionary" );
 theDictionary.RemoveAll();
 Session.Output( "The dictionary has " + theDictionary.Count + " item(s) in it." );
 
 Session.Output( "=====" );
 Session.Output( "Done!" );
 Session.Output( "=====" );
}

DictionaryExample();
"/>
</DataRow>
<DataRow>
<Column name="ScriptID" value="16"/>
<Column name="ScriptCategory" value="ScriptDebugging"/>
<Column name="ScriptName" value="ScriptDebugging"/>
<Column name="ScriptAuthor" value="ScriptDebugging"/>
<Column name="Notes" value="<?xml version="1.0"?>
<DATA><Debugger value="Scripting"/></DATA>
"/>
<Column name="Script" value=" "/>
</DataRow>
<DataRow>
<Column name="ScriptID" value="17"/>
<Column name="ScriptCategory" value="ScriptDebugging"/>
<Column name="ScriptName" value="ScriptDebugging"/>
<Column name="ScriptAuthor" value="ScriptDebugging"/>
<Column name="Notes" value="<?xml version="1.0"?>
<DATA><Debugger value="Scripting"/></DATA>
"/>
<Column name="Script" value=" "/>
</DataRow>
<DataRow>
<Column name="ScriptID" value="18"/>
<Column name="ScriptCategory" value="605A62F7-BCD0-4845-A8D0-7DC45B4D2E3F"/>
<Column name="ScriptName" value="{38445D81-46E0-4734-B779-56A415228460}"/>
<Column name="ScriptAuthor" value="{9BB70D4F-3874-4116-8185-AB0730F25791}"/>
<Column name="Notes" value="<Script Name="JavaScript-Table Counts" Type="Internal" Language="JavaScript"/>
"/>
<Column name="Script" value="!INC JavaScriptLib.JavaScript-EAConstants
/* @Status Tested Successfully
 * Script Name: 
 * Author: 
 * Purpose: 
 * Date: 
 */
 
function main()
{
 dumpcount("t_xref");
dumpcount("t_roleconstraint");
dumpcount("t_authors");
dumpcount("t_cardinality");
dumpcount("t_category");
dumpcount("t_clients");
dumpcount("t_complexitytypes");
dumpcount("t_connectortypes");
dumpcount("t_constants");
dumpcount("t_constrainttypes");
dumpcount("t_datatypes");
dumpcount("t_ecf");
dumpcount("t_efforttypes");
dumpcount("t_genopt");
dumpcount("t_lists");
dumpcount("t_mainttypes");
dumpcount("t_metrictypes");
dumpcount("t_objecttypes");
dumpcount("t_ocf");
dumpcount("t_package");
dumpcount("t_problemtypes");
dumpcount("t_projectroles");
dumpcount("t_propertytypes");
dumpcount("t_requiretypes");
dumpcount("t_resources");
dumpcount("t_risktypes");
dumpcount("t_rtfreport");
dumpcount("t_scenariotypes");
dumpcount("t_statustypes");
dumpcount("t_stereotypes");
dumpcount("t_tcf");
dumpcount("t_testclass");
dumpcount("t_testtypes");
dumpcount("t_trxtypes");
dumpcount("t_diagramtypes");
dumpcount("t_glossary");
dumpcount("t_implement");
dumpcount("t_object");
dumpcount("t_secgroup");
dumpcount("t_secpermission");
dumpcount("t_secuser");
dumpcount("t_diagram");
dumpcount("t_method");
dumpcount("t_objectconstraint");
dumpcount("t_objecteffort");
dumpcount("t_objectfiles");
dumpcount("t_objectmetrics");
dumpcount("t_objectproblems");
dumpcount("t_objectproperties");
dumpcount("t_objectrequires");
dumpcount("t_objectresource");
dumpcount("t_objectrisks");
dumpcount("t_objectscenarios");
dumpcount("t_objecttests");
dumpcount("t_objecttrx");
dumpcount("t_operation");
dumpcount("t_palette");
dumpcount("t_attribute");
dumpcount("t_connector");
dumpcount("t_diagramlinks");
dumpcount("t_diagramobjects");
dumpcount("t_issues");
dumpcount("t_operationparams");
dumpcount("t_operationposts");
dumpcount("t_operationpres");
dumpcount("t_attributeconstraints");
dumpcount("t_attributetag");
dumpcount("t_connectorconstraint");
dumpcount("t_connectortag");
dumpcount("t_document");
dumpcount("t_files");
dumpcount("t_html");
dumpcount("t_image");
dumpcount("t_operationtag");
dumpcount("t_paletteitem");
dumpcount("t_phase");
dumpcount("t_rtf");
dumpcount("t_rules");
dumpcount("t_script");
dumpcount("t_secgrouppermission");
dumpcount("t_seclocks");
dumpcount("t_secusergroup");
dumpcount("t_secuserpermission");
dumpcount("t_snapshot");
dumpcount("t_taggedvalue");
dumpcount("t_tasks");
dumpcount("t_template");
dumpcount("t_testplans");
dumpcount("t_umlpattern");
dumpcount("t_version");
dumpcount("t_xrefsystem");
dumpcount("t_xrefuser");
dumpcount("usys_system");
dumpcount("t_secpolicies");
dumpcount("usystables");
};

function dumpcount( table)
{
 Session.Output("\nTABLE = " + table);
 s = Repository.SQLQuery("Select count(*) as RowCount from " + table);
 Session.Output(s);
};

main();"/>
</DataRow>
<DataRow>
<Column name="ScriptID" value="19"/>
<Column name="ScriptCategory" value="ScriptDebugging"/>
<Column name="ScriptName" value="ScriptDebugging"/>
<Column name="ScriptAuthor" value="ScriptDebugging"/>
<Column name="Notes" value="<?xml version="1.0"?>
<DATA><Debugger value="Scripting"/></DATA>
"/>
<Column name="Script" value=" "/>
</DataRow>
<DataRow>
<Column name="ScriptID" value="20"/>
<Column name="ScriptCategory" value="ScriptDebugging"/>
<Column name="ScriptName" value="ScriptDebugging"/>
<Column name="ScriptAuthor" value="ScriptDebugging"/>
<Column name="Notes" value="<?xml version="1.0"?>
<DATA><Debugger value="Scripting"/></DATA>
"/>
<Column name="Script" value=" "/>
</DataRow>
<DataRow>
<Column name="ScriptID" value="21"/>
<Column name="ScriptCategory" value="605A62F7-BCD0-4845-A8D0-7DC45B4D2E3F"/>
<Column name="ScriptName" value="{2F404CA2-DA90-4b79-A09B-EDB5E6E418F7}"/>
<Column name="ScriptAuthor" value="{9BB70D4F-3874-4116-8185-AB0730F25791}"/>
<Column name="Notes" value="<Script Name="JavaScript-Documentation Example" Type="Internal" Language="JavaScript"/>
"/>
<Column name="Script" value="!INC JavaScriptLib.JavaScript-EAConstants

// @Status Succecfully converted and tested
// Demonstrates how the DocumentGenerator API can be used to programmatically generate RTF or HTML
// documentation for model elements
//
// This example generates documentation for all actors under the package currently selected in
// the project browser, and all use cases they are linked to
//
// Related APIs
// =================================================================================
//

var ACTOR_TEMPLATE = "Model Report";
var USECASE_TEMPLATE = "Use Case Details";

var DOCUMENTATION_TYPE = dtRTF;
var OUTPUT_FILE = "c:\\Users\\paulh\\Documents\\DocumentationExample.rtf";
function DocumentationExample()
{
 // Show the script output window
 Repository.EnsureOutputVisible( "Script" );

 Session.Output( "JavaScript DOCUMENTATION EXAMPLE" );
 Session.Output( "=======================================" );
 
 // Get the currently selected package in the Project Browser
 var currentPackage as EA.Package;
 currentPackage = Repository.GetTreeSelectedPackage();
 
 if ( currentPackage )
 {
 // Create a document generator object
 var docGenerator as EA.DocumentGenerator;
 docGenerator = Repository.CreateDocumentGenerator();
 
 // Create a new document
 if ( docGenerator.NewDocument("") )
 {
 var generationSuccess = false;
 
 // Insert table of contents
 docGenerator.InsertText( "Table of Contents", alignLeft );
 generationSuccess = docGenerator.InsertTableOfContents();
 if ( !generationSuccess )
 ReportWarning( "Error inserting Table of Contents: " + docGenerator.GetLastError() );
 
 // Insert page break
 docGenerator.InsertBreak( breakPage );
 
 // Iterate over all actors under the currently selected package
 var packageElements as EA.Collection;
 packageElements = currentPackage.Elements;
 for ( var i = 0 ; i < packageElements.Count ; i++ )
 {
 // Get the current element
 var currentElement as EA.Element;
 currentElement = packageElements.GetAt( i );
 
 if ( currentElement.Type == "Actor" )
 {
 // Generate Actor documentation
 ReportInfo( "Generating documentation for actor: " + currentElement.Name );
 generationSuccess = docGenerator.DocumentElement( currentElement.ElementID, 0, ACTOR_TEMPLATE );
 if ( !generationSuccess )
 ReportWarning( "Error generating Actor documentation: " + docGenerator.GetLastError() );
 
 // Generate documentation for all Use Cases connected to the current actor
 var elementConnectors as EA.Collection;
 elementConnectors = currentElement.Connectors;
 for ( var j = 0 ; j < elementConnectors.Count ; j++ )
 {
 // Get the current connector and the element that it connects to
 var currentConnector as EA.Connector;
 currentConnector = elementConnectors.GetAt( j );
 var connectedElement as EA.Element;
 connectedElement = Repository.GetElementByID( currentConnector.SupplierID );
 
 if ( connectedElement.Type == "UseCase" )
 {
 // Generate Use Case documentation
 ReportInfo( "Generating documentation for connected UseCase: " + connectedElement.Name );
 generationSuccess = docGenerator.DocumentElement( connectedElement.ElementID, 1, USECASE_TEMPLATE );
 if ( !generationSuccess )
 ReportWarning( "Error generating UseCase documentation: " + docGenerator.GetLastError() );
 }
 }
 
 }
 else
 {
 ReportInfo( "Skipping element " + currentElement.Name + " - not an actor" );
 }
 }
 
 // Save the document
 var saveSuccess = docGenerator.SaveDocument( OUTPUT_FILE, DOCUMENTATION_TYPE );
 if ( saveSuccess )
 ReportInfo( "Documentation complete!" );
 else
 ReportWarning( "Error saving file: " + docGenerator.GetLastError() );
 }
 else
 {
 ReportFatal( "Could not create new document: " + docGenerator.GetLastError() );
 }
 }
 else
 {
 ReportFatal( "This script requires a package to be selected in the Project Browser.\n" +
 "Please select a package in the Project Browser and try again." );
 }
 
 Session.Output( "Done!" );
 
}

function ReportInfo( message )
{
 Session.Output( "[INFO] " + message );
}

function ReportWarning( message )
{
 Session.Output( "[WARNING] " + message );
}

function ReportFatal( message )
{
 Session.Output( "[FATAL] " + message );
 Session.Prompt( message, promptOK );
}

DocumentationExample();"/>
</DataRow>
<DataRow>
<Column name="ScriptID" value="22"/>
<Column name="ScriptCategory" value="ScriptDebugging"/>
<Column name="ScriptName" value="ScriptDebugging"/>
<Column name="ScriptAuthor" value="ScriptDebugging"/>
<Column name="Notes" value="<?xml version="1.0"?>
<DATA><Debugger value="Scripting"/></DATA>
"/>
<Column name="Script" value=" "/>
</DataRow>
<DataRow>
<Column name="ScriptID" value="23"/>
<Column name="ScriptCategory" value="605A62F7-BCD0-4845-A8D0-7DC45B4D2E3F"/>
<Column name="ScriptName" value="{6CB5B59D-3E23-4771-80E9-029460A14100}"/>
<Column name="ScriptAuthor" value="{9BB70D4F-3874-4116-8185-AB0730F25791}"/>
<Column name="Notes" value="<Script Name="JavaScript-Element Extras Example" Type="Internal" Language="JavaScript"/>
"/>
<Column name="Script" value="!INC JavaScriptLib.JavaScript-EAConstants

/*
 * @Status Successfully converted and tested
 * Examples of how to access and use element extras - such as scenarios, constraints 
 * and requirements.
 *
 * NOTE: Requires an element to be selected in the Project Browser
 *
 * Related APIs
 * =================================================================================
 * Element API - http://www.sparxsystems.com/enterprise_architect_user_guide/15.1/automation_and_scripting/element2.html
 */
function ElementExtrasExample()
{
 // Show the script output window
 Repository.EnsureOutputVisible( "Script" );

 // Get the currently selected element in the tree to work on
 var theElement as EA.Element;
 theElement = Repository.GetTreeSelectedObject();
 
 if ( theElement != null && theElement.ObjectType == otElement )
 {
 var addedAttributeID = 0;

 Session.Output( "JavaScript ELEMENT EXTRAS EXAMPLE" );
 Session.Output( "=======================================" );
 Session.Output( "Working on element '" + theElement.Name + "' (Type=" + theElement.Type +
 ", ID=" + theElement.ElementID + ")" );
 
 // ==================================================
 // MANAGE ELEMENT CONSTRAINTS
 // ==================================================
 Session.Output( "Constraints" );
 
 // Add a new constraint
 var constraints as EA.Collection;
 constraints = theElement.Constraints;
 
 var newConstraint as EA.Constraint;
 newConstraint = constraints.AddNew( "MyConstraint", "Pre-condition" );
 newConstraint.Update();
 constraints.Refresh();
 
 Session.Output( " Added new Constraint: " + newConstraint.Name );
 
 newConstraint = null;
 
 // List all element constraints
 for ( var i = 0 ; i < constraints.Count ; i++ )
 {
 var currentConstraint as EA.Constraint;
 currentConstraint = constraints.GetAt( i );
 
 Session.Output( " Constraint: " + currentConstraint.Name );
 
 // Delete the constraint that we just added
 if ( currentConstraint.Name == "MyConstraint" )
 {
 constraints.DeleteAt( i, false );
 Session.Output( " Deleted Constraint: " + currentConstraint.Name );
 }
 }
 
 constraints = null;

 // ==================================================
 // MANAGE ELEMENT EFFORTS
 // ==================================================
 Session.Output( "Efforts" );
 
 // Add a new effort
 var efforts as EA.Collection;
 efforts = theElement.Efforts;
 
 var newEffort as EA.Effort;
 newEffort = efforts.AddNew( "MyEffort", "Coding" );
 newEffort.Update();
 efforts.Refresh();
 
 Session.Output( " Added new Effort: " + newEffort.Name );
 
 newEffort = null;
 
 // List all element efforts
 for ( var i = 0 ; i < efforts.Count ; i++ )
 {
 var currentEffort as EA.Effort;
 currentEffort = efforts.GetAt( i );
 
 Session.Output( " Effort: " + currentEffort.Name );
 
 // Delete the effort that we just added
 if ( currentEffort.Name == "MyEffort" )
 {
 efforts.DeleteAt( i, false );
 Session.Output( " Deleted Effort: " + currentEffort.Name );
 }
 }
 
 efforts = null;

 // ==================================================
 // MANAGE ELEMENT RISKS
 // ==================================================
 Session.Output( "Risks" );
 
 // Add a new risk
 var risks as EA.Collection;
 risks = theElement.Risks;
 
 var newRisk as EA.Risk;
 newRisk = risks.AddNew( "MyRisk", "Time" );
 newRisk.Update();
 risks.Refresh();
 
 Session.Output( " Added new Risk: " + newRisk.Name );
 
 newRisk = null;
 
 // List all element risks
 for ( var i = 0 ; i < risks.Count ; i++ )
 {
 var currentRisk as EA.Risk;
 currentRisk = risks.GetAt( i );
 
 Session.Output( " Risk: " + currentRisk.Name );
 
 // Delete the risk that we just added
 if ( currentRisk.Name == "MyRisk" )
 {
 risks.DeleteAt( i, false );
 Session.Output( " Deleted Risk: " + currentRisk.Name );
 }
 }
 
 risks = null;
 
 // ==================================================
 // MANAGE ELEMENT METRICS
 // ==================================================
 Session.Output( "Metrics" );
 
 // Add a new metric
 var metrics as EA.Collection;
 metrics = theElement.Metrics;
 
 var newMetric as EA.Metric;
 newMetric = metrics.AddNew( "MyMetric", "Cost" );
 newMetric.Update();
 metrics.Refresh();
 
 Session.Output( " Added new Metric: " + newMetric.Name );
 
 newMetric = null;
 
 // List all element metrics
 for ( var i = 0 ; i < metrics.Count ; i++ )
 {
 var currentMetric as EA.Metric;
 currentMetric = metrics.GetAt( i );
 
 Session.Output( " Metric: " + currentMetric.Name );
 
 // Delete the metric that we just added
 if ( currentMetric.Name == "MyMetric" )
 {
 metrics.DeleteAt( i, false );
 Session.Output( " Deleted Metric: " + currentMetric.Name );
 }
 }
 
 metrics = null;
 
 // ==================================================
 // MANAGE ELEMENT TAGGED VALUES
 // ==================================================
 Session.Output( "Tagged Values" );
 
 // Add a new tag
 var tags as EA.Collection;
 tags = theElement.TaggedValues;
 
 var newTag as EA.TaggedValue;
 newTag = tags.AddNew( "MyTag", "Number" );
 newTag.Update();
 tags.Refresh();
 
 Session.Output( " Added new Tag: " + newTag.Name );
 
 newTag = null;
 
 // List all element tag
 for ( var i = 0 ; i < tags.Count ; i++ )
 {
 var currentTag as EA.TaggedValue;
 currentTag = tags.GetAt( i );
 
 Session.Output( " Tag Value: " + currentTag.Name );
 
 // Delete the tagged value that we just added
 if ( currentTag.Name == "MyTag" )
 {
 tags.DeleteAt( i, false );
 Session.Output( " Deleted Tag: " + currentTag.Name );
 }
 }
 
 tags = null; 
 
 // ==================================================
 // MANAGE ELEMENT SCENARIOS
 // ==================================================
 Session.Output( "Scenarios" );
 
 // Add a new scenario
 var scenarios as EA.Collection;
 scenarios = theElement.Scenarios;
 
 var newScenario as EA.Scenario;
 newScenario = scenarios.AddNew( "MyScenario", "Alternate" );
 newScenario.Update();
 scenarios.Refresh();
 
 Session.Output( " Added new Scenario: " + newScenario.Name );
 
 newScenario = null;
 
 // List all element scenarios
 for ( var i = 0 ; i < scenarios.Count ; i++ )
 {
 var currentScenario as EA.Scenario;
 currentScenario = scenarios.GetAt( i );
 
 Session.Output( " Scenario: " + currentScenario.Name );
 
 // Delete the scenario that we just added
 if ( currentScenario.Name == "MyScenario" )
 {
 scenarios.DeleteAt( i, false );
 Session.Output( " Deleted Scenario: " + currentScenario.Name );
 }
 }
 
 scenarios = null;
 
 // ==================================================
 // MANAGE ELEMENT FILES
 // ==================================================
 Session.Output( "Files" );
 
 // Add a new file
 var files as EA.Collection;
 files = theElement.Files;
 
 var newFile as EA.File;
 newFile = files.AddNew( "MyFile", "doc" );
 newFile.Update();
 files.Refresh();
 
 Session.Output( " Added new File: " + newFile.Name );
 
 newFile = null;
 
 // List all element files
 for ( var i = 0 ; i < files.Count ; i++ )
 {
 var currentFile as EA.File;
 currentFile = files.GetAt( i );
 
 Session.Output( " File: " + currentFile.Name );
 
 // Delete the file that we just added
 if ( currentFile.Name == "MyFile" )
 {
 files.DeleteAt( i, false );
 Session.Output( " Deleted File: " + currentFile.Name );
 }
 }
 
 files = null;
 
 // ==================================================
 // MANAGE ELEMENT TESTS
 // ==================================================
 Session.Output( "Tests" );
 
 // Add a new test
 var tests as EA.Collection;
 tests = theElement.Tests;
 
 var newTest as EA.Test;
 newTest = tests.AddNew( "MyTest", "Unit" );
 newTest.Update();
 tests.Refresh();
 
 Session.Output( " Added new Test: " + newTest.Name );
 
 newTest = null;
 
 // List all element tests
 for ( var i = 0 ; i < tests.Count ; i++ )
 {
 var currentTest as EA.Test;
 currentTest = tests.GetAt( i );
 
 Session.Output( " Test: " + currentTest.Name );
 
 // Delete the test that we just added
 if ( currentTest.Name == "MyTest" )
 {
 tests.DeleteAt( i, false );
 Session.Output( " Deleted Test: " + currentTest.Name );
 }
 }
 
 tests = null;
 
 // ==================================================
 // MANAGE ELEMENT ISSUES
 // ==================================================
 Session.Output( "Issues" );
 
 // Add a new issue
 var issues as EA.Collection;
 issues = theElement.Issues;
 
 var newIssue as EA.Issue;
 newIssue = issues.AddNew( "MyIssue", "Defect" );
 newIssue.Update();
 issues.Refresh();
 
 Session.Output( " Added new Issue: " + newIssue.Name );
 
 newIssue = null;
 
 // List all element issues
 for ( var i = 0 ; i < issues.Count ; i++ )
 {
 var currentIssue as EA.Issue;
 currentIssue = issues.GetAt( i );
 
 Session.Output( " Issue: " + currentIssue.Name );
 
 // Delete the issue that we just added
 if ( currentIssue.Name == "MyIssue" )
 {
 issues.DeleteAt( i, false );
 Session.Output( " Deleted Issue: " + currentIssue.Name );
 }
 }
 
 issues = null; 
 
 Session.Output( "Done!" );
 }
 else
 {
 // No item selected in the tree, or the item selected was not an element
 Session.Prompt( "This script requires an element be selected in the Project Browser.\n" +
 "Please select an element in the Project Browser and try again.", promptOK );
 }
}

ElementExtrasExample();
"/>
</DataRow>
<DataRow>
<Column name="ScriptID" value="24"/>
<Column name="ScriptCategory" value="605A62F7-BCD0-4845-A8D0-7DC45B4D2E3F"/>
<Column name="ScriptName" value="{2E9CF665-0091-41bb-A168-611872361FAD}"/>
<Column name="ScriptAuthor" value="{9BB70D4F-3874-4116-8185-AB0730F25791}"/>
<Column name="Notes" value="<Script Name="JavaScript-Manage Attributes and Methods Example" Type="Internal" Language="JavaScript"/>
"/>
<Column name="Script" value="!INC JavaScriptLib.JavaScript-EAConstants

/*
 * @Status converted and tested
 * Example illustrating how to add and delete Attributes and Methods.
 *
 * NOTE: Requires an element to be selected in the Project Browser
 *
 * Related APIs
 * =================================================================================
 * Element API - http://www.sparxsystems.com/enterprise_architect_user_guide/151/automation_and_scripting/element2.html
 * Attribute API - http://www.sparxsystems.com/enterprise_architect_user_guide/15.1/automation_and_scripting/attribute.html
 * Method API - http://www.sparxsystems.com/enterprise_architect_user_guide/15.1/automation_and_scripting/method.html
 */
function ManageAttributesMethodsExample()
{
 // Show the script output window
 Repository.EnsureOutputVisible( "Script" );

 // Get the currently selected element in the tree to work on
 var theElement as EA.Element;
 theElement = Repository.GetTreeSelectedObject();
 
 if ( theElement != null && theElement.ObjectType == otElement )
 {
 Session.Output( "JavaScript MANAGE ATTRIBUTES/METHODS EXAMPLE" );
 Session.Output( "=======================================" );
 Session.Output( "Working on element '" + theElement.Name + "' (Type=" + theElement.Type +
 ", ID=" + theElement.ElementID + ")" );
 
 // ==================================================
 // MANAGE ATTRIBUTES
 // ==================================================
 // Add an attribute
 var attributes as EA.Collection;
 attributes = theElement.Attributes;
 
 var newAttribute as EA.Attribute;
 newAttribute = attributes.AddNew( "m_newAttribute", "string" );
 newAttribute.Update();
 attributes.Refresh();
 
 Session.Output( "Added attribute: " + newAttribute.Name );
 
 newAttribute = null;
 
 // Search the attribute collection for the added attribute and delete it
 for ( var i = 0 ; i < attributes.Count ; i++ )
 {
 var currentAttribute as EA.Attribute;
 currentAttribute = attributes.GetAt( i );
 
 Session.Output( "Attribute: " + currentAttribute.Name );
 
 // Delete the attribute we just added
 if ( currentAttribute.Name == "m_newAttribute" )
 {
 attributes.DeleteAt( i, false );
 Session.Output( "Deleted Attribute: " + currentAttribute.Name );
 }
 }
 
 attributes = null;
 
 // ==================================================
 // MANAGE METHODS
 // ==================================================
 // Add a method
 var methods as EA.Collection;
 methods = theElement.Methods;
 
 var newMethod as EA.Method;
 newMethod = methods.AddNew( "NewMethod", "int" );
 newMethod.Update();
 methods.Refresh();
 
 Session.Output( "Added method: " + newMethod.Name );
 
 newMethod = null;
 
 // Search the method collection for the added method and delete it
 for ( var i = 0 ; i < methods.Count ; i++ )
 {
 var currentMethod as EA.Method;
 currentMethod = methods.GetAt( i );
 
 Session.Output( "Method: " + currentMethod.Name );
 
 // Delete the method we just added
 if ( currentMethod.Name == "NewMethod" )
 {
 methods.DeleteAt( i, false );
 Session.Output( "Deleted Method: " + currentMethod.Name );
 }
 }
 
 methods = null; 
 
 Session.Output( "Done!" );
 }
 else
 {
 // No item selected in the tree, or the item selected was not an element
 Session.Prompt( "This script requires an element be selected in the Project Browser.\n" +
 "Please select an element in the Project Browser and try again.", promptOK );
 }
}

ManageAttributesMethodsExample();
"/>
</DataRow>
<DataRow>
<Column name="ScriptID" value="25"/>
<Column name="ScriptCategory" value="605A62F7-BCD0-4845-A8D0-7DC45B4D2E3F"/>
<Column name="ScriptName" value="{51A51B10-0BD2-46f7-A4BF-DFC0C3C7EAD3}"/>
<Column name="ScriptAuthor" value="{9BB70D4F-3874-4116-8185-AB0730F25791}"/>
<Column name="Notes" value="<Script Name="JavaScript-Manage Diagrams Example" Type="Internal" Language="JavaScript"/>
"/>
<Column name="Script" value="!INC JavaScriptLib.JavaScript-EAConstants

// @Status tested successfully
// An example of how to create a diagram and add an Element to it.
// 
// Related APIs
// =================================================================================
// Diagram API - http://www.sparxsystems.com/enterprise_architect_user_guide/15.1/automation_and_scripting/diagram2.html
// Diagram Object API - http://www.sparxsystems.com/enterprise_architect_user_guide/15.1/automation_and_scripting/diagramobjects.html
//
function ManageDiagramsExample()
{
 // Show the script output window
 Repository.EnsureOutputVisible( "Script" );

 Session.Output( "JScript MANAGE DIAGRAMS EXAMPLE" );
 Session.Output( "=======================================" );
 
 // Create a new package in the first model node
 var modelNode as EA.Package;
 modelNode = Repository.Models.GetAt( 0 );
 
 var testPackage as EA.Package;
 testPackage = modelNode.Packages.AddNew( "TestPackage", "Class" );
 testPackage.Update();
 
 Session.Output( "Added package '" + testPackage.Name + "' to model" );
 
 // Create a diagram in the test package
 var testDiagram as EA.Diagram;
 testDiagram = testPackage.Diagrams.AddNew( "My Logical Diagram", "Logical" );
 testDiagram.Notes = "Test diagram created by the ManageDiagramsExample script";
 testDiagram.Update();
 
 Session.Output( "Added diagram '" + testDiagram.Name + "' to package " + testPackage.Name );
 
 // Create an element (which will be added to the diagram later on)
 var testElement as EA.Element;
 testElement = testPackage.Elements.AddNew( "TestClass", "Class" );
 testElement.Update();
 
 Session.Output( "Created element '" + testElement.Name + "' in package '" +
 testPackage.Name + "'" );
 
 // Add the element to the diagram
 var diagramObjects as EA.Collection;
 diagramObjects = testDiagram.DiagramObjects;
 
 var testDiagramObject as EA.DiagramObject;
 testDiagramObject = diagramObjects.AddNew( "l=200;r=400;t=200;b=600;", "" );
 testDiagramObject.ElementID = testElement.ElementID ;
 testDiagramObject.Update();
 
 Session.Output( "Added element '" + testElement.Name + "' to diagram '" +
 testDiagram.Name + "'" );

 Session.Output( "Done!" );
}

ManageDiagramsExample();
"/>
</DataRow>
<DataRow>
<Column name="ScriptID" value="38"/>
<Column name="ScriptCategory" value="ScriptDebugging"/>
<Column name="ScriptName" value="ScriptDebugging"/>
<Column name="ScriptAuthor" value="ScriptDebugging"/>
<Column name="Notes" value="<?xml version="1.0"?>
<DATA><Debugger value="Scripting"/></DATA>
"/>
<Column name="Script" value=" "/>
</DataRow>
<DataRow>
<Column name="ScriptID" value="39"/>
<Column name="ScriptCategory" value="ScriptDebugging"/>
<Column name="ScriptName" value="ScriptDebugging"/>
<Column name="ScriptAuthor" value="ScriptDebugging"/>
<Column name="Notes" value="<?xml version="1.0"?>
<DATA><Debugger value="Scripting"/></DATA>
"/>
<Column name="Script" value=" "/>
</DataRow>
<DataRow>
<Column name="ScriptID" value="101"/>
<Column name="ScriptCategory" value="ScriptDebugging"/>
<Column name="ScriptName" value="ScriptDebugging"/>
<Column name="ScriptAuthor" value="ScriptDebugging"/>
<Column name="Notes" value="<?xml version="1.0"?>
<DATA><Debugger value="Scripting"/></DATA>
"/>
<Column name="Script" value=" "/>
</DataRow>
<DataRow>
<Column name="ScriptID" value="102"/>
<Column name="ScriptCategory" value="ScriptDebugging"/>
<Column name="ScriptName" value="ScriptDebugging"/>
<Column name="ScriptAuthor" value="ScriptDebugging"/>
<Column name="Notes" value="<?xml version="1.0"?>
<DATA><Debugger value="Scripting"/></DATA>
"/>
<Column name="Script" value=" "/>
</DataRow>
<DataRow>
<Column name="ScriptID" value="103"/>
<Column name="ScriptCategory" value="ScriptDebugging"/>
<Column name="ScriptName" value="ScriptDebugging"/>
<Column name="ScriptAuthor" value="ScriptDebugging"/>
<Column name="Notes" value="<?xml version="1.0"?>
<DATA><Debugger value="Scripting"/></DATA>
"/>
<Column name="Script" value=" "/>
</DataRow>
<DataRow>
<Column name="ScriptID" value="104"/>
<Column name="ScriptCategory" value="ScriptDebugging"/>
<Column name="ScriptName" value="ScriptDebugging"/>
<Column name="ScriptAuthor" value="ScriptDebugging"/>
<Column name="Notes" value="<?xml version="1.0"?>
<DATA><Debugger value="Scripting"/></DATA>
"/>
<Column name="Script" value=" "/>
</DataRow>
<DataRow>
<Column name="ScriptID" value="105"/>
<Column name="ScriptCategory" value="ScriptDebugging"/>
<Column name="ScriptName" value="ScriptDebugging"/>
<Column name="ScriptAuthor" value="ScriptDebugging"/>
<Column name="Notes" value="<?xml version="1.0"?>
<DATA><Debugger value="Scripting"/></DATA>
"/>
<Column name="Script" value=" "/>
</DataRow>
<DataRow>
<Column name="ScriptID" value="106"/>
<Column name="ScriptCategory" value="ScriptDebugging"/>
<Column name="ScriptName" value="ScriptDebugging"/>
<Column name="ScriptAuthor" value="ScriptDebugging"/>
<Column name="Notes" value="<?xml version="1.0"?>
<DATA><Debugger value="Scripting"/></DATA>
"/>
<Column name="Script" value=" "/>
</DataRow>
<DataRow>
<Column name="ScriptID" value="107"/>
<Column name="ScriptCategory" value="ScriptDebugging"/>
<Column name="ScriptName" value="ScriptDebugging"/>
<Column name="ScriptAuthor" value="ScriptDebugging"/>
<Column name="Notes" value="<?xml version="1.0"?>
<DATA><Debugger value="Scripting"/></DATA>
"/>
<Column name="Script" value=" "/>
</DataRow>
<DataRow>
<Column name="ScriptID" value="108"/>
<Column name="ScriptCategory" value="ScriptDebugging"/>
<Column name="ScriptName" value="ScriptDebugging"/>
<Column name="ScriptAuthor" value="ScriptDebugging"/>
<Column name="Notes" value="<?xml version="1.0"?>
<DATA><Debugger value="Scripting"/></DATA>
"/>
<Column name="Script" value=" "/>
</DataRow>
<DataRow>
<Column name="ScriptID" value="109"/>
<Column name="ScriptCategory" value="ScriptDebugging"/>
<Column name="ScriptName" value="ScriptDebugging"/>
<Column name="ScriptAuthor" value="ScriptDebugging"/>
<Column name="Notes" value="<?xml version="1.0"?>
<DATA><Debugger value="Scripting"/></DATA>
"/>
<Column name="Script" value=" "/>
</DataRow>
<DataRow>
<Column name="ScriptID" value="110"/>
<Column name="ScriptCategory" value="ScriptDebugging"/>
<Column name="ScriptName" value="ScriptDebugging"/>
<Column name="ScriptAuthor" value="ScriptDebugging"/>
<Column name="Notes" value="<?xml version="1.0"?>
<DATA><Debugger value="Scripting"/></DATA>
"/>
<Column name="Script" value=" "/>
</DataRow>
<DataRow>
<Column name="ScriptID" value="111"/>
<Column name="ScriptCategory" value="ScriptDebugging"/>
<Column name="ScriptName" value="ScriptDebugging"/>
<Column name="ScriptAuthor" value="ScriptDebugging"/>
<Column name="Notes" value="<?xml version="1.0"?>
<DATA><Debugger value="Scripting"/></DATA>
"/>
<Column name="Script" value=" "/>
</DataRow>
<DataRow>
<Column name="ScriptID" value="112"/>
<Column name="ScriptCategory" value="ScriptDebugging"/>
<Column name="ScriptName" value="ScriptDebugging"/>
<Column name="ScriptAuthor" value="ScriptDebugging"/>
<Column name="Notes" value="<?xml version="1.0"?>
<DATA><Debugger value="Scripting"/></DATA>
"/>
<Column name="Script" value=" "/>
</DataRow>
<DataRow>
<Column name="ScriptID" value="113"/>
<Column name="ScriptCategory" value="ScriptDebugging"/>
<Column name="ScriptName" value="ScriptDebugging"/>
<Column name="ScriptAuthor" value="ScriptDebugging"/>
<Column name="Notes" value="<?xml version="1.0"?>
<DATA><Debugger value="Scripting"/></DATA>
"/>
<Column name="Script" value=" "/>
</DataRow>
<DataRow>
<Column name="ScriptID" value="114"/>
<Column name="ScriptCategory" value="ScriptDebugging"/>
<Column name="ScriptName" value="ScriptDebugging"/>
<Column name="ScriptAuthor" value="ScriptDebugging"/>
<Column name="Notes" value="<?xml version="1.0"?>
<DATA><Debugger value="Scripting"/></DATA>
"/>
<Column name="Script" value=" "/>
</DataRow>
<DataRow>
<Column name="ScriptID" value="115"/>
<Column name="ScriptCategory" value="ScriptDebugging"/>
<Column name="ScriptName" value="ScriptDebugging"/>
<Column name="ScriptAuthor" value="ScriptDebugging"/>
<Column name="Notes" value="<?xml version="1.0"?>
<DATA><Debugger value="Scripting"/></DATA>
"/>
<Column name="Script" value=" "/>
</DataRow>
<DataRow>
<Column name="ScriptID" value="116"/>
<Column name="ScriptCategory" value="ScriptDebugging"/>
<Column name="ScriptName" value="ScriptDebugging"/>
<Column name="ScriptAuthor" value="ScriptDebugging"/>
<Column name="Notes" value="<?xml version="1.0"?>
<DATA><Debugger value="Scripting"/></DATA>
"/>
<Column name="Script" value=" "/>
</DataRow>
<DataRow>
<Column name="ScriptID" value="117"/>
<Column name="ScriptCategory" value="ScriptDebugging"/>
<Column name="ScriptName" value="ScriptDebugging"/>
<Column name="ScriptAuthor" value="ScriptDebugging"/>
<Column name="Notes" value="<?xml version="1.0"?>
<DATA><Debugger value="Scripting"/></DATA>
"/>
<Column name="Script" value=" "/>
</DataRow>
<DataRow>
<Column name="ScriptID" value="118"/>
<Column name="ScriptCategory" value="ScriptDebugging"/>
<Column name="ScriptName" value="ScriptDebugging"/>
<Column name="ScriptAuthor" value="ScriptDebugging"/>
<Column name="Notes" value="<?xml version="1.0"?>
<DATA><Debugger value="Scripting"/></DATA>
"/>
<Column name="Script" value=" "/>
</DataRow>
<DataRow>
<Column name="ScriptID" value="119"/>
<Column name="ScriptCategory" value="ScriptDebugging"/>
<Column name="ScriptName" value="ScriptDebugging"/>
<Column name="ScriptAuthor" value="ScriptDebugging"/>
<Column name="Notes" value="<?xml version="1.0"?>
<DATA><Debugger value="Scripting"/></DATA>
"/>
<Column name="Script" value=" "/>
</DataRow>
<DataRow>
<Column name="ScriptID" value="120"/>
<Column name="ScriptCategory" value="ScriptDebugging"/>
<Column name="ScriptName" value="ScriptDebugging"/>
<Column name="ScriptAuthor" value="ScriptDebugging"/>
<Column name="Notes" value="<?xml version="1.0"?>
<DATA><Debugger value="Scripting"/></DATA>
"/>
<Column name="Script" value=" "/>
</DataRow>
<DataRow>
<Column name="ScriptID" value="121"/>
<Column name="ScriptCategory" value="ScriptDebugging"/>
<Column name="ScriptName" value="ScriptDebugging"/>
<Column name="ScriptAuthor" value="ScriptDebugging"/>
<Column name="Notes" value="<?xml version="1.0"?>
<DATA><Debugger value="Scripting"/></DATA>
"/>
<Column name="Script" value=" "/>
</DataRow>
<DataRow>
<Column name="ScriptID" value="122"/>
<Column name="ScriptCategory" value="ScriptDebugging"/>
<Column name="ScriptName" value="ScriptDebugging"/>
<Column name="ScriptAuthor" value="ScriptDebugging"/>
<Column name="Notes" value="<?xml version="1.0"?>
<DATA><Debugger value="Scripting"/></DATA>
"/>
<Column name="Script" value=" "/>
</DataRow>
<DataRow>
<Column name="ScriptID" value="123"/>
<Column name="ScriptCategory" value="ScriptDebugging"/>
<Column name="ScriptName" value="ScriptDebugging"/>
<Column name="ScriptAuthor" value="ScriptDebugging"/>
<Column name="Notes" value="<?xml version="1.0"?>
<DATA><Debugger value="Scripting"/></DATA>
"/>
<Column name="Script" value=" "/>
</DataRow>
<DataRow>
<Column name="ScriptID" value="124"/>
<Column name="ScriptCategory" value="ScriptDebugging"/>
<Column name="ScriptName" value="ScriptDebugging"/>
<Column name="ScriptAuthor" value="ScriptDebugging"/>
<Column name="Notes" value="<?xml version="1.0"?>
<DATA><Debugger value="Scripting"/></DATA>
"/>
<Column name="Script" value=" "/>
</DataRow>
<DataRow>
<Column name="ScriptID" value="125"/>
<Column name="ScriptCategory" value="ScriptDebugging"/>
<Column name="ScriptName" value="ScriptDebugging"/>
<Column name="ScriptAuthor" value="ScriptDebugging"/>
<Column name="Notes" value="<?xml version="1.0"?>
<DATA><Debugger value="Scripting"/></DATA>
"/>
<Column name="Script" value=" "/>
</DataRow>
<DataRow>
<Column name="ScriptID" value="126"/>
<Column name="ScriptCategory" value="ScriptDebugging"/>
<Column name="ScriptName" value="ScriptDebugging"/>
<Column name="ScriptAuthor" value="ScriptDebugging"/>
<Column name="Notes" value="<?xml version="1.0"?>
<DATA><Debugger value="Scripting"/></DATA>
"/>
<Column name="Script" value=" "/>
</DataRow>
<DataRow>
<Column name="ScriptID" value="127"/>
<Column name="ScriptCategory" value="ScriptDebugging"/>
<Column name="ScriptName" value="ScriptDebugging"/>
<Column name="ScriptAuthor" value="ScriptDebugging"/>
<Column name="Notes" value="<?xml version="1.0"?>
<DATA><Debugger value="Scripting"/></DATA>
"/>
<Column name="Script" value=" "/>
</DataRow>
<DataRow>
<Column name="ScriptID" value="128"/>
<Column name="ScriptCategory" value="ScriptDebugging"/>
<Column name="ScriptName" value="ScriptDebugging"/>
<Column name="ScriptAuthor" value="ScriptDebugging"/>
<Column name="Notes" value="<?xml version="1.0"?>
<DATA><Debugger value="Scripting"/></DATA>
"/>
<Column name="Script" value=" "/>
</DataRow>
<DataRow>
<Column name="ScriptID" value="129"/>
<Column name="ScriptCategory" value="ScriptDebugging"/>
<Column name="ScriptName" value="ScriptDebugging"/>
<Column name="ScriptAuthor" value="ScriptDebugging"/>
<Column name="Notes" value="<?xml version="1.0"?>
<DATA><Debugger value="Scripting"/></DATA>
"/>
<Column name="Script" value=" "/>
</DataRow>
<DataRow>
<Column name="ScriptID" value="130"/>
<Column name="ScriptCategory" value="ScriptDebugging"/>
<Column name="ScriptName" value="ScriptDebugging"/>
<Column name="ScriptAuthor" value="ScriptDebugging"/>
<Column name="Notes" value="<?xml version="1.0"?>
<DATA><Debugger value="Scripting"/></DATA>
"/>
<Column name="Script" value=" "/>
</DataRow>
<DataRow>
<Column name="ScriptID" value="131"/>
<Column name="ScriptCategory" value="ScriptDebugging"/>
<Column name="ScriptName" value="ScriptDebugging"/>
<Column name="ScriptAuthor" value="ScriptDebugging"/>
<Column name="Notes" value="<?xml version="1.0"?>
<DATA><Debugger value="Scripting"/></DATA>
"/>
<Column name="Script" value=" "/>
</DataRow>
<DataRow>
<Column name="ScriptID" value="132"/>
<Column name="ScriptCategory" value="ScriptDebugging"/>
<Column name="ScriptName" value="ScriptDebugging"/>
<Column name="ScriptAuthor" value="ScriptDebugging"/>
<Column name="Notes" value="<?xml version="1.0"?>
<DATA><Debugger value="Scripting"/></DATA>
"/>
<Column name="Script" value=" "/>
</DataRow>
<DataRow>
<Column name="ScriptID" value="133"/>
<Column name="ScriptCategory" value="ScriptDebugging"/>
<Column name="ScriptName" value="ScriptDebugging"/>
<Column name="ScriptAuthor" value="ScriptDebugging"/>
<Column name="Notes" value="<?xml version="1.0"?>
<DATA><Debugger value="Scripting"/></DATA>
"/>
<Column name="Script" value=" "/>
</DataRow>
<DataRow>
<Column name="ScriptID" value="134"/>
<Column name="ScriptCategory" value="ScriptDebugging"/>
<Column name="ScriptName" value="ScriptDebugging"/>
<Column name="ScriptAuthor" value="ScriptDebugging"/>
<Column name="Notes" value="<?xml version="1.0"?>
<DATA><Debugger value="Scripting"/></DATA>
"/>
<Column name="Script" value=" "/>
</DataRow>
<DataRow>
<Column name="ScriptID" value="135"/>
<Column name="ScriptCategory" value="ScriptDebugging"/>
<Column name="ScriptName" value="ScriptDebugging"/>
<Column name="ScriptAuthor" value="ScriptDebugging"/>
<Column name="Notes" value="<?xml version="1.0"?>
<DATA><Debugger value="Scripting"/></DATA>
"/>
<Column name="Script" value=" "/>
</DataRow>
<DataRow>
<Column name="ScriptID" value="136"/>
<Column name="ScriptCategory" value="ScriptDebugging"/>
<Column name="ScriptName" value="ScriptDebugging"/>
<Column name="ScriptAuthor" value="ScriptDebugging"/>
<Column name="Notes" value="<?xml version="1.0"?>
<DATA><Debugger value="Scripting"/></DATA>
"/>
<Column name="Script" value=" "/>
</DataRow>
<DataRow>
<Column name="ScriptID" value="137"/>
<Column name="ScriptCategory" value="ScriptDebugging"/>
<Column name="ScriptName" value="ScriptDebugging"/>
<Column name="ScriptAuthor" value="ScriptDebugging"/>
<Column name="Notes" value="<?xml version="1.0"?>
<DATA><Debugger value="Scripting"/></DATA>
"/>
<Column name="Script" value=" "/>
</DataRow>
<DataRow>
<Column name="ScriptID" value="138"/>
<Column name="ScriptCategory" value="ScriptDebugging"/>
<Column name="ScriptName" value="ScriptDebugging"/>
<Column name="ScriptAuthor" value="ScriptDebugging"/>
<Column name="Notes" value="<?xml version="1.0"?>
<DATA><Debugger value="Scripting"/></DATA>
"/>
<Column name="Script" value=" "/>
</DataRow>
<DataRow>
<Column name="ScriptID" value="139"/>
<Column name="ScriptCategory" value="ScriptDebugging"/>
<Column name="ScriptName" value="ScriptDebugging"/>
<Column name="ScriptAuthor" value="ScriptDebugging"/>
<Column name="Notes" value="<?xml version="1.0"?>
<DATA><Debugger value="Scripting"/></DATA>
"/>
<Column name="Script" value=" "/>
</DataRow>
<DataRow>
<Column name="ScriptID" value="140"/>
<Column name="ScriptCategory" value="ScriptDebugging"/>
<Column name="ScriptName" value="ScriptDebugging"/>
<Column name="ScriptAuthor" value="ScriptDebugging"/>
<Column name="Notes" value="<?xml version="1.0"?>
<DATA><Debugger value="Scripting"/></DATA>
"/>
<Column name="Script" value=" "/>
</DataRow>
<DataRow>
<Column name="ScriptID" value="61"/>
<Column name="ScriptCategory" value="605A62F7-BCD0-4845-A8D0-7DC45B4D2E3F"/>
<Column name="ScriptName" value="{D2230A11-8EED-48aa-AA15-9568187435DA}"/>
<Column name="ScriptAuthor" value="{6F2AAA79-A828-415b-8FCF-6C374FC7F45B}"/>
<Column name="Notes" value="<Script Name="JavaScript-Enumerator" Type="Internal" Language="JavaScript"/>"/>
<Column name="Script" value="!INC JavaScriptLib.JavaScript-EAConstants
/*
Set of Enumerator functions to support iterating through collections
*/
function moveNext()
 {
 if(this.iElem > -1)
 {
 this.iElem++;
 if(this.iElem < this.Package.Count)
 {
 return true;
 }
 this.iElem = this.Package.Count;
 }
 return false;
 }
 
function item()
 {
 if( this.iElem > -1 && this.iElem < this.Package.Count)
 {
 return this.Package.GetAt(this.iElem);
 }
 return null;
 }

function atEnd()
 {
 if((this.iElem > -1) && (this.iElem < this.Package.Count))
 {
 return false;
 }
 // Session.Output("at end!");
 return true;
 }

function Check( obj)
 {
 if(obj == undefined)
 {
 Session.Output("Undefined object");
 return false;
 }
 return true;
 } 

function Enumerator( object )
{
 this.iElem = 0;
 this.Package = object;
 this.atEnd = atEnd;
 this.moveNext = moveNext;
 this.item = item;
 this.Check = Check;
 if(!Check(object))
 {
 this.iElem = -1;
 }
}"/>
</DataRow>
<DataRow>
<Column name="ScriptID" value="64"/>
<Column name="ScriptCategory" value="ScriptDebugging"/>
<Column name="ScriptName" value="ScriptDebugging"/>
<Column name="ScriptAuthor" value="ScriptDebugging"/>
<Column name="Notes" value="<?xml version="1.0"?>
<DATA><Debugger value="Scripting"/></DATA>
"/>
<Column name="Script" value=" "/>
</DataRow>
<DataRow>
<Column name="ScriptID" value="65"/>
<Column name="ScriptCategory" value="ScriptDebugging"/>
<Column name="ScriptName" value="ScriptDebugging"/>
<Column name="ScriptAuthor" value="ScriptDebugging"/>
<Column name="Notes" value="<?xml version="1.0"?>
<DATA><Debugger value="Scripting"/></DATA>
"/>
<Column name="Script" value=" "/>
</DataRow>
<DataRow>
<Column name="ScriptID" value="66"/>
<Column name="ScriptCategory" value="ScriptDebugging"/>
<Column name="ScriptName" value="ScriptDebugging"/>
<Column name="ScriptAuthor" value="ScriptDebugging"/>
<Column name="Notes" value="<?xml version="1.0"?>
<DATA><Debugger value="Scripting"/></DATA>
"/>
<Column name="Script" value=" "/>
</DataRow>
<DataRow>
<Column name="ScriptID" value="67"/>
<Column name="ScriptCategory" value="ScriptDebugging"/>
<Column name="ScriptName" value="ScriptDebugging"/>
<Column name="ScriptAuthor" value="ScriptDebugging"/>
<Column name="Notes" value="<?xml version="1.0"?>
<DATA><Debugger value="Scripting"/></DATA>
"/>
<Column name="Script" value=" "/>
</DataRow>
<DataRow>
<Column name="ScriptID" value="68"/>
<Column name="ScriptCategory" value="ScriptDebugging"/>
<Column name="ScriptName" value="ScriptDebugging"/>
<Column name="ScriptAuthor" value="ScriptDebugging"/>
<Column name="Notes" value="<?xml version="1.0"?>
<DATA><Debugger value="Scripting"/></DATA>
"/>
<Column name="Script" value=" "/>
</DataRow>
<DataRow>
<Column name="ScriptID" value="69"/>
<Column name="ScriptCategory" value="ScriptDebugging"/>
<Column name="ScriptName" value="ScriptDebugging"/>
<Column name="ScriptAuthor" value="ScriptDebugging"/>
<Column name="Notes" value="<?xml version="1.0"?>
<DATA><Debugger value="Scripting"/></DATA>
"/>
<Column name="Script" value=" "/>
</DataRow>
<DataRow>
<Column name="ScriptID" value="70"/>
<Column name="ScriptCategory" value="ScriptDebugging"/>
<Column name="ScriptName" value="ScriptDebugging"/>
<Column name="ScriptAuthor" value="ScriptDebugging"/>
<Column name="Notes" value="<?xml version="1.0"?>
<DATA><Debugger value="Scripting"/></DATA>
"/>
<Column name="Script" value=" "/>
</DataRow>
<DataRow>
<Column name="ScriptID" value="71"/>
<Column name="ScriptCategory" value="ScriptDebugging"/>
<Column name="ScriptName" value="ScriptDebugging"/>
<Column name="ScriptAuthor" value="ScriptDebugging"/>
<Column name="Notes" value="<?xml version="1.0"?>
<DATA><Debugger value="Scripting"/></DATA>
"/>
<Column name="Script" value=" "/>
</DataRow>
<DataRow>
<Column name="ScriptID" value="72"/>
<Column name="ScriptCategory" value="ScriptDebugging"/>
<Column name="ScriptName" value="ScriptDebugging"/>
<Column name="ScriptAuthor" value="ScriptDebugging"/>
<Column name="Notes" value="<?xml version="1.0"?>
<DATA><Debugger value="Scripting"/></DATA>
"/>
<Column name="Script" value=" "/>
</DataRow>
<DataRow>
<Column name="ScriptID" value="73"/>
<Column name="ScriptCategory" value="ScriptDebugging"/>
<Column name="ScriptName" value="ScriptDebugging"/>
<Column name="ScriptAuthor" value="ScriptDebugging"/>
<Column name="Notes" value="<?xml version="1.0"?>
<DATA><Debugger value="Scripting"/></DATA>
"/>
<Column name="Script" value=" "/>
</DataRow>
<DataRow>
<Column name="ScriptID" value="74"/>
<Column name="ScriptCategory" value="ScriptDebugging"/>
<Column name="ScriptName" value="ScriptDebugging"/>
<Column name="ScriptAuthor" value="ScriptDebugging"/>
<Column name="Notes" value="<?xml version="1.0"?>
<DATA><Debugger value="Scripting"/></DATA>
"/>
<Column name="Script" value=" "/>
</DataRow>
<DataRow>
<Column name="ScriptID" value="75"/>
<Column name="ScriptCategory" value="ScriptDebugging"/>
<Column name="ScriptName" value="ScriptDebugging"/>
<Column name="ScriptAuthor" value="ScriptDebugging"/>
<Column name="Notes" value="<?xml version="1.0"?>
<DATA><Debugger value="Scripting"/></DATA>
"/>
<Column name="Script" value=" "/>
</DataRow>
<DataRow>
<Column name="ScriptID" value="76"/>
<Column name="ScriptCategory" value="ScriptDebugging"/>
<Column name="ScriptName" value="ScriptDebugging"/>
<Column name="ScriptAuthor" value="ScriptDebugging"/>
<Column name="Notes" value="<?xml version="1.0"?>
<DATA><Debugger value="Scripting"/></DATA>
"/>
<Column name="Script" value=" "/>
</DataRow>
<DataRow>
<Column name="ScriptID" value="77"/>
<Column name="ScriptCategory" value="ScriptDebugging"/>
<Column name="ScriptName" value="ScriptDebugging"/>
<Column name="ScriptAuthor" value="ScriptDebugging"/>
<Column name="Notes" value="<?xml version="1.0"?>
<DATA><Debugger value="Scripting"/></DATA>
"/>
<Column name="Script" value=" "/>
</DataRow>
<DataRow>
<Column name="ScriptID" value="78"/>
<Column name="ScriptCategory" value="ScriptDebugging"/>
<Column name="ScriptName" value="ScriptDebugging"/>
<Column name="ScriptAuthor" value="ScriptDebugging"/>
<Column name="Notes" value="<?xml version="1.0"?>
<DATA><Debugger value="Scripting"/></DATA>
"/>
<Column name="Script" value=" "/>
</DataRow>
<DataRow>
<Column name="ScriptID" value="79"/>
<Column name="ScriptCategory" value="ScriptDebugging"/>
<Column name="ScriptName" value="ScriptDebugging"/>
<Column name="ScriptAuthor" value="ScriptDebugging"/>
<Column name="Notes" value="<?xml version="1.0"?>
<DATA><Debugger value="Scripting"/></DATA>
"/>
<Column name="Script" value=" "/>
</DataRow>
<DataRow>
<Column name="ScriptID" value="80"/>
<Column name="ScriptCategory" value="ScriptDebugging"/>
<Column name="ScriptName" value="ScriptDebugging"/>
<Column name="ScriptAuthor" value="ScriptDebugging"/>
<Column name="Notes" value="<?xml version="1.0"?>
<DATA><Debugger value="Scripting"/></DATA>
"/>
<Column name="Script" value=" "/>
</DataRow>
<DataRow>
<Column name="ScriptID" value="81"/>
<Column name="ScriptCategory" value="ScriptDebugging"/>
<Column name="ScriptName" value="ScriptDebugging"/>
<Column name="ScriptAuthor" value="ScriptDebugging"/>
<Column name="Notes" value="<?xml version="1.0"?>
<DATA><Debugger value="Scripting"/></DATA>
"/>
<Column name="Script" value=" "/>
</DataRow>
<DataRow>
<Column name="ScriptID" value="82"/>
<Column name="ScriptCategory" value="ScriptDebugging"/>
<Column name="ScriptName" value="ScriptDebugging"/>
<Column name="ScriptAuthor" value="ScriptDebugging"/>
<Column name="Notes" value="<?xml version="1.0"?>
<DATA><Debugger value="Scripting"/></DATA>
"/>
<Column name="Script" value=" "/>
</DataRow>
<DataRow>
<Column name="ScriptID" value="83"/>
<Column name="ScriptCategory" value="ScriptDebugging"/>
<Column name="ScriptName" value="ScriptDebugging"/>
<Column name="ScriptAuthor" value="ScriptDebugging"/>
<Column name="Notes" value="<?xml version="1.0"?>
<DATA><Debugger value="Scripting"/></DATA>
"/>
<Column name="Script" value=" "/>
</DataRow>
<DataRow>
<Column name="ScriptID" value="84"/>
<Column name="ScriptCategory" value="ScriptDebugging"/>
<Column name="ScriptName" value="ScriptDebugging"/>
<Column name="ScriptAuthor" value="ScriptDebugging"/>
<Column name="Notes" value="<?xml version="1.0"?>
<DATA><Debugger value="Scripting"/></DATA>
"/>
<Column name="Script" value=" "/>
</DataRow>
<DataRow>
<Column name="ScriptID" value="85"/>
<Column name="ScriptCategory" value="ScriptDebugging"/>
<Column name="ScriptName" value="ScriptDebugging"/>
<Column name="ScriptAuthor" value="ScriptDebugging"/>
<Column name="Notes" value="<?xml version="1.0"?>
<DATA><Debugger value="Scripting"/></DATA>
"/>
<Column name="Script" value=" "/>
</DataRow>
<DataRow>
<Column name="ScriptID" value="86"/>
<Column name="ScriptCategory" value="ScriptDebugging"/>
<Column name="ScriptName" value="ScriptDebugging"/>
<Column name="ScriptAuthor" value="ScriptDebugging"/>
<Column name="Notes" value="<?xml version="1.0"?>
<DATA><Debugger value="Scripting"/></DATA>
"/>
<Column name="Script" value=" "/>
</DataRow>
<DataRow>
<Column name="ScriptID" value="87"/>
<Column name="ScriptCategory" value="ScriptDebugging"/>
<Column name="ScriptName" value="ScriptDebugging"/>
<Column name="ScriptAuthor" value="ScriptDebugging"/>
<Column name="Notes" value="<?xml version="1.0"?>
<DATA><Debugger value="Scripting"/></DATA>
"/>
<Column name="Script" value=" "/>
</DataRow>
<DataRow>
<Column name="ScriptID" value="88"/>
<Column name="ScriptCategory" value="ScriptDebugging"/>
<Column name="ScriptName" value="ScriptDebugging"/>
<Column name="ScriptAuthor" value="ScriptDebugging"/>
<Column name="Notes" value="<?xml version="1.0"?>
<DATA><Debugger value="Scripting"/></DATA>
"/>
<Column name="Script" value=" "/>
</DataRow>
<DataRow>
<Column name="ScriptID" value="89"/>
<Column name="ScriptCategory" value="ScriptDebugging"/>
<Column name="ScriptName" value="ScriptDebugging"/>
<Column name="ScriptAuthor" value="ScriptDebugging"/>
<Column name="Notes" value="<?xml version="1.0"?>
<DATA><Debugger value="Scripting"/></DATA>
"/>
<Column name="Script" value=" "/>
</DataRow>
<DataRow>
<Column name="ScriptID" value="90"/>
<Column name="ScriptCategory" value="ScriptDebugging"/>
<Column name="ScriptName" value="ScriptDebugging"/>
<Column name="ScriptAuthor" value="ScriptDebugging"/>
<Column name="Notes" value="<?xml version="1.0"?>
<DATA><Debugger value="Scripting"/></DATA>
"/>
<Column name="Script" value=" "/>
</DataRow>
<DataRow>
<Column name="ScriptID" value="91"/>
<Column name="ScriptCategory" value="ScriptDebugging"/>
<Column name="ScriptName" value="ScriptDebugging"/>
<Column name="ScriptAuthor" value="ScriptDebugging"/>
<Column name="Notes" value="<?xml version="1.0"?>
<DATA><Debugger value="Scripting"/></DATA>
"/>
<Column name="Script" value=" "/>
</DataRow>
<DataRow>
<Column name="ScriptID" value="92"/>
<Column name="ScriptCategory" value="ScriptDebugging"/>
<Column name="ScriptName" value="ScriptDebugging"/>
<Column name="ScriptAuthor" value="ScriptDebugging"/>
<Column name="Notes" value="<?xml version="1.0"?>
<DATA><Debugger value="Scripting"/></DATA>
"/>
<Column name="Script" value=" "/>
</DataRow>
<DataRow>
<Column name="ScriptID" value="93"/>
<Column name="ScriptCategory" value="ScriptDebugging"/>
<Column name="ScriptName" value="ScriptDebugging"/>
<Column name="ScriptAuthor" value="ScriptDebugging"/>
<Column name="Notes" value="<?xml version="1.0"?>
<DATA><Debugger value="Scripting"/></DATA>
"/>
<Column name="Script" value=" "/>
</DataRow>
<DataRow>
<Column name="ScriptID" value="94"/>
<Column name="ScriptCategory" value="ScriptDebugging"/>
<Column name="ScriptName" value="ScriptDebugging"/>
<Column name="ScriptAuthor" value="ScriptDebugging"/>
<Column name="Notes" value="<?xml version="1.0"?>
<DATA><Debugger value="Scripting"/></DATA>
"/>
<Column name="Script" value=" "/>
</DataRow>
<DataRow>
<Column name="ScriptID" value="95"/>
<Column name="ScriptCategory" value="ScriptDebugging"/>
<Column name="ScriptName" value="ScriptDebugging"/>
<Column name="ScriptAuthor" value="ScriptDebugging"/>
<Column name="Notes" value="<?xml version="1.0"?>
<DATA><Debugger value="Scripting"/></DATA>
"/>
<Column name="Script" value=" "/>
</DataRow>
<DataRow>
<Column name="ScriptID" value="96"/>
<Column name="ScriptCategory" value="ScriptDebugging"/>
<Column name="ScriptName" value="ScriptDebugging"/>
<Column name="ScriptAuthor" value="ScriptDebugging"/>
<Column name="Notes" value="<?xml version="1.0"?>
<DATA><Debugger value="Scripting"/></DATA>
"/>
<Column name="Script" value=" "/>
</DataRow>
<DataRow>
<Column name="ScriptID" value="97"/>
<Column name="ScriptCategory" value="ScriptDebugging"/>
<Column name="ScriptName" value="ScriptDebugging"/>
<Column name="ScriptAuthor" value="ScriptDebugging"/>
<Column name="Notes" value="<?xml version="1.0"?>
<DATA><Debugger value="Scripting"/></DATA>
"/>
<Column name="Script" value=" "/>
</DataRow>
<DataRow>
<Column name="ScriptID" value="98"/>
<Column name="ScriptCategory" value="ScriptDebugging"/>
<Column name="ScriptName" value="ScriptDebugging"/>
<Column name="ScriptAuthor" value="ScriptDebugging"/>
<Column name="Notes" value="<?xml version="1.0"?>
<DATA><Debugger value="Scripting"/></DATA>
"/>
<Column name="Script" value=" "/>
</DataRow>
<DataRow>
<Column name="ScriptID" value="99"/>
<Column name="ScriptCategory" value="ScriptDebugging"/>
<Column name="ScriptName" value="ScriptDebugging"/>
<Column name="ScriptAuthor" value="ScriptDebugging"/>
<Column name="Notes" value="<?xml version="1.0"?>
<DATA><Debugger value="Scripting"/></DATA>
"/>
<Column name="Script" value=" "/>
</DataRow>
<DataRow>
<Column name="ScriptID" value="100"/>
<Column name="ScriptCategory" value="ScriptDebugging"/>
<Column name="ScriptName" value="ScriptDebugging"/>
<Column name="ScriptAuthor" value="ScriptDebugging"/>
<Column name="Notes" value="<?xml version="1.0"?>
<DATA><Debugger value="Scripting"/></DATA>
"/>
<Column name="Script" value=" "/>
</DataRow>
<DataRow>
<Column name="ScriptID" value="141"/>
<Column name="ScriptCategory" value="ScriptDebugging"/>
<Column name="ScriptName" value="ScriptDebugging"/>
<Column name="ScriptAuthor" value="ScriptDebugging"/>
<Column name="Notes" value="<?xml version="1.0"?>
<DATA><Debugger value="Scripting"/></DATA>
"/>
<Column name="Script" value=" "/>
</DataRow>
<DataRow>
<Column name="ScriptID" value="142"/>
<Column name="ScriptCategory" value="ScriptDebugging"/>
<Column name="ScriptName" value="ScriptDebugging"/>
<Column name="ScriptAuthor" value="ScriptDebugging"/>
<Column name="Notes" value="<?xml version="1.0"?>
<DATA><Debugger value="Scripting"/></DATA>
"/>
<Column name="Script" value=" "/>
</DataRow>
<DataRow>
<Column name="ScriptID" value="27"/>
<Column name="ScriptCategory" value="605A62F7-BCD0-4845-A8D0-7DC45B4D2E3F"/>
<Column name="ScriptName" value="{8099D254-0BBD-412f-93EB-9A8E43272F7B}"/>
<Column name="ScriptAuthor" value="{9BB70D4F-3874-4116-8185-AB0730F25791}"/>
<Column name="Notes" value="<Script Name="JavaScript-Manage Elements Example" Type="Internal" Language="JavaScript"/>
"/>
<Column name="Script" value="!INC JavaScriptLib.JavaScript-EAConstants
// @Status tested successfully
// Example illustrating how to add and delete Elements in a Package. 
// 
// NOTE: Requires a package to be selected in the Project Browser
// 
// Related APIs
// =================================================================================
// Element API - http://www.sparxsystems.com/enterprise_architect_user_guide/15.1/automation_and_scripting/element2.html
//
function ManageElementsExample()
{
 // Show the script output window
 Repository.EnsureOutputVisible( "Script" );

 // Get the currently selected package in the tree to work on
 var thePackage as EA.Package;
 thePackage = Repository.GetTreeSelectedPackage();
 
 if ( thePackage != null && thePackage.ParentID != 0 )
 {
 var testElementID = 0;
 
 Session.Output( "JavaScript MANAGE ELEMENTS EXAMPLE" );
 Session.Output( "=======================================" );
 Session.Output( "Working on package '" + thePackage.Name + "' (ID=" +
 thePackage.PackageID + ")" );
 
 var elements as EA.Collection;
 elements = thePackage.Elements;
 
 // Create a new element in the package
 var testElement as EA.Element;
 testElement = elements.AddNew( "Login to Website", "UseCase" );
 testElement.Stereotype = "testcase";
 testElement.Update();
 thePackage.Elements.Refresh();
 
 testElementID = testElement.ElementID;
 Session.Output( "Added Element: " + testElement.Name + " (ID=" + testElementID + ")" );
 
 testElement = null;
 
 // Navigate the elements collection. Delete the newly added element when we find it
 for ( var i = 0 ; i < elements.Count ; i++ )
 {
 var currentElement as EA.Element;
 currentElement = elements.GetAt( i );
 
 Session.Output( "Element: " + currentElement.Name );
 
 // If the element is the one we just added, then delete it
 if ( currentElement.ElementID == testElementID )
 {
 elements.DeleteAt( i, false );
 Session.Output( "Deleted Element: " + currentElement.Name );
 }
 }
 
 Session.Output( "Done!" );
 }
 else
 {
 Session.Prompt( "This script requires a package to be selected in the Project Browser.\n" +
 "Please select a package in the Project Browser and try again.", promptOK );
 }
}

ManageElementsExample();
"/>
</DataRow>
<DataRow>
<Column name="ScriptID" value="28"/>
<Column name="ScriptCategory" value="605A62F7-BCD0-4845-A8D0-7DC45B4D2E3F"/>
<Column name="ScriptName" value="{C5BBF178-5CB1-482c-B9ED-B68878163724}"/>
<Column name="ScriptAuthor" value="{9BB70D4F-3874-4116-8185-AB0730F25791}"/>
<Column name="Notes" value="<Script Name="JavaScript-Manage Packages Example" Type="Internal" Language="JavaScript"/>
"/>
<Column name="Script" value="!INC JavaScriptLib.JavaScript-EAConstants

// @Status tested successfully
// Example illustrating how to add a Model or a Package.
// 
// Related APIs
// =================================================================================
// Package API - http://www.sparxsystems.com/enterprise_architect_user_guide/15.1/automation_and_scripting/package_2.html
// Element API - http://www.sparxsystems.com/enterprise_architect_user_guide/15.1/automation_and_scripting/element2.html
// Repository API - http://www.sparxsystems.com/enterprise_architect_user_guide/15.1/automation_and_scripting/repository3.html
//
function ManagePackagesExample()
{
 // Show the script output window
 Repository.EnsureOutputVisible( "Script" );

 var newModelID = 0;
 
 Session.Output( "JavaScript MANAGE PACKAGES EXAMPLE" );
 Session.Output( "=======================================" );
 
 // Create a new model node
 var newModel as EA.Package;
 newModel = Repository.Models.AddNew( "AdvancedModel", "" );
 newModel.Update();
 Repository.Models.Refresh();
 
 newModelID = newModel.PackageID;
 Session.Output( "Added new model: " + newModel.Name +
 " (PackageID=" + newModelID + ")" );
 
 // ==================================================
 // ADD A SUBPACKAGE TO THE MODEL
 // ==================================================
 var packages as EA.Collection;
 packages = newModel.Packages;
 
 var subPackage as EA.Package;
 subPackage = packages.AddNew( "SubPackage", "Class" );
 subPackage.Update();
 
 // GetElement returns the underlying element representation of the package
 // The initial Update() of the package must be called before we can access the
 // underlying element.
 var packageMetaElement as EA.Element;
 packageMetaElement = subPackage.Element;
 
 // Set the package's stereotype
 packageMetaElement.Stereotype = "system";
 subPackage.Update();
 
 packages.Refresh();
 
 Session.Output( "Added subpackage '" + subPackage.Name +
 "' under model '" + newModel.Name + "'" );
 
 packageMetaElement = null;
 subPackage = null;
 newModel = null;
 
 // List all models in the collection, deleting the one we added
 for ( var i = 0 ; i < Repository.Models.Count ; i++ )
 {
 var currentModel as EA.Package;
 currentModel = Repository.Models.GetAt( i );
 Session.Output( "Model: " + currentModel.Name );
 
 // If the model is the one we just added, then delete it
 if ( currentModel.PackageID == newModelID )
 {
 Repository.Models.DeleteAt( i, false );
 Session.Output( "Deleted model " + currentModel.Name +
 " (PackageID=" + currentModel.PackageID + ")" );
 }
 }
 
 Session.Output( "Done!" );
}

ManagePackagesExample();
"/>
</DataRow>
<DataRow>
<Column name="ScriptID" value="29"/>
<Column name="ScriptCategory" value="605A62F7-BCD0-4845-A8D0-7DC45B4D2E3F"/>
<Column name="ScriptName" value="{A918AF3D-09E2-49b0-A65B-0564365638B8}"/>
<Column name="ScriptAuthor" value="{9BB70D4F-3874-4116-8185-AB0730F25791}"/>
<Column name="Notes" value="<Script Name="JavaScript-Manage Stereotypes Example" Type="Internal" Language="JavaScript"/>
"/>
<Column name="Script" value="!INC JavaScriptLib.JavaScript-EAConstants

// @Status tested successfully
// Example illustrating how to add and delete Stereotypes.
// 
// Related APIs
// =================================================================================
// Stereotype API - http://www.sparxsystems.com/enterprise_architect_user_guide/15.1/automation_and_scripting/stereotype.html
// Repository API - http://www.sparxsystems.com/enterprise_architect_user_guide/15.1/automation_and_scripting/repository3.html
//
function ManageStereotypesExample()
{
 // Show the script output window
 Repository.EnsureOutputVisible( "Script" );

 Session.Output( "JavaScript MANAGE STEREOTYPES EXAMPLE" );
 Session.Output( "=======================================" );
 
 // Create a new stereotype in the repository
 var stereotypes as EA.Collection;
 stereotypes = Repository.Stereotypes;
 
 var testStereo as EA.Stereotype;
 testStereo = stereotypes.AddNew( "TestStereotype", "Class" );
 testStereo.Update();
 stereotypes.Refresh();
 
 Session.Output( "Added Stereotype: " + testStereo.Name );
 
 // Navigate the stereotype collection. Delete the newly added stereotype
 // when we find it
 for ( var i = 0 ; i < stereotypes.Count ; i++ )
 {
 var currentStereo as EA.Stereotype;
 currentStereo = stereotypes.GetAt( i );
 
 Session.Output( "Stereotype: " + currentStereo.Name );
 
 // If the stereotype is the one we just added, then delete it
 if ( currentStereo.Name == "TestStereotype" )
 {
 stereotypes.DeleteAt( i , false );
 Session.Output( "Deleted Stereotype: " + currentStereo.Name );
 }
 }
 
 Session.Output( "Done!" );
}

ManageStereotypesExample();
"/>
</DataRow>
<DataRow>
<Column name="ScriptID" value="30"/>
<Column name="ScriptCategory" value="605A62F7-BCD0-4845-A8D0-7DC45B4D2E3F"/>
<Column name="ScriptName" value="{789F1989-2EAC-4c8b-B51A-1A666AA43428}"/>
<Column name="ScriptAuthor" value="{9BB70D4F-3874-4116-8185-AB0730F25791}"/>
<Column name="Notes" value="<Script Name="JavaScript-Method Lifecycle Example" Type="Internal" Language="JavaScript"/>
"/>
<Column name="Script" value="!INC JavaScriptLib.JavaScript-EAConstants
/* @Status tested successfully
 * An example of working with methods.
 *
 * NOTE: Requires an element to be selected in the Project Browser
 *
 * Related APIs
 * =================================================================================
 * Method API - http://www.sparxsystems.com/enterprise_architect_user_guide/15.1/automation_and_scripting/method.html
 */
function ManageMethodsExample()
{
 // Show the script output window
 Repository.EnsureOutputVisible( "Script" );

 // Get the currently selected element in the tree to work on
 var theElement as EA.Element;
 theElement = Repository.GetTreeSelectedObject();
 
 if ( theElement != null && theElement.ObjectType == otElement )
 {
 var addedMethodID = 0;

 Session.Output( "JavaScript METHOD LIFE CYCLE EXAMPLE" );
 Session.Output( "=======================================" );
 Session.Output( "Working on element '" + theElement.Name + "' (Type=" + theElement.Type +
 ", ID=" + theElement.ElementID + ")" );
 
 // ==================================================
 // ADD A METHOD
 // ==================================================
 // Create a method to work on
 var methods as EA.Collection;
 methods = theElement.Methods;
 
 var newMethod as EA.Method;
 newMethod = methods.AddNew( "TestMethod", "bool" );
 newMethod.Update();
 methods.Refresh();
 
 addedMethodID = newMethod.MethodID;
 
 Session.Output( "Added method: " + newMethod.Name +
 "(ID=" + addedMethodID + ")" );
 
 // ==================================================
 // MANAGE METHOD PRECONDITIONS
 // ==================================================
 // Add a PreCondition
 var preConditions as EA.Collection;
 preConditions = newMethod.PreConditions;
 
 var newPreCondition as EA.MethodConstraint;
 newPreCondition = preConditions.AddNew( "TestPreCondition", "Precision" );
 newPreCondition.Update();
 preConditions.Refresh();
 
 Session.Output( "Added PreCondition: " + newPreCondition.Name );
 
 newPreCondition = null;
 
 // Search the collection for the added PreCondition and delete it
 for ( var i = 0 ; i < preConditions.Count ; i++ )
 {
 var currentPreCondition as EA.MethodConstraint;
 currentPreCondition = preConditions.GetAt( i );
 
 Session.Output( "PreCondition: " + currentPreCondition.Name );
 
 // Delete the PreCondition we just added
 if ( currentPreCondition.Name == "TestPreCondition" )
 {
 preConditions.DeleteAt( i, false );
 Session.Output( "Deleted PreCondition: " + currentPreCondition.Name );
 }
 }
 
 preConditions = null;
 
 // ==================================================
 // MANAGE METHOD POSTCONDITIONS
 // ==================================================
 // Add a PostCondition
 var postConditions as EA.Collection;
 postConditions = newMethod.PostConditions;
 
 var newPostCondition as EA.MethodConstraint;
 newPostCondition = postConditions.AddNew( "TestPostCondition", "Precision" );
 newPostCondition.Update();
 postConditions.Refresh();
 
 Session.Output( "Added PostCondition: " + newPostCondition.Name );
 
 newPostCondition = null;
 
 // Search the collection for the added PostCondition and delete it
 for ( var i = 0 ; i < postConditions.Count ; i++ )
 {
 var currentPostCondition as EA.MethodConstraint;
 currentPostCondition = postConditions.GetAt( i );
 
 Session.Output( "PostCondition: " + currentPostCondition.Name );
 
 // Delete the PostCondition we just added
 if ( currentPostCondition.Name == "TestPostCondition" )
 {
 postConditions.DeleteAt( i, true );
 Session.Output( "Deleted PostCondition: " + currentPostCondition.Name );
 }
 }
 
 postConditions = null;
 
 // ==================================================
 // MANAGE METHOD TAGGED VALUES
 // ==================================================
 // Add a method tag
 var tags as EA.Collection;
 tags = newMethod.TaggedValues;
 
 var newTag as EA.MethodTag;
 newTag = tags.AddNew( "MyMethodTag", "Number" );
 newTag.Update();
 tags.Refresh();
 
 Session.Output( "Added tag: " + newTag.Name + " (ID=" + newTag.TagID + ")" );
 
 newTag = null;
 
 // Search the tag collection for the added tag and delete it
 for ( var i = 0 ; i < tags.Count ; i++ )
 {
 var currentTag as EA.MethodTag;
 currentTag = tags.GetAt( i );
 
 Session.Output( "Method Tag: " + currentTag.Name );
 
 // Delete the tag we just added
 if ( currentTag.Name == "MyMethodTag" )
 {
 tags.DeleteAt( i, false );
 Session.Output( "Deleted Tag: " + currentTag.Name + 
 " (ID=" + currentTag.TagID + ")" );
 }
 }
 
 tags = null; 
 
 // ==================================================
 // MANAGE METHOD PARAMETERS
 // ==================================================
 // Add a method parameter
 var parameters as EA.Collection;
 parameters = newMethod.Parameters;
 
 var newParameter as EA.Parameter;
 newParameter = parameters.AddNew( "sName", "String" );
 newParameter.Update();
 parameters.Refresh();
 
 Session.Output( "Added parameter: " + newParameter.Name );
 
 newParameter = null;
 
 // Search the parameter collection for the added parameter and delete it
 for ( var i = 0 ; i < parameters.Count ; i++ )
 {
 var currentParameter as EA.MethodTag;
 currentParameter = parameters.GetAt( i );
 
 Session.Output( "Method Parameter: " + currentParameter.Name );
 
 // Delete the parameter we just added
 if ( currentParameter.Name == "sName" )
 {
 parameters.DeleteAt( i, false );
 Session.Output( "Deleted Parameter: " + currentParameter.Name );
 }
 }
 
 parameters = null;
 
 // ==================================================
 // LIST AND DELETE METHODS
 // ==================================================
 newMethod = null;
 
 // List methods
 for ( var i = 0 ; i < methods.Count ; i++ )
 {
 var currentMethod as EA.Method;
 currentMethod = methods.GetAt( i );
 
 Session.Output( "Method: " + currentMethod.Name );
 
 // Delete the method we added
 if ( currentMethod.MethodID == addedMethodID )
 {
 methods.DeleteAt( i, false );
 Session.Output( "Deleted Method: " + currentMethod.Name +
 " (ID=" + currentMethod.MethodID + ")" );
 }
 }
 
 methods = null;
 
 Session.Output( "Done!" );
 }
 else
 {
 // No item selected in the tree, or the item selected was not an element
 Session.Prompt( "This script requires an element be selected in the Project Browser.\n" +
 "Please select an element in the Project Browser and try again.", promptOK );
 }
}

ManageMethodsExample();
"/>
</DataRow>
<DataRow>
<Column name="ScriptID" value="31"/>
<Column name="ScriptCategory" value="605A62F7-BCD0-4845-A8D0-7DC45B4D2E3F"/>
<Column name="ScriptName" value="{7AEA570E-DE40-4044-BA2E-EEE4A7CA72C3}"/>
<Column name="ScriptAuthor" value="{9BB70D4F-3874-4116-8185-AB0730F25791}"/>
<Column name="Notes" value="<Script Name="JavaScript-Model Search Attributes Example" Type="Internal" Language="JavaScript"/>
"/>
<Column name="Script" value="!INC JavaScriptLib.JavaScript-EAConstants

/* @Status Unknown.
 * Example of how to utilise the search window from scripts
 * 
 * NOTE: Requires an element to be selected in context
 *
 * Related APIs
 * =================================================================================
 * Repository API - http://www.sparxsystems.com/enterprise_architect_user_guide/15.1/automation_and_scripting/repository3.html
 * Attribute API - http://www.sparxsystems.com/enterprise_architect_user_guide/15.1/automation_and_scripting/attribute.html
 * Element API - http://www.sparxsystems.com/enterprise_architect_user_guide/15.1/automation_and_scripting/element2.html
 */

// The columns that will apear in the Model Search window
var SEARCH_SPECIFICATION = "<ReportViewData>" +
 "<Fields>" +
 "<Field name=\"CLASSGUID\" />" +
 "<Field name=\"CLASSTYPE\" />" +
 "<Field name=\"Name\" />" +
 "<Field name=\"Scope\" />" +
 "<Field name=\"Stereotype\" />" +
 "<Field name=\"Type\" />" +
 "<Field name=\"Note\" />" +
 "<Field name=\"Element\" />" +
 "</Fields>" +
 "<Rows/>" +
 "</ReportViewData>";

function CreateXMLObject()
{
 var xmlDOM;
 try
 {
 xmlDOM = new COMXObject( "MSXML2.DOMDocument.4.0" );
 }
 catch(e)
 {
 xmlDOM = new COMObject( "MSXML2.DOMDocument.6.0" );
 }
 
 xmlDOM.validateOnParse = false;
 xmlDOM.async = false;
 
 return xmlDOM;
} 
/*
 * Finds all Attributes and inherited Attributes of the selected context element.
 * The results are added to an XML document and passed back to the Model Search window to display 
 * the results.
 */ 
function RunModelSearchExample()
{
 // Show the script output window
 Repository.EnsureOutputVisible( "Script" );

 Session.Output( "JScript RUN MODEL SEARCH EXAMPLE" );
 Session.Output( "=======================================" );
 
 // Create a DOM object to represent the search tree
 var xmlDOM = CreateXMLObject();
 
 // If an element is selected in context, get its Attributes, including any inherited 
 // Attributes
 var selectedObject as EA.Element;
 selectedObject = Repository.GetContextObject();
 
 if( selectedObject != null && selectedObject.ObjectType == otElement )
 {
 Session.Output( "Working on element '" + selectedObject.Name + "' (Type=" + 
 selectedObject.Type + ", ID=" + selectedObject.ElementID + ")" );
 
 // Retrieve all attributes and inherited attributes for this object
 var attributesCollection as EA.Collection;
 attributesCollection = selectedObject.AttributesEx;
 
 // Load the search template
 if( xmlDOM.loadXML(SEARCH_SPECIFICATION) )
 {
 var node = xmlDOM.selectSingleNode( "//ReportViewData//Rows" );
 
 if( attributesCollection.Count > 0 )
 {
 var objectIDs = "";
 
 // Get the Object IDs for all elements that declare attributes in the inheritance
 // hierarchy of the selected object
 objectIDs = GetObjectIDs( attributesCollection );
 
 if( objectIDs != "" )
 { 
 // Now we have the IDs of all elements in the hierarchy, get the actual elements
 // themselves
 var elementCollection as EA.Collection;
 elementCollection = GetElementSet( objectIDs, 0 );
 
 // For each Attribute extract the information to populate our XML document, this 
 // will make up the row data in the Model Search window
 var lastID = selectedObject.ElementID;
 var elementName = selectedObject.Name;
 
 for( var i = 0; i < attributesCollection.Count; i++ )
 {
 var attribute as EA.Attribute;
 attribute = attributesCollection.GetAt( i );
 
 if( attribute == null )
 continue;
 
 // If the attribute belongs to the selected Element use its name, other wise
 // get the name of the Element for the inherited attribute.
 if(lastID != attribute.ParentID)
 {
 elementName = GetOwningElementName( elementCollection, attribute );
 lastID = attribute.ParentID ;
 }
 
 // Add this element to the XML tree
 AddRow( xmlDOM, node, elementName, attribute );
 }
 }
 else
 { 
 Session.Output( "Error constructing Object ID list" );
 }
 }
 
 // Fill the Model Search window with the results
 Repository.RunModelSearch( "", "", "", xmlDOM.xml );
 }
 else
 {
 Session.Prompt( "Failed to load search xml", promptOK );
 }
 
 Session.Output( "Done!" );
 
 }
 else
 {
 // No item selected in context, or the item selected was not an element
 Session.Prompt( "This script requires the current context item to be an element.\n" +
 "Please select an element and try again.", promptOK );
 }
}

/*
 * Trims any of the set of characters given in 'chars' from the end of the string 'str'
 */
function RTrim(str, chars)
{
 chars = chars || "\\s";
 return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}

/*
 * Adds an entry for the attribute object 'theAttribute' to the xml row node 'rowsNode'
 */
function AddRow( xmlDOM, rowsNode, elementName, theAttribute )
{
 // Cast theAttribute for intellisense
 var attribute as EA.Attribute;
 attribute = theAttribute;

 // Create a Row node
 var row = xmlDOM.createElement( "Row" );
 
 // Add the Model Search row data to our DOM
 AddField( xmlDOM, row, "CLASSGUID", attribute.AttributeGUID );
 AddField( xmlDOM, row, "CLASSTYPE", "Attribute" );
 AddField( xmlDOM, row, "Name", attribute.Name );
 AddField( xmlDOM, row, "Scope", attribute.Visibility );
 AddField( xmlDOM, row, "Stereotype", attribute.Stereotype );
 AddField( xmlDOM, row, "Type", attribute.Type );
 AddField( xmlDOM, row, "Note", attribute.Notes );
 AddField( xmlDOM, row, "Element", elementName );
 
 // Append the newly created row node to the rows node
 rowsNode.appendChild( row );
}

/*
 * Adds an Element to our DOM called Field which makes up the Row data for the Model Search window.
 * <Field name "" value ""/>
 */
function AddField( xmlDOM, row, name, value )
{
 var fieldNode = xmlDOM.createElement( "Field" );
 
 // Create first attribute for the name
 var nameAttribute = xmlDOM.createAttribute( "name" );
 nameAttribute.value = name;
 fieldNode.attributes.setNamedItem( nameAttribute );
 
 // Create second attribute for the value
 var valueAttribute = xmlDOM.createAttribute( "value" );
 valueAttribute.value = value;
 fieldNode.attributes.setNamedItem( valueAttribute );
 
 // Append the fieldNode
 row.appendChild( fieldNode );
}

/*
 * Returns the name of the element in 'theElementCollection' that declares the attribute 'theAttribute'
 */
function GetOwningElementName( theElementCollection, theAttribute )
{
 // Cast theAttribute to get intellisense
 var currentAttribute as EA.Attribute;
 currentAttribute = theAttribute;
 
 // Cast elementCollection to get intellisense
 var elementCollection as EA.Collection;
 elementCollection = theElementCollection;
 
 var elementName = "";
 
 // Iterate through elements in the elementCollection to find the declaring element
 for( var i = 0; i < elementCollection.Count; i++ )
 {
 // Get the current element
 var element as EA.Element;
 element = elementCollection.GetAt( i );
 
 // Is this element the declaring element?
 if( element != null && element.ElementID == currentAttribute.ParentID )
 {
 // If it is then set the elementName variable appropriately
 elementName = element.Name;
 break;
 }
 } 
 
 return elementName;
}

/*
 * Returns the signature of the provided attribute object 'theAttribute'. The signature is returned as a
 * comma separated list of parameter types
 */
function BuildAttributeSignature( theAttribute )
{
 // Cast theAttribute for intellisense
 var currentAttribute as EA.Attribute;
 currentAttribute = theAttribute;
 
 // Get a list of all parameters for the attribute
 var parameterCollection as EA.Collection;
 parameterCollection = currentAttribute.Parameters;

 var attributeSignature = "";
 
 //Construct the signature of the Attribute
 for( var i = 0; i < parameterCollection.Count; i++)
 {
 var currentParameter as EA.Parameter;
 currentParameter = parameterCollection.GetAt( i );
 
 if( currentParameter != null )
 {
 // Add the currentParameter's type to the attributeSignature string
 attributeSignature = attributeSignature + currentParameter.Type + ", ";
 }
 }
 
 // Trim the trailing comma from the signature
 attributeSignature = RTrim( attributeSignature, ", " );
 
 return attributeSignature;
}

/*
 * Returns a unique comma seperated string of Element IDs for every Attribute and inherited Attribute of
 * the selected Class in the Project Browser
 */
function GetObjectIDs( attributesCollection )
{
 // Cast attributesCollection for intellisense
 var theAttributesCollection as EA.Collection;
 theAttributesCollection = attributesCollection;
 
 var objectIDs = "";
 var lastID = 0;
 
 // Iterate through all attributes and add their parent ID to the objectIDs list
 for( var i = 0; i < theAttributesCollection.Count; i++ )
 {
 var attribute = theAttributesCollection.GetAt( i );

 // Only record each objectID once
 if( lastID != attribute.ParentID )
 {
 objectIDs = objectIDs + attribute.ParentID + ",";
 lastID = attribute.ParentID;
 }
 }
 
 // Trim the trailing comma from the objectIDs list
 objectIDs = RTrim( objectIDs, "," );
 
 return objectIDs;
}

RunModelSearchExample();
"/>
</DataRow>
<DataRow>
<Column name="ScriptID" value="32"/>
<Column name="ScriptCategory" value="605A62F7-BCD0-4845-A8D0-7DC45B4D2E3F"/>
<Column name="ScriptName" value="{0FF9F545-5B23-43aa-91C2-55686164611E}"/>
<Column name="ScriptAuthor" value="{9BB70D4F-3874-4116-8185-AB0730F25791}"/>
<Column name="Notes" value="<Script Name="JavaScript-Model Search Operations Example" Type="Internal" Language="JavaScript"/>
"/>
<Column name="Script" value="!INC JavaScriptLib.JavaScript-EAConstants

/*@Status Tested successfully
 * Example of how to utilise the search window from scripts
 * 
 * NOTE: Requires an element to be selected in context
 *
 * Related APIs
 * =================================================================================
 * Repository API - http://www.sparxsystems.com/enterprise_architect_user_guide/12.1/automation_and_scripting/repository3.html
 * Method API - http://www.sparxsystems.com/enterprise_architect_user_guide/12.1/automation_and_scripting/method.html 
 * Element API - http://www.sparxsystems.com/enterprise_architect_user_guide/12.1/automation_and_scripting/element2.html
 */

// The columns that will appear in the Model Search window
var SEARCH_SPECIFICATION = "<ReportViewData>" +
 "<Fields>" +
 "<Field name=\"CLASSGUID\" />" +
 "<Field name=\"CLASSTYPE\" />" +
 "<Field name=\"Abstract\" />" +
 "<Field name=\"Name\" />" +
 "<Field name=\"Parameters\" />" +
 "<Field name=\"Scope\" />" +
 "<Field name=\"Stereotype\" />" +
 "<Field name=\"ReturnType\" />" +
 "<Field name=\"Note\" />" +
 "<Field name=\"Element\" />" +
 "</Fields>" +
 "<Rows/>" +
 "</ReportViewData>";

function CreateXMLObject()
{
 var xmlDOM;
 try
 {
 xmlDOM = new COMObject( "MSXML2.DOMDocument.4.0" );
 }
 catch(e)
 {
 xmlDOM = new COMXObject( "MSXML2.DOMDocument.6.0" );
 }
 
 xmlDOM.validateOnParse = false;
 xmlDOM.async = false;
 
 return xmlDOM;
}

/*
 * Finds all Methods and inherited Methods of the selected context element.
 * The results are added to an XML document and passed back to the Model Search window to display 
 * the results.
 */ 
function RunModelSearchExample()
{
 // Show the script output window
 Repository.EnsureOutputVisible( "Script" );
 
 Session.Output( "JScript RUN MODEL SEARCH EXAMPLE" );
 Session.Output( "=======================================" );
 
 // Create a DOM object to represent the search tree
 var xmlDOM = CreateXMLObject();
 
 // If an element is selected in context, get its Methods, including any inherited 
 // Methods
 var selectedObject as EA.Element;
 selectedObject = Repository.GetContextObject();
 
 if( selectedObject != null && selectedObject.ObjectType == otElement )
 {
 Session.Output( "Working on element '" + selectedObject.Name + "' (Type=" + 
 selectedObject.Type + ", ID=" + selectedObject.ElementID + ")" );
 
 // Retrieve all methods and inherited methods for this object
 var methodsCollection as EA.Collection;
 methodsCollection = selectedObject.MethodsEx;
 
 // Load the search template
 if( xmlDOM.loadXML(SEARCH_SPECIFICATION) )
 {
 var node = xmlDOM.selectSingleNode( "//ReportViewData//Rows" );
 
 if( methodsCollection.Count > 0 )
 {
 var objectIDs = "";
 
 // Get the Object IDs for all elements that declare methods in the inheritance
 // hierarchy of the selected object
 objectIDs = GetObjectIDs( methodsCollection );
 
 if( objectIDs != "" )
 { 
 // Now we have the IDs of all elements in the hierarchy, get the actual elements
 // themselves
 var elementCollection as EA.Collection;
 elementCollection = GetElementSet( objectIDs, 0 );
 
 // For each Method extract the information to populate our XML document, this 
 // will make up the row data in the Model Search window
 var lastID = selectedObject.ElementID;
 var elementName = selectedObject.Name;
 
 for( var i = 0; i < methodsCollection.Count; i++ )
 {
 var method as EA.Method;
 method = methodsCollection.GetAt( i );
 
 if( method == null )
 continue;

 // Get the method's signature
 var methodSignature = BuildMethodSignature( method );
 
 // If the method belongs to the selected Element use its name, other wise
 // get the name of the Element for the inherited method.
 if(lastID != method.ParentID)
 {
 elementName = GetOwningElementName( elementCollection, method );
 lastID = method.ParentID ;
 }
 
 // Add this element to the XML tree
 AddRow( xmlDOM, node, elementName, method );
 }
 }
 else
 { 
 Session.Output( "Error constructing Object ID list" );
 }
 }
 
 // Fill the Model Search window with the results
 Repository.RunModelSearch( "", "", "", xmlDOM.xml );
 }
 else
 {
 Session.Prompt( "Failed to load search xml", promptOK );
 }
 
 Session.Output( "Done!" );
 
 }
 else
 {
 // No item selected in context, or the item selected was not an element
 Session.Prompt( "This script requires the current context item to be an element.\n" +
 "Please select an element and try again.", promptOK );
 }
}

/*
 * Trims any of the set of characters given in 'chars' from the end of the string 'str'
 */
function RTrim(str, chars)
{
 chars = chars || "\\s";
 return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}

/*
 * Adds an entry for the method object 'theMethod' to the xml row node 'rowsNode'
 */
function AddRow( xmlDOM, rowsNode, elementName, theMethod )
{
 // Cast theMethod for intellisense
 var method as EA.Method;
 method = theMethod;

 // Create a Row node
 var row = xmlDOM.createElement( "Row" );
 
 // Add the Model Search row data to our DOM
 AddField( xmlDOM, row, "CLASSGUID", method.MethodGUID );
 AddField( xmlDOM, row, "CLASSTYPE", "Operation" );
 AddField( xmlDOM, row, "Abstract", method.Abstract ? "Abstract" : "Concrete" );
 AddField( xmlDOM, row, "Name", method.Name );
 AddField( xmlDOM, row, "Parameters", BuildMethodSignature(method) );
 AddField( xmlDOM, row, "Scope", method.Visibility );
 AddField( xmlDOM, row, "Stereotype", method.Stereotype );
 AddField( xmlDOM, row, "ReturnType", method.ReturnType );
 AddField( xmlDOM, row, "Note", method.Notes );
 AddField( xmlDOM, row, "Element", elementName );
 
 // Append the newly created row node to the rows node
 rowsNode.appendChild( row );
}

/*
 * Adds an Element to our DOM called Field which makes up the Row data for the Model Search window.
 * <Field name "" value ""/>
 */
function AddField( xmlDOM, row, name, value )
{
 var fieldNode = xmlDOM.createElement( "Field" );
 
 // Create first attribute for the name
 var nameAttribute = xmlDOM.createAttribute( "name" );
 nameAttribute.value = name;
 fieldNode.attributes.setNamedItem( nameAttribute );
 
 // Create second attribute for the value
 var valueAttribute = xmlDOM.createAttribute( "value" );
 valueAttribute.value = value;
 fieldNode.attributes.setNamedItem( valueAttribute );
 
 // Append the fieldNode
 row.appendChild( fieldNode );
}

/*
 * Returns the name of the element in 'theElementCollection' that declares the method 'theMethod'
 */
function GetOwningElementName( theElementCollection, theMethod )
{
 // Cast theMethod to get intellisense
 var currentMethod as EA.Method;
 currentMethod = theMethod;
 
 // Cast elementCollection to get intellisense
 var elementCollection as EA.Collection;
 elementCollection = theElementCollection;
 
 var elementName = "";
 
 // Iterate through elements in the elementCollection to find the declaring element
 for( var i = 0; i < elementCollection.Count; i++ )
 {
 // Get the current element
 var element as EA.Element;
 element = elementCollection.GetAt( i );
 
 // Is this element the declaring element?
 if( element != null && element.ElementID == currentMethod.ParentID )
 {
 // If it is then set the elementName variable appropriately
 elementName = element.Name;
 break;
 }
 } 
 
 return elementName;
}

/*
 * Returns the signature of the provided method object 'theMethod'. The signature is returned as a
 * comma separated list of parameter types
 */
function BuildMethodSignature( theMethod )
{
 // Cast theMethod for intellisense
 var currentMethod as EA.Method;
 currentMethod = theMethod;
 
 // Get a list of all parameters for the method
 var parameterCollection as EA.Collection;
 parameterCollection = currentMethod.Parameters;

 var methodSignature = "";
 
 //Construct the signature of the Method
 for( var i = 0; i < parameterCollection.Count; i++)
 {
 var currentParameter as EA.Parameter;
 currentParameter = parameterCollection.GetAt( i );
 
 if( currentParameter != null )
 {
 // Add the currentParameter's type to the methodSignature string
 methodSignature = methodSignature + currentParameter.Type + ", ";
 }
 }
 
 // Trim the trailing comma from the signature
 methodSignature = RTrim( methodSignature, ", " );
 
 return methodSignature;
}

/*
 * Returns a unique comma seperated string of Element IDs for every Method and inherited Method of
 * the selected Class in the Project Browser
 */
function GetObjectIDs( methodsCollection )
{
 // Cast methodsCollection for intellisense
 var theMethodsCollection as EA.Collection;
 theMethodsCollection = methodsCollection;
 
 var objectIDs = "";
 var lastID = 0;
 
 // Iterate through all methods and add their parent ID to the objectIDs list
 for( var i = 0; i < theMethodsCollection.Count; i++ )
 {
 var method = theMethodsCollection.GetAt( i );

 // Only record each objectID once
 if( lastID != method.ParentID )
 {
 objectIDs = objectIDs + method.ParentID + ",";
 lastID = method.ParentID;
 }
 }
 
 // Trim the trailing comma from the objectIDs list
 objectIDs = RTrim( objectIDs, "," );
 
 return objectIDs;
}

RunModelSearchExample();
"/>
</DataRow>
<DataRow>
<Column name="ScriptID" value="33"/>
<Column name="ScriptCategory" value="605A62F7-BCD0-4845-A8D0-7DC45B4D2E3F"/>
<Column name="ScriptName" value="{4C242BE1-4C3D-4483-8A32-F16F36D50044}"/>
<Column name="ScriptAuthor" value="{9BB70D4F-3874-4116-8185-AB0730F25791}"/>
<Column name="Notes" value="<Script Name="JavaScript-Non-Recursive Model Dump Example" Type="Internal" Language="JavaScript"/>
"/>
<Column name="Script" value="!INC JavaScriptLib.JavaScript-EAConstants
!INC JavaScriptLib.JavaScript-Enumerator
// @Status Tested successfully
// Lists all top level packages and diagrams underneath them in a non-recursive style.
// 
// Related APIs
// =================================================================================
// Repository API - http://www.sparxsystems.com/enterprise_architect_user_guide/12.1/automation_and_scripting/repository3.html
//
function NonRecursiveModelDumpExample()
{
 // Show the script output window
 Repository.EnsureOutputVisible( "Script" );

 Session.Output( "JavaScript NON RECURSIVE MODEL DUMP EXAMPLE" );
 Session.Output( "=======================================" );
 
 // Get the first model node
 var theModel as EA.Package;
 theModel = Repository.Models.GetAt( 0 );
 
 // Iterate through all views (top level packages) in the model
 var viewEnumerator = new Enumerator( theModel.Packages );
 while ( !viewEnumerator.atEnd() )
 {
 var currentView as EA.Package;
 currentView = viewEnumerator.item();
 
 // Add the name of this view to the output window
 Session.Output( currentView.Name );
 
 // Iterate through all diagrams in this view
 var diagramEnumerator = new Enumerator( currentView.Diagrams );
 while ( !diagramEnumerator.atEnd() )
 {
 var currentDiagram as EA.Diagram;
 currentDiagram = diagramEnumerator.item();
 
 // Add the name of this diagram to the output window
 Session.Output( " -> Diagram: " + currentDiagram.Name );
 
 // Iterate through all objects in this diagram
 var diagramObjectEnumerator = new Enumerator( currentDiagram.DiagramObjects );
 while ( !diagramObjectEnumerator.atEnd() )
 {
 var currentDiagramObject as EA.DiagramObject;
 currentDiagramObject = diagramObjectEnumerator.item();
 
 // Get the element that this Diagram Object represents
 var currentElement as EA.Element;
 currentElement = Repository.GetElementByID( currentDiagramObject.ElementID );
 
 if ( currentElement != null )
 {
 // Add the element details to the output window
 Session.Output( " -> Element: " + currentElement.Name +
 " (" + currentElement.Type +
 ", ID=" + currentElement.ElementID + ")" );
 }
 
 diagramObjectEnumerator.moveNext();
 }
 
 diagramEnumerator.moveNext();
 }
 
 viewEnumerator.moveNext();
 }
 
 Session.Output( "Done!" );
}

NonRecursiveModelDumpExample();
"/>
</DataRow>
<DataRow>
<Column name="ScriptID" value="34"/>
<Column name="ScriptCategory" value="605A62F7-BCD0-4845-A8D0-7DC45B4D2E3F"/>
<Column name="ScriptName" value="{37FB900C-2951-4bd1-A43B-237342959382}"/>
<Column name="ScriptAuthor" value="{9BB70D4F-3874-4116-8185-AB0730F25791}"/>
<Column name="Notes" value="<Script Name="JavaScript-Project Browser Multi Selection Example" Type="Internal" Language="JavaScript"/>
"/>
<Column name="Script" value="!INC JavaScriptLib.JavaScript-EAConstants

//@Status Tested Successfully
// Outputs the details of elements selected in the Project Browser
// 
// Related APIs
// =================================================================================
// Repository API - http://www.sparxsystems.com/enterprise_architect_user_guide/15.1/automation_and_scripting/repository3.html
//
function MultiSelectionExample()
{
 // Show the script output window
 Repository.EnsureOutputVisible( "Script" );

 Session.Output( "JavaScript Project Browser Multi Selection Example" );
 Session.Output( "=======================================" );
 
 // Get the set of selected items as a collection
 var selectedElements as EA.Collection;
 selectedElements = Repository.GetTreeSelectedElements();
 
 var selectedElementCount = selectedElements.Count;
 if ( selectedElementCount > 0 )
 {
 // Iterate over all of the selected elements
 for ( var i = 0 ; i < selectedElementCount ; i++ )
 {
 var theElement as EA.Element;
 theElement = selectedElements.GetAt( i );
 
 // Output the details of the current selected element
 var message = "Element Name: " + theElement.Name;
 message += "\nGUID: " + theElement.ElementGUID;
 message += "\nType: " + theElement.Type;
 message += "\nStereotype: " + theElement.StereotypeEx;
 message += "\nID: " + theElement.ElementID;
 message += "\n\n";
 Session.Output( message );
 }
 
 Session.Output( "Done!" );
 }
 else
 {
 // No item selected in the tree, or the item selected was not an element
 Session.Prompt( "This script requires one or more elements to be selected in the Project Browser.\n" +
 "Please select a range of elements in the Project Browser and try again.", promptOK );
 }
}

MultiSelectionExample();

"/>
</DataRow>
<DataRow>
<Column name="ScriptID" value="35"/>
<Column name="ScriptCategory" value="605A62F7-BCD0-4845-A8D0-7DC45B4D2E3F"/>
<Column name="ScriptName" value="{2DC9A50F-ACA0-4b80-A4F2-B6FAECA324BE}"/>
<Column name="ScriptAuthor" value="{9BB70D4F-3874-4116-8185-AB0730F25791}"/>
<Column name="Notes" value="<Script Name="JavaScript-Project Interface Example" Type="Internal" Language="JavaScript"/>
"/>
<Column name="Script" value="!INC JavaScriptLib.JavaScript-EAConstants
!INC JavaScriptLib.JavaScript-Enumerator
// Examples of how to access and use the Project Interface.
// 
// Related APIs
// =================================================================================
// Project Interface API - http://www.sparxsystems.com/enterprise_architect_user_guide/12.1/automation_and_scripting/project_2.html
//

// Global reference to the project interface
var projectInterface as EA.Project

function ProjectInterfaceExample()
{
 // Show the script output window
 Repository.EnsureOutputVisible( "Script" );

 Session.Output( "JavaScript PROJECT INTERFACE EXAMPLE" );
 Session.Output( "=======================================" );
 
 projectInterface = Repository.GetProjectInterface();
 
 // Iterate through all model nodes
 var modelEnumerator = new Enumerator( Repository.Models );
 while ( !modelEnumerator.atEnd() )
 {
 var currentModel as EA.Package;
 currentModel = modelEnumerator.item();
 
 // Iterate through all child packages and save out their diagrams
 var childPackageEnumerator = new Enumerator( currentModel.Packages );
 while ( !childPackageEnumerator.atEnd() )
 {
 var childPackage = childPackageEnumerator.item();
 DumpDiagrams( childPackage );
 
 childPackageEnumerator.moveNext();
 }
 
 modelEnumerator.moveNext();
 }
 
 Session.Output( "Done!" );
}

//
// Recursively saves all diagrams under the provided package and its children
//
function DumpDiagrams( thePackage )
{
 // Cast thePackage to EA.Package so we get intellisense
 var currentPackage as EA.Package;
 currentPackage = thePackage;
 
 // Iterate through all diagrams in the current package
 var diagramEnumerator = new Enumerator( currentPackage.Diagrams );
 while ( !diagramEnumerator.atEnd() )
 {
 var currentDiagram as EA.Diagram;
 currentDiagram = diagramEnumerator.item();
 
 // Open the diagram
 Repository.OpenDiagram( currentDiagram.DiagramID );
 
 // Save and close the diagram
 Session.Output( "Saving " + currentDiagram.Name );
 projectInterface.SaveDiagramImageToFile( "c:\\temp\\" + currentDiagram.Name + ".emf" );
 Repository.CloseDiagram( currentDiagram.DiagramID );
 
 diagramEnumerator.moveNext();
 }
 
 // Process child packages
 var childPackageEnumerator = new Enumerator( currentPackage.Packages );
 while ( !childPackageEnumerator.atEnd() )
 {
 var childPackage = childPackageEnumerator.item();
 DumpDiagrams( childPackage );
 
 childPackageEnumerator.moveNext();
 } 
}

ProjectInterfaceExample();"/>
</DataRow>
<DataRow>
<Column name="ScriptID" value="36"/>
<Column name="ScriptCategory" value="605A62F7-BCD0-4845-A8D0-7DC45B4D2E3F"/>
<Column name="ScriptName" value="{1170E010-369E-437a-9F81-498673A6C407}"/>
<Column name="ScriptAuthor" value="{9BB70D4F-3874-4116-8185-AB0730F25791}"/>
<Column name="Notes" value="<Script Name="JavaScript-Recursive Element Count Example" Type="Internal" Language="JavaScript"/>
"/>
<Column name="Script" value="!INC JavaScriptLib.JavaScript-EAConstants
!INC JavaScriptLib.JavaScript-Enumerator

// @Status Tested Successfully
// Recursively counts the number of elements in the selected package and its children
// 
// Related APIs
// =================================================================================
// Package API - http://www.sparxsystems.com/enterprise_architect_user_guide/12.1/automation_and_scripting/package_2.htm
// Repository API - http://www.sparxsystems.com/enterprise_architect_user_guide/12.1/automation_and_scripting/repository3.html
//

function RecursiveElementCountExample()
{
 // Show the script output window
 Repository.EnsureOutputVisible( "Script" );

 Session.Output( "JavaScript RECURSIVE ELEMENT COUNT EXAMPLE" );
 Session.Output( "=======================================" );
 
 // Get the package to work on
 var contextObjectType = Repository.GetContextItemType();
 
 if ( contextObjectType == otPackage )
 {
 var elementCounter = 0;
 
 // Get the context object as a package
 var contextPackage as EA.Package;
 contextPackage = Repository.GetContextObject();
 
 // Recursively count the number of elements in the package and its
 // children
 elementCounter = CountElements( contextPackage );
 
 // Output the results!
 var message = "Package '" + contextPackage.Name + "' has " + elementCounter +
 " element(s) under it";
 
 Session.Prompt( message, promptOK );
 Session.Output( message );
 
 Session.Output( "Done!" );
 }
 else
 {
 Session.Prompt( "This script requires a package to be selected.\n" +
 "Please select a package and try again.", promptOK );
 }
}

//
// Counts the number of elements under the provided package and its children
//
function CountElements( thePackage )
{
 var count = 0;
 
 // Cast thePackage to EA.Package so we get intellisense
 var contextPackage as EA.Package;
 contextPackage = thePackage;
 
 // Iterate through all child packages
 var childPackageEnumerator = new Enumerator( contextPackage.Packages );
 while ( !childPackageEnumerator.atEnd() )
 {
 var currentPackage as EA.Package;
 currentPackage = childPackageEnumerator.item();
 
 // Recursively process child packages
 count = count + CountElements( currentPackage );
 
 childPackageEnumerator.moveNext();
 }
 
 // Add this package's element count to the counter
 return count + contextPackage.Elements.Count;
}

RecursiveElementCountExample();"/>
</DataRow>
<DataRow>
<Column name="ScriptID" value="37"/>
<Column name="ScriptCategory" value="605A62F7-BCD0-4845-A8D0-7DC45B4D2E3F"/>
<Column name="ScriptName" value="{A520C4DE-2F19-4d8a-A129-BDEC54659B39}"/>
<Column name="ScriptAuthor" value="{9BB70D4F-3874-4116-8185-AB0730F25791}"/>
<Column name="Notes" value="<Script Name="JavaScript-Respository Extras Example" Type="Internal" Language="JavaScript"/>
"/>
<Column name="Script" value="!INC JavaScriptLib.JavaScript-EAConstants

// @Status Tested Successfully
// Examples of how to access repository collections for system level information.
// 
// Related APIs
// =================================================================================
// Repository API - http://www.sparxsystems.com/enterprise_architect_user_guide/15.1/automation_and_scripting/repository3.html
//
function RepositoryExtrasExample()
{
 // Show the script output window
 Repository.EnsureOutputVisible( "Script" );

 Session.Output( "JavaScript REPOSITORY EXTRAS EXAMPLE" );
 Session.Output( "=======================================" ) ;
 
 // ==================================================
 // MANAGE PROJECT ISSUES
 // ==================================================
 // Add a project issue
 var issues as EA.Collection;
 issues = Repository.Issues;
 
 var newIssue as EA.ProjectIssues;
 newIssue = issues.AddNew( "Problem", "Defect" );
 
 newIssue.Update();
 issues.Refresh();
 
 var newIssueID = newIssue.IssueID;
 Session.Output( "Added new Issue: " + newIssue.Name + " (ID=" +
 newIssueID + ")" );
 
 newIssue = null;
 
 // List all project issues
 for ( var i = 0 ; i < issues.Count ; i++ )
 {
 var currentIssue as EA.ProjectIssues;
 currentIssue = issues.GetAt( i );
 
 Session.Output( "Issue: " + currentIssue.Name );
 
 // Delete the project issue that we just added
 if ( currentIssue.IssueID == newIssueID )
 {
 issues.DeleteAt( i, false );
 Session.Output( "Deleted issue: " + currentIssue.Name +
 " (ID=" + currentIssue.IssueID + ")" );
 }
 }
 
 issues = null;
 
 // ==================================================
 // MANAGE TASKS
 // ==================================================
 // Add a task
 var tasks as EA.Collection;
 tasks = Repository.Tasks
 
 var newTask as EA.Task;
 newTask = tasks.AddNew( "NewTask", "Defect" );
 
 newTask.Update();
 tasks.Refresh();
 
 var newTaskID = newTask.TaskID;
 Session.Output( "Added new Task: " + newTask.Name + " (ID=" +
 newTaskID + ")" );
 
 newTask = null;
 
 // List all tasks
 for ( var i = 0 ; i < tasks.Count ; i++ )
 {
 var currentTask as EA.Task;
 currentTask = tasks.GetAt( i );
 
 Session.Output( "Task: " + currentTask.Name );
 
 // Delete the task that we just added
 if ( currentTask.TaskID == newTaskID )
 {
 tasks.DeleteAt( i, false );
 Session.Output( "Deleted task: " + currentTask.Name +
 " (ID=" + currentTask.TaskID + ")" );
 }
 }
 
 tasks = null;
 
 // ==================================================
 // MANAGE GLOSSARY TERMS
 // ==================================================
 // Add a term
 var terms as EA.Collection;
 terms = Repository.Terms
 
 var newTerm as EA.Term;
 newTerm = terms.AddNew( "NewTerm", "Business" );
 
 newTerm.Update();
 terms.Refresh();
 
 var newTermID = newTerm.TermID;
 Session.Output( "Added new Term: " + newTerm.Term + " (ID=" +
 newTermID + ")" );
 
 newTerm = null;
 
 // List all terms
 for ( var i = 0 ; i < terms.Count ; i++ )
 {
 var currentTerm as EA.Term;
 currentTerm = terms.GetAt( i );
 
 Session.Output( "Term: " + currentTerm.Term );
 
 // Delete the term that we just added
 if ( currentTerm.TermID == newTermID )
 {
 terms.DeleteAt( i, false );
 Session.Output( "Deleted term: " + currentTerm.Term +
 " (ID=" + currentTerm.TermID + ")" );
 }
 }
 
 terms = null;
 
 // ==================================================
 // MANAGE AUTHORS
 // ==================================================
 // Add an author
 var authors as EA.Collection;
 authors = Repository.Authors;
 
 var newAuthor as EA.Author;
 newAuthor = authors.AddNew( "Author P. McAuthor", "Writer" );
 
 newAuthor.Update();
 authors.Refresh();
 
 Session.Output( "Added new author: " + newAuthor.Name );
 
 newAuthor = null;
 
 // List all authors
 for ( var i = 0 ; i < authors.Count ; i++ )
 {
 var currentAuthor as EA.Author;
 currentAuthor = authors.GetAt( i );
 
 Session.Output( "Author: " + currentAuthor.Name );
 
 // Delete the author that we just added
 if ( currentAuthor.Name == "Author P. McAuthor" )
 {
 authors.DeleteAt( i, false );
 Session.Output( "Deleted author: " + currentAuthor.Name );
 }
 }
 
 authors = null; 

 // ==================================================
 // MANAGE CLIENTS
 // ==================================================
 // Add a Client
 var clients as EA.Collection;
 clients = Repository.Clients;
 
 var newClient as EA.Client;
 newClient = clients.AddNew( "Joe Client", "Client" );
 
 newClient.Update();
 clients.Refresh();
 
 Session.Output( "Added new client: " + newClient.Name );
 
 newClient = null;
 
 // List all clients
 for ( var i = 0 ; i < clients.Count ; i++ )
 {
 var currentClient as EA.Client;
 currentClient = clients.GetAt( i );
 
 Session.Output( "Client: " + currentClient.Name );
 
 // Delete the client that we just added
 if ( currentClient.Name == "Joe Client" )
 {
 clients.DeleteAt( i, false );
 Session.Output( "Deleted client: " + currentClient.Name );
 }
 }
 
 clients = null; 

 // ==================================================
 // MANAGE PROJECT RESOURCES
 // ==================================================
 // Add a Project Resource
 var resources as EA.Collection;
 resources = Repository.Resources;
 
 var newResource as EA.Resource;
 newResource = resources.AddNew( "Senor Resource", "Resource" );
 
 newResource.Update();
 resources.Refresh();
 
 Session.Output( "Added new resource: " + newResource.Name );
 
 newResource = null;
 
 // List all resources
 for ( var i = 0 ; i < resources.Count ; i++ )
 {
 var currentResource as EA.Resource;
 currentResource = resources.GetAt( i );
 
 Session.Output( "Resource: " + currentResource.Name );
 
 // Delete the resource that we just added
 if ( currentResource.Name == "Senor Resource" )
 {
 resources.DeleteAt( i, false );
 Session.Output( "Deleted resource: " + currentResource.Name );
 }
 }
 
 resources = null; 
 
 Session.Output( "Done!" );
 
}

RepositoryExtrasExample();"/>
</DataRow>
<DataRow>
<Column name="ScriptID" value="42"/>
<Column name="ScriptCategory" value="ScriptDebugging"/>
<Column name="ScriptName" value="ScriptDebugging"/>
<Column name="ScriptAuthor" value="ScriptDebugging"/>
<Column name="Notes" value="<?xml version="1.0"?>
<DATA><Debugger value="Scripting"/></DATA>
"/>
<Column name="Script" value=" "/>
</DataRow>
<DataRow>
<Column name="ScriptID" value="43"/>
<Column name="ScriptCategory" value="ScriptDebugging"/>
<Column name="ScriptName" value="ScriptDebugging"/>
<Column name="ScriptAuthor" value="ScriptDebugging"/>
<Column name="Notes" value="<?xml version="1.0"?>
<DATA><Debugger value="Scripting"/></DATA>
"/>
<Column name="Script" value=" "/>
</DataRow>
<DataRow>
<Column name="ScriptID" value="44"/>
<Column name="ScriptCategory" value="ScriptDebugging"/>
<Column name="ScriptName" value="ScriptDebugging"/>
<Column name="ScriptAuthor" value="ScriptDebugging"/>
<Column name="Notes" value="<?xml version="1.0"?>
<DATA><Debugger value="Scripting"/></DATA>
"/>
<Column name="Script" value=" "/>
</DataRow>
<DataRow>
<Column name="ScriptID" value="45"/>
<Column name="ScriptCategory" value="ScriptDebugging"/>
<Column name="ScriptName" value="ScriptDebugging"/>
<Column name="ScriptAuthor" value="ScriptDebugging"/>
<Column name="Notes" value="<?xml version="1.0"?>
<DATA><Debugger value="Scripting"/></DATA>
"/>
<Column name="Script" value=" "/>
</DataRow>
<DataRow>
<Column name="ScriptID" value="46"/>
<Column name="ScriptCategory" value="ScriptDebugging"/>
<Column name="ScriptName" value="ScriptDebugging"/>
<Column name="ScriptAuthor" value="ScriptDebugging"/>
<Column name="Notes" value="<?xml version="1.0"?>
<DATA><Debugger value="Scripting"/></DATA>
"/>
<Column name="Script" value=" "/>
</DataRow>
<DataRow>
<Column name="ScriptID" value="47"/>
<Column name="ScriptCategory" value="ScriptDebugging"/>
<Column name="ScriptName" value="ScriptDebugging"/>
<Column name="ScriptAuthor" value="ScriptDebugging"/>
<Column name="Notes" value="<?xml version="1.0"?>
<DATA><Debugger value="Scripting"/></DATA>
"/>
<Column name="Script" value=" "/>
</DataRow>
<DataRow>
<Column name="ScriptID" value="48"/>
<Column name="ScriptCategory" value="ScriptDebugging"/>
<Column name="ScriptName" value="ScriptDebugging"/>
<Column name="ScriptAuthor" value="ScriptDebugging"/>
<Column name="Notes" value="<?xml version="1.0"?>
<DATA><Debugger value="Scripting"/></DATA>
"/>