Author Topic: Scripting EA with PowerShell  (Read 3418 times)

David Robinson

  • EA Novice
  • *
  • Posts: 7
  • Karma: +0/-0
    • View Profile
Scripting EA with PowerShell
« 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:
Code: [Select]
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):
Code: [Select]
$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:
Code: [Select]
[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

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8085
  • Karma: +118/-20
    • View Profile
Re: Scripting EA with PowerShell
« Reply #1 on: November 07, 2008, 09:23:38 am »
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.