Book a Demo

Author Topic: Change multiple connectors' type  (Read 4925 times)

Evandro

  • EA Novice
  • *
  • Posts: 19
  • Karma: +0/-0
    • View Profile
Change multiple connectors' type
« on: May 04, 2018, 01:19:14 am »
Hi there,
in a Class Diagram I've got +100 connectors I need to change.
EA User's Guide suggests me the following: Diagram>Right-click on Connector>Advanced>Change Type.
Any suggestion how to avoid doing this one by one?

Thanks

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Change multiple connectors' type
« Reply #1 on: May 04, 2018, 06:34:15 am »
You need to write a little script that goes through all connectors. EA does not allow to change multiple connectors in one go via the GUI.

q.

Nizam

  • Prolab Moderator
  • EA User
  • *
  • Posts: 320
  • Karma: +15/-2
  • Model Sharing - Simplified
    • View Profile
    • Professional Model Collaboration
Re: Change multiple connectors' type
« Reply #2 on: May 04, 2018, 12:54:22 pm »
Had one in my toolset :)
Code: [Select]
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:
' Author:
' Purpose:
' Date:
'

'
' Project Browser Script main function
'

'Business Service - Application Relationship conversion
dim SOURCE_STEREO
SOURCE_STEREO = "ApplicationComponent"
dim SOURCE_TYPE
SOURCE_TYPE = "Component"
dim TARGET_STEREO
TARGET_STEREO = "ApplicationComponent"
dim TARGET_TYPE
TARGET_TYPE = "Component"
dim CONN_ORIG_TYPE
CONN_ORIG_TYPE = "Association"
dim CONN_ORIG_STEREO
dim CONN_ORIG_FQSTEREO
CONN_ORIG_STEREO = "InformationFlow"
CONN_ORIG_FQSTEREO = "PROFILE::InformationFlow"
dim CONN_NEW_TYPE
CONN_NEW_TYPE = "Association"
dim CONN_NEW_STEREO
CONN_NEW_STEREO = "IntegrationFlow"


sub ConvertRelationships()
Repository.EnsureOutputVisible "Script"
' 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 theElement as EA.Element
set theElement = Repository.GetTreeSelectedObject()
ProcessElement theElement

case otPackage
' Code for when a package is selected
dim thePackage as EA.Package
set thePackage = Repository.GetTreeSelectedObject()
ProcessPackage thePackage


case else
' Error message
Session.Prompt "This script does not support items of this type.", promptOK

end select
Repository.SynchProfile "Westpac",CONN_NEW_STEREO
Session.Output( "Done Converting...")

end sub

sub ProcessPackage ( thePackage )

' Cast thePackage to EA.Package so we get intellisense
dim currentPackage as EA.Package
set currentPackage = thePackage

Session.Output( currentPackage.Name & " (PackageID=" & currentPackage.PackageID & ")" )

' Process the Applications this package contains
IteratePackage currentPackage

' Recursively process any child packages
dim childPackage as EA.Package
for each childPackage in currentPackage.Packages
ProcessPackage childPackage
next

end sub

sub IteratePackage ( thePackage )

' Iterate through all elements and add them to the list
dim currentElement as EA.Element
for each currentElement in thePackage.Elements
ProcessElement (currentElement)
next
end sub

sub ProcessElement ( theElement )

' Iterate through all elements and add them to the list
ConvertConnector theElement
Session.Output( "Converting..." & theElement.Name)
dim currentElement as EA.Element
for each currentElement in theElement.Elements
ProcessElement (currentElement)
next
end sub

sub ConvertConnector (theElement)
if theElement.Stereotype=SOURCE_STEREO then
' Reset Element Stereotype
Session.Output( "Name: " & theElement.Name )

dim currConn as EA.Connector
'TODO - replace connectors to Brands, Domains
dim targetElement as EA.Element
for each currConn in theElement.Connectors
'Session.Prompt currConn.Stereotype, promptOK
if currConn.Type = CONN_ORIG_TYPE then
if currConn.Stereotype=CONN_ORIG_STEREO or currConn.Stereotype= CONN_ORIG_FQSTEREO then
set targetElement = Repository.GetElementByID(currConn.SupplierID)
'check if the other end is a domain
if targetElement.Stereotype=TARGET_STEREO then
Session.Output( "Connector Updated: " & currConn.ConnectorID & "Element : " & targetElement.Name)
currConn.StereotypeEx=""
currConn.Type=CONN_NEW_TYPE
currConn.Stereotype=CONN_NEW_STEREO
currConn.Update
End If
end if
end if
next
theElement.Update
End If
end sub
ConvertRelationships