Sparx Systems Forum
Enterprise Architect => General Board => Topic started by: David Robinson on November 06, 2008, 08:57:23 pm
-
Has anyone successfully tried scripting EA with PowerShell? There seems to be a problem with the COM interface exposed that prevents Powershell accessing type library information. The symptoms are indentical to those in this blog entry:
http://www.mcleod.co.uk/scotty/powershell/COMinterop.htm
I've successfully used the interop assembly to drive EA from C# but the same (or very similar) mechanisms don't work in PowerShell.
The C# code looks like this:
EA.Repository r = new EA.RepositoryClass();
r.OpenFile("C:\\CMC.eap");
EA.Collection models = r.Models;
foreach (object obj in models)
{
if (obj is EA.Package)
{
EA.Package package = (EA.Package)obj;
MessageBox.Show(package.Name);
}
}
PowerShell (standard COM interop):
$rep = New-Object -ComObject EA.Repository
--- EA launches as COM server process with no visible window
$rep1.OpenFile("C:\CMC.eap")
Method invocation failed because [System.__ComObject] doesn't contain a method named 'OpenFile'.
At line:1 char:15
PowerShell using interop assembly:
[system.reflection.assembly]::LoadFile("C:\Program Files\Sparx Systems\EA Trial\Interop.EA.dll")
$rep=New-Object EA.RepositoryClass
$rep.OpenFile("C:\CMC.eap")
$rep.ShowWindow(1)
---- EA Window shows loaded model
$models = [EA.Collection]$rep.Models
$models.Count
1 --- Correct count of top-level packages
$package = [EA.Package]$models.GetAt(0)
Cannot convert "System.__ComObject" to "EA.Package".
At line:1 char:37
-
I can't remember the details, but we have recently changed something to do with name exposure to COM for our next major build. It sounds like powershell is having the same problems.