Sparx Systems Forum
Enterprise Architect => Automation Interface, Add-Ins and Tools => Topic started by: sousac on November 05, 2019, 01:05:34 pm
-
I have written a script that creates a collection of child Archimate elements (nested) for the selected element, complete with tagged values, as well as relationships. The script performs as designed without any issues.
<Existing Element>
3 x New Child Element (with tagged values and a relationship to its parent)
6 x Sub-Child Elements for each (with tagged values and relationship to its parent)
Performance
On a local EAPX, the scrip runs in about 5 seconds or less (what I would expect). Over a wide area network to a repository via cloud connection, the same script takes about a minute to run (a factor of 12x slower).
The slowness seems to be due to the number of addNew and Update methods I am calling in the script (one can literally observe the items being created in the project browser at a snails pace).
General question, is there any general strategy to observe to limit the number of "save trips" back to the repository when creating a structure like the one depicted (ie., similar to the concept of a commit wrapper....create a bunch of data....commit once?)
-
If you post your code where we could try to say something useful about it.
Right now it's just a guessing game.
Geert
-
Thanks Geert,
The code creates a collection of elements and child elements on the object that was used as context. Tagged values are also required on the child elements. A composition connector, in addition to nesting is also required.
Capability
Current State Assessment
Tech Assessment
Process Assessment
etc.
Target State
Tech Assessment
Process Assessment
etc.
sub OnProjectBrowserScript()
' Get the type of element selected in the Project Browser
dim treeSelectedType
treeSelectedType = Repository.GetTreeSelectedItemType()
select case treeSelectedType
case otElement
' Code for when an element is selected
dim theCapability as EA.Element
set theCapability = Repository.GetTreeSelectedObject()
dim AssessmentName
If theCapability.Stereotype = "ArchiMate_Capability" then
AssessmentName = InputBox( "Entrez un nom pour la nouvelle évaluation.", "Create Assessment", "évaluation année 9999")
Call CreateAssessmentStructure(theCapability, AssessmentName)
else
Session.Prompt "Sélectionnez un élément de capacité pour exécuter ce script.", promptOK
end if
case else
' Error message
Session.Prompt "Sélectionnez un élément de capacité pour exécuter ce script.", promptOK
end select
end sub
' Creates an assessment structure
Sub CreateAssessmentStructure(capabilityElement, AssessmentName)
Dim CapabilityElements as EA.Collection
Dim newAssessment as EA.Element
Dim NewAssessmentElements as EA.Collection
Dim tecAssessment as EA.Element
Dim infAssessment as EA.Element
Dim prcAssessment as EA.Element
Dim savAssessment as EA.Element
Dim orgAssessment as EA.Element
Dim matAssessment as EA.Element
set CapabilityElements = capabilityElement.Elements
set newAssessment = CapabilityElements.AddNew(AssessmentName,"Class")
newAssessment.Stereotype = "Archimate3::ArchiMate_Assessment"
newAssessment.Update
' Add composition Relationship to the parent element
Call AddArchimateComposition(capabilityElement,newAssessment)
Set NewAssessmentElements = newAssessment.Elements
Set tecAssessment = NewAssessmentElements.AddNew("TEC","Class")
Set infAssessment = NewAssessmentElements.AddNew("INF","Class")
Set prcAssessment = NewAssessmentElements.AddNew("PRC","Class")
Set savAssessment = NewAssessmentElements.AddNew("SAV","Class")
Set orgAssessment = NewAssessmentElements.AddNew("ORG","Class")
Set matAssessment = NewAssessmentElements.AddNew("MAT","Class")
tecAssessment.Stereotype = "Archimate3::ArchiMate_Assessment"
infAssessment.Stereotype = "Archimate3::ArchiMate_Assessment"
prcAssessment.Stereotype = "Archimate3::ArchiMate_Assessment"
savAssessment.Stereotype = "Archimate3::ArchiMate_Assessment"
orgAssessment.Stereotype = "Archimate3::ArchiMate_Assessment"
matAssessment.Stereotype = "Archimate3::ArchiMate_Assessment"
tecAssessment.Update
infAssessment.Update
prcAssessment.Update
savAssessment.Update
orgAssessment.Update
matAssessment.Update
Call AddTag(newAssessment,"Capability Assessment")
Call AddTag(tecAssessment,"Capability Assessment")
Call AddTag(infAssessment,"Capability Assessment")
Call AddTag(prcAssessment,"Capability Assessment")
Call AddTag(savAssessment,"Capability Assessment")
Call AddTag(orgAssessment,"Capability Assessment")
Call AddTag(matAssessment,"Capability Assessment")
Call AddArchimateComposition(newAssessment,tecAssessment)
Call AddArchimateComposition(newAssessment,infAssessment)
Call AddArchimateComposition(newAssessment,prcAssessment)
Call AddArchimateComposition(newAssessment,savAssessment)
Call AddArchimateComposition(newAssessment,orgAssessment)
Call AddArchimateComposition(newAssessment,matAssessment)
End Sub
' Adds a relationship of a specific type and stereotype
Sub AddArchimateComposition( Source, Target )
dim Conn as EA.Connector
dim ClientEnd as EA.ConnectorEnd
' ClientID = source end, SupplierID = target end
' source end is already set based on the element that owns the Connectors collection. Only need to set SupplierID.
set conn = Source.Connectors.AddNew("", "Association")
Conn.StereoType = "Archimate3::ArchiMate_Composition"
Conn.SupplierID = target.ElementID
Conn.Update
' Establish the aggregation on the client End as Composite
set ClientEnd = Conn.ClientEnd
ClientEnd.Aggregation = 2
ClientEnd.Update
Source.Connectors.Refresh
Target.Connectors.Refresh
end sub
' Adds a tagged value to an element
sub AddTag(theElement, TagName)
Dim ElementTags as EA.Collection
Dim newTag as EA.TaggedValue
set ElementTags = theElement.TaggedValues
set newTag = ElementTags.AddNew(TagName,"")
newTag.Update
end sub
OnProjectBrowserScript
-
On my model (Local SQL Server) it runs in about a second.
The only thing I see you don't need is this:
Source.Connectors.Refresh
Target.Connectors.Refresh
Other than that the code is just fine from from a performance point of view.
What I usually propose is to use remote desktop or citrix for using EA over a WAN.
This keeps the database connection local, and the overal performance just fine, even when connecting via 3G hotspot or something similar.
Geert
-
Appreciate the insight as always Geert.
Cheers.
PS - I also noticed a flaw in my script for the tagged values that is only noticeable when using the auto color legend against the tag. If I allow the script to simply add the tag without a value and permit the tagged value definition to assign its default value, the value isn't visible to the legend until it is changed via the UI (initialization issue it seems). I altered the script to explicitly set the default value for the tag and this corrected the problem.