Displaying items by tag: script

Saturday, 25 November 2017 06:00

ArchiMate Search helper in EA

Introduction

One of the challenges of a teambased architecture repository based on the ArchiMate language is to reduce the number of duplicate entities. With duplicates I mean an Archimate concept with the same name and stereotype that has two or more instances in the repository.

Especially in large repositories with a complex project browser configuration and a large number of modellers the changes of duplicates are substantial. Therefore mostly a procedure is introduced based on the steps that a modeller has to do a repository search before he or she can actually add an element from the toolbox and modify it

Search

For searching for elements in the repository there is a search dialog availabe that opens by default in a simple common search that searches for a text in all the items. This works fine but has a number of limitations for an ArchiMate modeller:

  • The search is relatively slow
  • The modeller is not interested in the full content but only in ArchiMate elements of a specific type.

Luckily we can define our own searches in EA and an example of a ArchiMate specific search is shown bin the image below:

In this image you see that we can search for application components only and the list is by default sorted by objectname. This will help us in a later stage in user friendliness. The SQL statement is given below.

 

SELECT t_object.ea_guid AS CLASSGUID, t_object.name as ObjectName, t_object.Stereotype, ParentPkg.Name as ParentName, t_object.ModifiedDate, t_object.Author, t_object.[Version], t_object.[Alias], t_object.Object_Type as CLASSTYPE,t_object.Note as Notes FROM t_object, t_package as ParentPkg WHERE (t_object.name LIKE '#WC#[Search Term]#WC#' OR '[Search Term]'='') AND t_object.stereotype IN('ArchiMate_ApplicationComponent') AND t_object.Package_ID = ParentPkg.Package_ID ORDER BY t_object.Name

The trick is in two parts of the select statement:

  • The first one is that we filter on the stereotype of the element so we only see a limited number of elements based on that stereotype
  • The second is that we do a trick with the search term. We combine a search term search with a full search so you can see all the elements when the search term is empty

Model view

 

This helps us a lot in finding the relevant elements relatively fast however the search screen has a number of limitations in which selecting all the time the right query is relatively user unfriendly. However luckily Enterprise Architect has another screen for implementing this user friendly approach in a convenient way: the model view.

In the modelview you can define your own search view and link these views to a search in the search component of EA. See the picture below

In this screen you see a sample of a number of ArchiMate specific searches based on their stereotype. When you expand one of these searches you get the list of elements based on this stereotype. Since we have a combination of a keyword search and a full search (on the stereotype) the modeller can select the approach that best fits his needs. In the view you can select an element by typing in the first characters another option is to open the conext menu and go to the search function in EA and now we open the richt search immediately.

Download

For download of this solution or for downloading other scripts or add ons please visit the eaxpertise website.

Published in Community Resources

This script will search the text in the comments, scenario’s and linked document of the selected elements for terms in the domain model. If it finds a match it will create a trace from your selected element to the element in the domain model.

The idea is that when we write descriptions and scenario’s we often use terms already defined in the domain model, so it would be good if we had a real trace from the element in the domain model and the element using it in its description.

Link to domain model example

But it is hard to keep the descriptions and scenario’s in sync with the traces to the domain model. This script does the hard part for us and keeps those traces in sync. All you need to do is type your description and run the script. The script will find the referenced elements in the domain model and create a trace link to it. It will also remove any automatic traces that are not valid anymore.

Next to the NameNotes, and the Linked Document, this script will also search the scenarios, both theScenario Description, as the structured Scenario Steps. In case of a Scenario Step the script will insert to the name of the domain model element in the Uses column.Link to domain model scenario

Note that the script is case sensitive. That is the reason why RoomType does not appear in the uses column. Enterprise Architect itself isn’t that picky, and it underlines Roomtype anyway because it finds a relationship to RoomType.

In order to execute the script you have to select either one or more elements in the project browser, or select a package in the project browser.

Link to domain model menu option

Then select Script|Link To Domain Model

Free download

Trace to Domain Model script
Trace to Domain Model script
€0.00
Download

The script

In the first part we ask the user to select the domain model package.
If you want to use this script on a particular model you may want to replace that by a hard coding the Domain models GUID into the script.
Since this script may run for a while on a large model, we also create an output tab so we can inform the user of our progress.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
sub main
    'let the user select the domain model package
    dim response
    response = Msgbox ("Please select the domain model package", vbOKCancel+vbQuestion, "Selecte domain model")
    if response = vbOK then
         
        dim domainModelPackage as EA.Package
        set domainModelPackage = selectPackage()
        if not domainModelPackage is nothing then
            Repository.CreateOutputTab "Link to Domain Model"
            Repository.ClearOutput "Link to Domain Model"
            Repository.EnsureOutputVisible "Link to Domain Model"
            'link selected elements to the domain model elements
            linkSelectionToDomainModel(domainModelPackage)
            'tell the user we are done
            Repository.WriteOutput "Link to Domain Model", "Finished!", 0
        end if
    end if
end sub

Next we create a dictionary of all classes in domain model package and all of the sub-packages recursively.

1
2
3
4
5
6
7
8
'first get the pattern from all the classes in the domain model
dim dictionary
Set dictionary = CreateObject("Scripting.Dictionary")
 
'create domain model dictionary
'tell the user what we are doing
Repository.WriteOutput "Link to Domain Model", "Creating domain model dictionary", 0
addToClassDictionary domainModelPackage.PackageGUID, dictionary

Based on this dictionary we can create one large Regular Expression that will tell us which of the terms in the dictionary are used in a certain text.

1
2
3
4
5
6
7
8
9
' and prepare the regex object
dim pattern
'create the pattern based on the names in the dictionary
pattern = createRegexPattern(dictionary)
Dim regExp 
Set regExp = CreateObject("VBScript.RegExp")
regExp.Global = True  
regExp.IgnoreCase = False
regExp.Pattern = pattern

Then we check what is selected in the project browser. If the user has selected one or more elements we start process those elements. If a package is selected then we process the elements in the selected package.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
' Get the type of element selected in the Project Browser
dim treeSelectedType
treeSelectedType = Repository.GetTreeSelectedItemType()
' Either process the selected Element, or process all elements in the selected package
select case treeSelectedType
    case otElement
        ' Code for when an element is selected
        dim selectedElements as EA.Collection
        set selectedElements = Repository.GetTreeSelectedElements()
        'link the selected elements with the
        linkDomainClassesWithElements dictionary,regExp,selectedElements
    case otPackage
        ' Code for when a package is selected
        dim selectedPackage as EA.Package
        set selectedpackage = Repository.GetTreeSelectedObject()
        'link use domain classes with the elements in the selected package
        linkDomainClassesWithElementsInPackage dictionary, regExp,selectedPackage
    case else
        ' Error message
        Session.Prompt "You have to select Elements or a Package", promptOK
end select

Here’s the complete code for the script.

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
option explicit
 
!INC Local Scripts.EAConstants-VBScript
 
'
' Script Name: Link to Domain Model
' Author: Geert Bellekens
' Purpose: Link elements with classes in the domain model based on their name.
' Date: 15/11/2015
'
 
 
sub main
    'let the user select the domain model package
    dim response
    response = Msgbox ("Please select the domain model package", vbOKCancel+vbQuestion, "Selecte domain model")
    if response = vbOK then
         
        dim domainModelPackage as EA.Package
        set domainModelPackage = selectPackage()
        if not domainModelPackage is nothing then
            Repository.CreateOutputTab "Link to Domain Model"
            Repository.ClearOutput "Link to Domain Model"
            Repository.EnsureOutputVisible "Link to Domain Model"
            'link selected elements to the domain model elements
            linkSelectionToDomainModel(domainModelPackage)
            'tell the user we are done
            Repository.WriteOutput "Link to Domain Model", "Finished!", 0
        end if
    end if
end sub
 
'this is the actual call to the main function
main
 
function linkSelectionToDomainModel(domainModelPackage)
    'first get the pattern from all the classes in the domain model
    dim dictionary
    Set dictionary = CreateObject("Scripting.Dictionary")
     
    'create domain model dictionary
    'tell the user what we are doing
    Repository.WriteOutput "Link to Domain Model", "Creating domain model dictionary", 0
    addToClassDictionary domainModelPackage.PackageGUID, dictionary
     
    'tell the user what we are doing
    Repository.WriteOutput "Link to Domain Model", "Interpreting dictionary", 0
    ' and prepare the regex object
    dim pattern
    'create the pattern based on the names in the dictionary
    pattern = createRegexPattern(dictionary)
    Dim regExp 
    Set regExp = CreateObject("VBScript.RegExp")
    regExp.Global = True  
    regExp.IgnoreCase = False
    regExp.Pattern = pattern
     
    ' Get the type of element selected in the Project Browser
    dim treeSelectedType
    treeSelectedType = Repository.GetTreeSelectedItemType()
    ' Either process the selected Element, or process all elements in the selected package
    select case treeSelectedType
        case otElement
            ' Code for when an element is selected
            dim selectedElements as EA.Collection
            set selectedElements = Repository.GetTreeSelectedElements()
            'link the selected elements with the
            linkDomainClassesWithElements dictionary,regExp,selectedElements
        case otPackage
            ' Code for when a package is selected
            dim selectedPackage as EA.Package
            set selectedpackage = Repository.GetTreeSelectedObject()
            'link use domain classes with the elements in the selected package
            linkDomainClassesWithElementsInPackage dictionary, regExp,selectedPackage
        case else
            ' Error message
            Session.Prompt "You have to select Elements or a Package", promptOK
    end select
end function
 
'this function will get all elements in the given package and subpackages recursively and link them to the domain classes
function linkDomainClassesWithElementsInPackage(dictionary,regExp,selectedPackage)
    dim packageList
    set packageList = getPackageTree(selectedPackage)
    dim packageIDString
    packageIDString = makePackageIDString(packageList)
    dim getElementsSQL
    getElementsSQL = "select o.Object_ID from t_object o where o.Package_ID in (" & packageIDString & ")"
    dim usecases
    set usecases = getElementsFromQuery(getElementsSQL)
    linkDomainClassesWithElements dictionary,regExp,usecases
end function
 
 
function linkDomainClassesWithElements(dictionary,regExp,elements)
    dim element as EA.Element
    'loop de elements
    for each element in elements
        'tell the user what we are doing
        Repository.WriteOutput "Link to Domain Model", "Linking element: " & element.Name, 0
        'first remove all automatic traces
        removeAllAutomaticTraces element
        'match based on notes and linked document
        dim elementText
        'get full text (name +notes + linked document + scenario names + scenario notes)
        elementText = element.Name
        elementText = elementText & vbNewLine & Repository.GetFormatFromField("TXT",element.Notes)
        elementText = elementText & vbNewLine & getLinkedDocumentContent(element, "TXT")
        elementText = elementText & vbNewLine & getTextFromScenarios(element)
        dim matches
        set matches = regExp.Execute(elementText)
        'for each match create a «trace» link with the element
        linkMatchesWithelement matches, element, dictionary
        'link based on text in scenariosteps
        dim scenario as EA.Scenario
        'get all dependencies left
        dim dependencies
        set dependencies = getDependencies(element)
        'loop scenarios
        for each scenario in element.Scenarios
            dim scenarioStep as EA.ScenarioStep
            for each scenarioStep in scenario.Steps
                'first remove any additional terms in the uses field
                scenarioStep.Uses = removeAddionalUses(dependencies, scenarioStep.Uses)
                set matches = regExp.Execute(scenarioStep.Name)
                dim classesToMatch
                set classesToMatch = getClassesToMatchDictionary(matches, dictionary)
                dim classToMatch as EA.Element
                for each classToMatch in classesToMatch.Items
                    if not instr(scenarioStep.Uses,classToMatch.Name) > 0 then
                        scenarioStep.Uses = scenarioStep.Uses & " " & classToMatch.Name
                    end if
                    'create the dependency between the use case and the domain model class
                    linkElementsWithAutomaticTrace element, classToMatch
                next
                'save scenario step
                scenarioStep.Update
                scenario.Update
            next
        next
    next
end function
 
function linkMatchesWithelement(matches, element, dictionary)
    dim classesToMatch
    'get the classes to match
    Set classesToMatch = getClassesToMatchDictionary(matches,dictionary)
    dim classToMatch as EA.Element
    'actually link the classes
    for each classToMatch in classesToMatch.Items
        linkElementsWithAutomaticTrace element, classToMatch
    next
end function
 
 
'get the text from the scenarios name and notes
function getTextFromScenarios(element)
    dim scenario as EA.Scenario
    dim scenarioText
    scenarioText = ""
    for each scenario in element.Scenarios
        scenarioText = scenarioText & vbNewLine & scenario.Name
        scenarioText = scenarioText & vbNewLine & Repository.GetFormatFromField("TXT",scenario.Notes)
    next
    getTextFromScenarios = scenarioText
end function
 
function removeAddionalUses(dependencies, uses)
    dim dependency
    dim filteredUses
    filteredUses = ""
    if len(uses) > 0 then
        for each dependency in dependencies.Keys
            if Instr(uses,dependency) > 0 then
                if len(filteredUses) > 0 then
                    filteredUses = filteredUses & " " & dependency
                else
                    filteredUses = dependency
                end if
            end if
        next
    end if
    removeAddionalUses = filteredUses
end function
 
'returns a dictionary of elements with the name as key and the element as value.
function getDependencies(element)
    dim getDependencySQL
    getDependencySQL =  "select dep.Object_ID from ( t_object dep " & _
                        " inner join t_connector con on con.End_Object_ID = dep.Object_ID)   " & _
                        " where con.Connector_Type = 'Dependency'  " & _
                        " and con.Start_Object_ID = " & element.ElementID  
    set getDependencies = getElementDictionaryFromQuery(getDependencySQL)
end function
 
function removeAllAutomaticTraces(element)
        dim i
        dim connector as EA.Connector
        'remove all the traces to domain model classes
        for i = element.Connectors.Count -1 to 0 step -1
            set connector = element.Connectors.GetAt(i)
            if connector.Alias = "automatic" and connector.Stereotype = "trace" then
                element.Connectors.DeleteAt i,false
            end if
        next
end function
 
function getClassesToMatchDictionary(matches, allClassesDictionary)
    dim match
    dim classesToMatch
    dim className
    Set classesToMatch = CreateObject("Scripting.Dictionary")
    'create list of elements to link
    For each match in matches
        if not allClassesDictionary.Exists(match.Value) then
            'strip the last 's'
            className = left(match.Value, len(match.Value) -1)
        else
            className = match.Value
        end if
        if not classesToMatch.Exists(className) then
            classesToMatch.Add className, allClassesDictionary(className)
        end if
    next
    set getClassesToMatchDictionary = classesToMatch
end function
 
'Create a «trace» relation between source and target with "automatic" as alias
function linkElementsWithAutomaticTrace(sourceElement, targetElement)
    dim linkExists
    linkExists = false
    'first make sure there isn't already a trace relation between the two
    dim existingConnector as EA.Connector
    'make sure we are using the up-to-date connectors collection
    sourceElement.Connectors.Refresh
    for each existingConnector in sourceElement.Connectors
        if existingConnector.SupplierID = targetElement.ElementID _
           and existingConnector.Stereotype = "trace" then
           linkExists = true
           exit for
        end if
    next
    if not linkExists then
        'tell the user what we are doing
        Repository.WriteOutput "Link to Domain Model", "Adding trace between " &sourceElement.Name & " and " & targetElement.Name, 0
        dim trace as EA.Connector
        set trace = sourceElement.Connectors.AddNew("","trace")
        trace.Alias = "automatic"
        trace.SupplierID = targetElement.ElementID
        trace.Update
    end if
end function
 
function addToClassDictionary(PackageGUID, dictionary)
    dim package as EA.Package
    set package = Repository.GetPackageByGuid(PackageGUID)
     
    'get the classes in the dictionary (recursively
    addClassesToDictionary package, dictionary
end function
 
function addClassesToDictionary(package, dictionary)
    dim classElement as EA.Element
    dim subpackage as EA.Package
    'process owned elements
    for each classElement in package.Elements
        if classElement.Type = "Class" AND len(classElement.Name) > 0 AND not dictionary.Exists(classElement.Name) then
            dictionary.Add classElement.Name,  classElement
        end if
    next
    'process subpackages
    for each subpackage in package.Packages
        addClassesToDictionary subpackage, dictionary
    next
end function
 
 
'Create a reges pattern like this "\b(name1|name2|name3)\b" based on the
function createRegexPattern(dictionary)
    Dim patternString
    dim className
    'add begin
    patternString = "\b("
    dim addPipe
    addPipe = FALSE
    for each className in dictionary.Keys
            if addPipe then
                patternString = patternString & "|"
            else
                addPipe = True
            end if
            patternString = patternString & className
    next
    'add end
    patternString = patternString & ")s?\b"
    'return pattern
    createRegexPattern = patternString
end function
 
'returns an ArrayList of the given package and all its subpackages recursively
function getPackageTree(package)
    dim packageList
    set packageList = CreateObject("System.Collections.ArrayList")
    addPackagesToList package, packageList
    set getPackageTree = packageList
end function
 
'make an id string out of the package ID of the given packages
function makePackageIDString(packages)
    dim package as EA.Package
    dim idString
    idString = ""
    dim addComma
    addComma = false
    for each package in packages
        if addComma then
            idString = idString & ","
        else
            addComma = true
        end if
        idString = idString & package.PackageID
    next
    'if there are no packages then we return "0"
    if packages.Count = 0 then
        idString = "0"
    end if
    'return idString
    makePackageIDString = idString
end function
 
'returns an ArrayList with the elements accordin tot he ObjectID's in the given query
function getElementsFromQuery(sqlQuery)
    dim elements
    set elements = Repository.GetElementSet(sqlQuery,2)
    dim result
    set result = CreateObject("System.Collections.ArrayList")
    dim element
    for each element in elements
        result.Add Element
    next
    set getElementsFromQuery = result
end function
 
'returns a dictionary of all elements in the query with their name as key, and the element as value.
'for elements with the same name only one will be returned
function getElementDictionaryFromQuery(sqlQuery)
    dim elements
    set elements = Repository.GetElementSet(sqlQuery,2)
    dim result
    set result = CreateObject("Scripting.Dictionary")
    dim element
    for each element in elements
        if not result.Exists(element.Name) then
        result.Add element.Name, element
        end if
    next
    set getElementDictionaryFromQuery = result
end function
 
'gets the content of the linked document in the given format (TXT, RTF or EA)
function getLinkedDocumentContent(element, format)
    dim linkedDocumentRTF
    dim linkedDocumentEA
    dim linkedDocumentPlainText
    linkedDocumentRTF = element.GetLinkedDocument()
    if format = "RTF" then
        getLinkedDocumentContent = linkedDocumentRTF
    else
        linkedDocumentEA = Repository.GetFieldFromFormat("RTF",linkedDocumentRTF)
        if format = "EA" then
            getLinkedDocumentContent = linkedDocumentEA
        else
            linkedDocumentPlainText = Repository.GetFormatFromField("TXT",linkedDocumentEA)
            getLinkedDocumentContent = linkedDocumentPlainText
        end if
    end if
end function
 
'let the user select a package
function selectPackage()
    dim documentPackageElementID       
    documentPackageElementID = Repository.InvokeConstructPicker("IncludedTypes=Package")
    if documentPackageElementID > 0 then
        dim packageElement as EA.Element
        set packageElement = Repository.GetElementByID(documentPackageElementID)
        dim package as EA.Package
        set package = Repository.GetPackageByGuid(packageElement.ElementGUID)
    else
        set package = nothing
    end if
    set selectPackage = package
end function
 
'add the given package and all subPackges to the list (recursively
function addPackagesToList(package, packageList)
    dim subPackage as EA.Package
    'add the package itself
    packageList.Add package
    'add subpackages
    for each subPackage in package.Packages
        addPackagesToList subPackage, packageList
    next
end function

This article was originally published on Bellekens.com

Published in Community Resources

With this script you can change set all the lines styles on a diagram at once, to your preferred style per type of connector.

In Enterprise Architect you can choose from no less then 9 different line styles for the connectors.

Line Styles

Unfortunately you can only choose from the first three to be the default line style for new connectors. Additionally you can also specify the default for Generalization to be Tree Style, but that is it.

For me that is not enough. I have my own habits when making UML diagrams. For most connector types I use Orthogonal – Square, but not for dependencies, use case relations and note links. For those I like theDirect style. The last exception are the control flow, state flow and object flows, for which I use Orthogonal – Rounded.

LineStylesDiagram

With this script I can set all the line styles on a diagram to the styles that I like.  All I need to do is right click on a diagram and choose Scripts|Set Line Styles

Set Linestyles menu option

And the script will set all the line styles to the defaults set in the script. If you would like the line styles to be set to your preferences automatically without having to run the script you can use EA-Matic version of this script.

You can set your own preferences in this section of the script

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
'*********EDIT BETWEEN HERE*************
 
' set here the default style to be used
defaultStyle = lsOrthogonalSquareTree
 
' set there the style to be used for each type of connector
function determineStyle(connector)
    dim connectorType
    connectorType = connector.Type
    select case connectorType
        case "ControlFlow", "StateFlow","ObjectFlow","InformationFlow"
            determineStyle = lsOrthogonalRoundedTree
        case "Generalization", "Realization", "Realisation"
            determineStyle = lsTreeVerticalTree
        case "UseCase", "Dependency","NoteLink"
            determineStyle = lsDirectMode
        case else
            determineStyle = defaultStyle
    end select
end function
'************AND HERE****************

Free download

Default Line Styles Script
Default Line Styles Script
€0.00
Download 

Video

This script has been previously featured in the webinar Introduction to Scripting with Enterprise Architect presented by yours truly.

The script

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
option explicit
 
!INC Local Scripts.EAConstants-VBScript
 
' Script Name: DefaultLineStyles
' Author: Geert Bellekens
' Purpose: Allows to change the linestyles to their default
' Date: 27/04/2015
'
dim lsDirectMode, lsAutoRouteMode, lsCustomMode, lsTreeVerticalTree, lsTreeHorizontalTree, _
lsLateralHorizontalTree, lsLateralVerticalTree, lsOrthogonalSquareTree, lsOrthogonalRoundedTree
 
lsDirectMode = "1"
lsAutoRouteMode = "2"
lsCustomMode = "3"
lsTreeVerticalTree = "V"
lsTreeHorizontalTree = "H"
lsLateralHorizontalTree = "LH"
lsLateralVerticalTree = "LC"
lsOrthogonalSquareTree = "OS"
lsOrthogonalRoundedTree = "OR"
 
dim defaultStyle
dim menuDefaultLines
 
 
'*********EDIT BETWEEN HERE*************
 
 
' set here the default style to be used
defaultStyle = lsOrthogonalSquareTree
 
' set there the style to be used for each type of connector
function determineStyle(connector)
    dim connectorType
    connectorType = connector.Type
    select case connectorType
        case "StateFlow","ObjectFlow","InformationFlow"
            determineStyle = lsOrthogonalRoundedTree
        case "Generalization", "Realization", "Realisation"
            determineStyle = lsTreeVerticalTree
        case "UseCase", "Dependency","NoteLink"
            determineStyle = lsDirectMode
        case else
            determineStyle = defaultStyle
    end select
end function
'************AND HERE****************
 
 
sub main
        dim diagram
        dim diagramLink
        dim connector
        dim dirty
        dirty = false
        set diagram = Repository.GetCurrentDiagram
        'save the diagram first
        Repository.SaveDiagram diagram.DiagramID
        'then loop all diagramLinks
        if not diagram is nothing then
            for each diagramLink in diagram.DiagramLinks
                set connector = Repository.GetConnectorByID(diagramLink.ConnectorID)
                if not connector is nothing then
                    'set the connectorstyle
                    setConnectorStyle diagramLink, determineStyle(connector)
                    'save the diagramlink
                    diagramLink.Update
                    dirty = true
                end if
            next
            'reload the diagram if we changed something
            if dirty then
                'reload the diagram to show the link style
                Repository.ReloadDiagram diagram.DiagramID
            end if
        end if
end sub
 
main
 
 
'gets the diagram link object
function getdiagramLinkForConnector(connector, diagram)
    dim diagramLink
    set getdiagramLinkForConnector = nothing
    for each diagramLink in diagram.DiagramLinks
        if diagramLink.ConnectorID = connector.ConnectorID then
            set getdiagramLinkForConnector = diagramLink
            exit for
        end if
    next
end function
 
'actually sets the connector style
function setConnectorStyle(diagramLink, connectorStyle)
    'split the style into its parts
    dim styleparts
    dim styleString
    styleString = diagramLink.Style
    styleparts = Split(styleString,";")
    dim stylePart
    dim mode
    dim modeIndex
    modeIndex = -1
    dim tree
    dim treeIndex
    treeIndex = -1
    mode = ""
    tree = ""
    dim i
    'find if Mode and Tree are already defined
    for i = 0 to Ubound(styleparts) -1
        stylePart = styleparts(i)
        if Instr(stylepart,"Mode=") > 0 then
            modeIndex = i
        elseif Instr(stylepart,"TREE=") > 0 then
            treeIndex = i
        end if
    next
    'these connectorstyles use mode=3 and the tree
    if  connectorStyle = lsTreeVerticalTree or _
        connectorStyle = lsTreeHorizontalTree or _
        connectorStyle = lsLateralHorizontalTree or _
        connectorStyle = lsLateralVerticalTree or _
        connectorStyle = lsOrthogonalSquareTree or _
        connectorStyle = lsOrthogonalRoundedTree then
        mode = "3"
        tree = connectorStyle
    else
        mode = connectorStyle
    end if
    'set the mode value
    if modeIndex >= 0 then
        styleparts(modeIndex) = "Mode=" & mode
        diagramLink.Style = join(styleparts,";")
    else
        diagramLink.Style = "Mode=" & mode& ";"& diagramLink.Style
    end if
    'set the tree value
    if treeIndex >= 0 then
        if len(tree) > 0 then
            styleparts(treeIndex) = "TREE=" & tree
            diagramLink.Style = join(styleparts,";")
        else
            'remove tree part
            diagramLink.Style = replace(diagramLink.Style,styleparts(treeIndex)&";" , "")
        end if
    else
        diagramLink.Style = diagramLink.Style & "TREE=" & tree & ";"
    end if
end function
 
function getConnectorStyle(diagramLink)
    'split the style
    dim styleparts
    styleparts = Split(diagramLink.Style,";")
    dim stylePart
    dim mode
    dim tree
    mode = ""
    tree = ""
    for each stylepart in styleparts
        if Instr(stylepart,"Mode=") > 0 then
            mode = right(stylepart, 1)
        elseif Instr(stylepart,"TREE=") > 0 then
            tree = replace(stylepart, "TREE=", "")
        end if
    next
    if tree <> "" then
        getConnectorStyle = tree
    else
        getConnectorStyle = mode
    end if
end function

This article was originally published on Bellekens.com

Published in Community Resources
Tagged under
Saturday, 31 January 2015 07:59

EA-Matic a new add-in by Geert Bellekens

EA-Matic

EA-MaticLogo64

EA-Matic is an add-in for Sparx Enterprise Architect that enables rapid EA add-in development.

It uses the built-in scripting features of EA to relieve you of developing, building and deploying full-blown EA add-ins.
Aimed at corporate environments it greatly reduces the time to introduce new functionality.

With EA-Matic you can develop your EA add-in using nothing but EA, and deploy changes instantly to all model users.

The possibilities are endless. You can validate your own modelling rules, keep your model consistent by preventing the deletion of elements that are still used, add your own context menus, or make self-maintaining diagrams. The only limits are those of your imagination.

The table below shows how add-in development with EA-Matic differs from classic add-in development.

  EA-Matic Classic add-in development
Required tools Only EA Visual Studio, Sharpdevelop, or equivalent IDE
Installation of a new version Instantly available for all users without the need to install anything again on the workstations. Msi-deployment on all workstations
Languages VBScript, JScript, JavaScript VB, C#
Security access on development machine Normal user rights are enough. Local Administrator rights required.

Try and buy

Download EA-Matic and try it for free for 30 days   Buy EA-Matic from EAWorkplace

Download EA-Matic and try it for free for 30 days.

The evaluation version can be activated as full licensed version by entering a valid license key. No need to download and install another version.

EA-Matic is distributed through EAWorkplace. You should be registered and logged in to EAWorkplace in order to download or purchase.

Quantity Per seat Floating
1 – 4 € 50 € 70
5 – 19 € 46 € 63
20 – 100 € 42 € 60
100 + € 39 € 56

 

EA-Matic should be installed on all workstations that use EA, so you should have the same number of EA-Matic licenses as you have EA licenses.

Prerequisites

Examples

Usage

This one minute video will show how easy it is to create a new add-in for EA using EA-Matic

 
 

More info
 

More information can can be found on the authors website: http://bellekens.com/ea-matic/

 

Published in News

Early this month, I published a script to sort elements from a selected package by the alias name. This article provides another project browser script that finds and selects the classifier for an instance or a class attribute, or the property type for a SysML port or part.

Sparx Enterprise Architect makes it possible to find from a diagram an instance classifier with a right click > Find > Locate Classifier in Project Browser, or a SysML port/part's classifier with a right click > Find > Locate Property Type in Project Browser. 

 

As there isn't any similar feature from the project browser, I wrote a script to achieve it, whilst extending it to a class attribute.

Enterprise Architect Project Browser scripts

Enterprise Architect lets you create project browser scripts. Once created in your project, these are available via a right click on a selected package from the browser, as illustrated below:

sparx enterprise architect project browser find-classifier-for-instance-port-part-attribute

 

Find the classifier of an instance, port, part, or attribute with FindClassifier project browser script

To add the FindClassifier Project Browser script to your modelling project:

Step 1: open the scripting view using the Enterprise Architect menu Tools > Scripting.

Step 2: click on "New Project Browser Group" to store all user-defined scripts, e.g. Project Browser scripts.

Step 3: click on "New script > New VBScript" to define the "Find Classifier" script, e.g. FindClassifier.

sparx enterprise architect project browser script findclassifier

Step 4: open the script and copy/paste the content from the following file: download FindClassifier VBScript text file

Step 5: save the script (Ctrl-S).

Step 6: test the FindClassifier script with a right click on a selected object from the Project Browser to find its classifier, and select Scripts > FindClassifier

Result: the instance's class has been selected from the Project Browser as illustrated below.

sparx-enterprise-architect-project_browser_script_sortbyalias_running result

Here is another example of using this script with a class attribute:

sparx-enterprise-architect-project_browser_script_sortbyalias_running result

 

Published in Tutorials
Tagged under