[NoBrainer] Connecting Enterprise Architect Interfaces with PowerShell
In one of our projects we needed to create a lot of components that expose interfaces. The steps to design this in EA are quite tedious: Link the Interface to […]
d-fens GmbH
Audit and Consulting of Information Systems and Business Processes
In one of our projects we needed to create a lot of components that expose interfaces. The steps to design this in EA are quite tedious: Link the Interface to […]
In one of our projects we needed to create a lot of components that expose interfaces. The steps to design this in EA are quite tedious:
Interface to the diagram of our component.ProvidedInterface and attach it to the componentProvidedInterface to the name of the InterfaceInterface from the search dialogue of the ProvidedInterface (internally this will set the ClassifierID on the ProvidedInterface)Realization connector from the ProvidedInterface to the actual target InterfaceThe end result would then look like this:

Luckily this is all too easy with PowerShell:
PARAM
(
[Parameter(Mandatory = $true, Position = 0)]
[ValidateNotNullOrEmpty()]
[string] $ProvidedInterface
,
[Parameter(Mandatory = $true, Position = 1)]
[ValidateNotNullOrEmpty()]
[string] $Interface
,
[ValidateScript( { Test-Path($_); } )]
[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[string] $Model
,
[switch] $RecreateConnector = $true
,
[Parameter(Mandatory = $false)]
[string] $EaInterop = 'Sparx Systems\EA\Interop.EA.dll'
)
BEGIN
{
$OutputParameter = $null;
$EaInteropPathAndFileName = Join-Path -Path ${env:ProgramFiles(x86)} -ChildPath $EaInterop;
Add-Type -Path $EaInteropPathAndFileName;
$ea = New-Object -ComObject EA.Repository;
$result = $ea.OpenFile($Model);
}
PROCESS
{
$source = $ea.GetElementByGuid([Guid]::Parse($ProvidedInterface).ToString('B'));
$target = $ea.GetElementByGuid([Guid]::Parse($Interface).ToString('B'));
# delete all existing connectors
if($RecreateConnector)
{
$cMax = $source.Connectors.Count;
for($c = 0; $c -lt $cMax; $c++)
{
$source.Connectors.Delete(0);
$source.Connectors.Refresh();
}
}
# this will add a Realization connector
$connector = $source.Connectors.AddNew([string]::Empty, 'Realization');
$connector.SupplierID = $target.ElementID;
$result = $connector.Update();
$source.Connectors.Refresh();
# this will link the `ProvidedInterface` with the `Interface`
$source.ClassifierID = $target.ElementID;
$source.Name = $target.Name;
$source.Update();
}
END
{
$ea.CloseFile();
$ea.Exit();
}
Via Ctrl+2 we can retrieve the GUID of the Interface and the ProvidedInterface so that we can then call the actual script:
.\Set-ProvidedInterface.ps1 {7C666C2A-571D-45c4-B1BF-0A19C698A050} {2EA70063-2D70-4670-9F61-5864AF8E485A}
Normally we would have to specify the model on every call via the -Model parameter. As this will probably always be the same during a design session, we can preset this via $PSDefaultParameterValues:
$PSDefaultParameterValues.Add('Set-ProvidedInterface.ps1:Model', 'C:\...\myModel.eap')