-
Notifications
You must be signed in to change notification settings - Fork 5
/
nameDesignation.vbs
294 lines (191 loc) · 7.91 KB
/
nameDesignation.vbs
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
option explicit
!INC Local Scripts.EAConstants-VBScript
'
' This code has been included from the default Project Browser template.
' If you wish to modify this template, it is located in the Config\Script Templates
' directory of your EA install path.
'
' Script Name: transelateDesignationName
' Author: Sara Henriksen
' Purpose: Bytter modellelementnavn med designation tags, for engelsk og norsk (kan utvides med språk)
' Date: 19.08.16
'
'
' Project Browser Script main function
'
sub OnProjectBrowserScript()
' Get the type of element selected in the Project Browser
dim treeSelectedType
treeSelectedType = Repository.GetTreeSelectedItemType()
' Handling Code: Uncomment any types you wish this script to support
' NOTE: You can toggle comments on multiple lines that are currently
' selected with [CTRL]+[SHIFT]+[C].
select case treeSelectedType
' case otElement
' ' Code for when an element is selected
' dim theElement as EA.Element
' set theElement = Repository.GetTreeSelectedObject()
'
case otPackage
' ' Code for when a package is selected
dim thePackage as EA.Package
set thePackage = Repository.GetTreeSelectedObject()
'if UCase(thePackage.element.stereotype) = UCase("applicationSchema") then
'sjekker om pakken har en language tag, det må den ha for å oversette elementnavnene.
dim languageTag AS EA.TaggedValue
dim taggedCounter
dim languageTagExisit
languageTagExisit = false
for taggedCounter = 0 to thePackage.Element.TaggedValues.Count - 1
set languageTag = thePackage.Element.TaggedValues.GetAt(taggedCounter)
if languageTag.Name = "language" then
languageTagExisit = true
call findDesignation(thePackage)
end if
next
if not languageTagExisit = true then
Msgbox "Error: Package [" &thePackage.Name& "] is missing a language-tag"
end if
' case otDiagram
' ' Code for when a diagram is selected
' dim theDiagram as EA.Diagram
' set theDiagram = Repository.GetTreeSelectedObject()
'
' case otAttribute
' ' Code for when an attribute is selected
' dim theAttribute as EA.Attribute
' set theAttribute = Repository.GetTreeSelectedObject()
'
' case otMethod
' ' Code for when a method is selected
' dim theMethod as EA.Method
' set theMethod = Repository.GetTreeSelectedObject()
case else
' Error message
Session.Prompt "This script does not support items of this type.", promptOK
end select
end sub
' finner language tagen og lager en variabel som består av verdien til taggen, som skal brukes senere i skriptet.
dim thePackage as EA.Package
set thePackage = Repository.GetTreeSelectedObject()
dim languageTag AS EA.TaggedValue
dim taggedCounter
dim languageTagExisit
languageTagExisit = false
for taggedCounter = 0 to thePackage.Element.TaggedValues.Count - 1
set languageTag = thePackage.Element.TaggedValues.GetAt(taggedCounter)
if languageTag.Name = "language" then
languageTagExisit = true
dim TVlanguageValue
TVlanguageValue = languageTag.Value
end if
next
sub transelation(theElement, taggedValueName)
'Session.Output("theElement: " &theElement.Name)
dim newTaggedValueName as EA.TaggedValue
set newTaggedValueName = nothing
dim newElementName as EA.Element.Name
set newElementName = nothing
dim newLanguageTag as EA.TaggedValue
set newLanguageTag = nothing
if not theElement is nothing and Len(taggedValueName) > 0 then
dim designationTagExist
designationTagExist = false
dim designationValueMissing
designationValueMissing = false
'check if the element has a tagged value with the provided name
dim currentExistingTaggedValue AS EA.TaggedValue
dim taggedValuesCounter
for taggedValuesCounter = 0 to theElement.TaggedValues.Count - 1
set currentExistingTaggedValue = theElement.TaggedValues.GetAt(taggedValuesCounter)
dim currentValue
currentValue = currentExistingTaggedValue.Value
if currentExistingTaggedValue.Name = taggedValueName then
designationTagExist = true
if not currentExistingTaggedValue.Value = "" then
'Session.Output( " Funnet tag med navn [" & taggedValueName & "] og verdi: " & currentValue & "")
'lag ny designation tag
set newTaggedValueName = theElement.TaggedValues.AddNew("designation", """"&theElement.Name&""""&"@"&TVlanguageValue)
newTaggedValueName.Update()
'fjern "" og landcode på taggen
dim start, slutt
Start = InStr( currentExistingTaggedValue.Value, """" )
slutt = len(currentExistingTaggedValue.Value)- InStr( StrReverse(currentExistingTaggedValue.Value), """" ) -1
'oppdater navnet til elementet, uten "" og @landcode
theElement.Name = Mid(currentExistingTaggedValue.Value,start+1,slutt)
theElement.Update()
'slett gammel designation tag
theElement.TaggedValues.DeleteAt taggedValuesCounter, TRUE
end if
if currentExistingTaggedValue.Value = "" then
designationValueMissing = true
end if
end if
next
'hvis designation tagen ikke finnes, gir advarsel og gjør ingenting med navnet.
if designationTagExist = false then
Session.Output("the element [" &theElement.Name& "] mangler designation tag")
end if
'hvis designation taggen har tom verdi, gir advarsel og gjør ingenting med navnet.
if designationValueMissing = true then
Session.Output("the element [" &theElement.Name& "] mangler designation verdi")
end if
end if
end sub
sub findDesignation(package)
Session.Output("The current package is: " & package.Name)
dim elements as EA.Collection
set elements = package.Elements 'collection of elements that belong to this package (classes, notes... BUT NO packages)
dim packages as EA.Collection
set packages = package.Packages 'collection of packages that belong to this package
' Navigate the package collection and call the FindTagValuesDesignationWithBlank function for each of them
dim p
for p = 0 to packages.Count - 1
dim currentPackage as EA.Package
set currentPackage = packages.GetAt( p ) 'getAT
findDesignation(currentPackage) 'går igjennom pakken for å lete etter underpakker
next
' Navigate the elements collection
dim i
for i = 0 to elements.Count - 1
dim currentElement as EA.Element
set currentElement = elements.GetAt( i )
'Is the currentElement of type Class? If so, continue checking tags and it's attributes' tags.
if currentElement.Type = "Class" then
Call transelation( currentElement, "designation")
dim attributesCollection as EA.Collection
set attributesCollection = currentElement.Attributes
if attributesCollection.Count > 0 then
dim n
for n = 0 to attributesCollection.Count - 1
dim currentAttribute as EA.Attribute
set currentAttribute = attributesCollection.GetAt(n)
'Call TVRemoveBlank(currentAttribute, "designation")
Call transelation( currentAttribute, "designation")
next
end if
end if
next
dim languageTag AS EA.TaggedValue
dim taggedCounter
dim languageTagExisit
languageTagExisit = false
'oppdater language taggen på pakken etter den har byttet språk
for taggedCounter = 0 to package.Element.TaggedValues.Count - 1
set languageTag = package.Element.TaggedValues.GetAt(taggedCounter)
if languageTag.Name = "language" then
if languageTag.Value = "no" then
languageTag.Value = "en"
languageTag.Update()
exit for
end if
if languageTag.Value = "en" then
languageTag.Value = "no"
languageTag.Update()
exit for
end if
end if
next
end sub
'Call the main function
OnProjectBrowserScript