Sparx Systems Forum
Enterprise Architect => General Board => Topic started by: salayande on December 26, 2009, 11:48:21 pm
-
Dear all,
I could not get my transformation scripts to do simple tasks in EA so I decided to learn the VBScript in EA.
To learn scripting in VBScript, I created a package with two classes with stereotypes set to the "Boy Soldiers".
I then wrote the script below to change the stereotype values to "BusinessEntity" but when I ran the script, nothing happened. Could anyone suggest what I may do to improve the script. Thank you in anticipation.
Option explicit
'
' The purpose of this script is to change the stereotype of all elements
' in a selected Package from current value to "BusinessEntity".
'
sub ChangeElementStereotype()
dim thePackage as EA.Package
set thePackage = Repository.GetTreeSelectedPackage()
if not thePackage is nothing and thePackage.ParentID <> 0 then
dim i
Session.Output( "Changing the elements' stereotype" )
'get elements
dim elements as EA.Collection
dim currentElement as EA.Element
set elements = thePackage.Elements
for i = 0 to elements.Count - 1
'get each element
set currentElement = elements.GetAt(i)
set currentElement.Stereotype = "BusinessEntity"
'update element stereotype
currentElement.Update()
Next
'refresh elements
elements.Refresh()
'report element updated
Session.Output( "Done!" )
else
' No package selected in the tree
MsgBox( "This script requires a package to be selected" )
end if
End sub
-
Hello,
Please add the following line before the currentElement.Update():
set currentElement.StereotypeEx = "BusinessEntity"
I think you need to set both the Stereotype and StereotypeEx.
Hope this helps,
-
Thank you for your quick response, T-kouno, and especially over the Xmas break.
I inserted the line as advised but nothing happened. The updated script now looks like this:
Option explicit
sub ChangeElementStereotype()
dim thePackage as EA.Package
set thePackage = Repository.GetTreeSelectedPackage()
if not thePackage is nothing and thePackage.ParentID <> 0 then
dim i
Session.Output( "Working on package ")
'get elements
dim elements as EA.Collection
dim currentElement as EA.Element
set elements = thePackage.Elements
for i = 0 to elements.Count - 1
'get each element
set currentElement = elements.GetAt(i)
set currentElement.Stereotype ="BusinessEntity"
set currentElement.StereotypeEx = "BusinessEntity"
'update element stereotype
currentElement.Update
Next
'refresh elements
elements.Refresh()
'report element updated
Session.Output( "Done!" )
else
' No package selected in the tree
MsgBox( "This script requires a package to be selected in the Project Browser.")
end if
End sub
Again, thank you for your help.
Segun
-
I have removed unnecessary lines and now it seems to work fine.
My code is:
--------------
sub ChangeElementStereotype()
dim thePackage
set thePackage = Repository.GetTreeSelectedPackage()
dim i
'get elements
dim elements
dim currentElement
set elements = thePackage.Elements
for i = 0 to elements.Count - 1
'get each element
set currentElement = elements.GetAt(i)
currentElement.Stereotype ="BusinessEntity"
currentElement.StereotypeEx = "BusinessEntity"
'update element stereotype
currentElement.Update
Next
End sub
ChangeElementStereotype
--------------
Please copy the above script and paste it as EA's script (of VBScript).
My EA is 7.5.850.
Hope this helps.
-
Many thanks to you, T-kouno
regards
Segun