[IronPython] COM Question

Nenad propadovic.nenad at debitel.net
Wed Nov 8 22:22:55 CET 2006

Hello everybody,

I'm using IronPython to automate Enterprise Architect (an UML Tool)
via COM.

I've translated the VB.Net code from their examples to Python, in
order to get hold of some objects (diagrams and elements in diagrams

from System import Console, Object
import clr
from EA import AppClass

def RunAll():
        App = AppClass() 
        m_Repository = App.Repository
        m_Repository.OpenFile(r"d:\Projekti\UML\Automotive Testing Exploration.eap")
        #use the Repository in any way required

        m_Repository = None
def DumpModel(m_Repository):
        for idx in range (0, m_Repository.Models.Count):
                Console.WriteLine("" + m_Repository.Models.GetAt(idx).Name)

def DumpPackage(Indent, Package):
        """output package name, then element contents, then process child packages"""
        Console.WriteLine(Indent + Package.Name)
        DumpElements(Indent + "    ", Package)

        for idx in range(0,Package.Packages.Count):
                DumpPackage(Indent + "    ", Package.Packages.GetAt(idx))

I get the following error:
  File C:\IronPython-1.0\Tutorial\ea_go.py, line 35, in Initialize
  File C:\IronPython-1.0\Tutorial\ea_go.py, line 11, in RunAll
  File C:\IronPython-1.0\Tutorial\ea_go.py, line 18, in DumpModel
  File C:\IronPython-1.0\Tutorial\ea_go.py, line 23, in DumpPackage
SystemError: Der Objektverweis wurde nicht auf eine Objektinstanz festgelegt.

So basically it says, m_Repository.Models.GetAt(idx) is not Object,
because m_Repository.Models is not initialized.

Uuups. It seems IronPython doesn't cope with all COM nuances as well
as VB.Net does?

I'd bee greatefull for a clue.
Thanks to all in advance!

P.S. The corresponding VB.Net code works just fine:

Module Module1
    Dim f As Object
    Sub Main()
        Call Run()
    End Sub
    ''class level variable for Repository

    Public m_Repository As Object

    Public Sub Run()
        'Microsoft.VisualBasic.FileOpen(1, "c:\Temp\ea_mdl.txt", OpenMode.Append)
        ''create the repository object
        m_Repository = CreateObject("EA.Repository")
        ''open an EAP file
        m_Repository.OpenFile("d:\Projekti\UML\Automotive Testing Exploration.eap")
        ''use the Repository in any way required
        ''close the repository and tidy up
        m_Repository = Nothing
        Console.WriteLine("Wir sind durch")
    End Sub

    Sub DumpModel()
        Dim idx As Integer
        For idx = 0 To m_Repository.Models.Count - 1
            DumpPackage("", m_Repository.Models.GetAt(idx))
    End Sub

    'output package name, then element contents, then process child packages
    Sub DumpPackage(ByVal Indent As String, ByVal Package As Object)
        Dim idx As Integer
        Console.WriteLine(Indent + Package.Name)
        'WriteLine(Indent + Package.Name)
        DumpElements(Indent + "    ", Package)
        For idx = 0 To Package.Packages.Count - 1
            DumpPackage(Indent + "    ", Package.Packages.GetAt(idx))
    End Sub
End Module

More information about the Ironpython-users mailing list